7
7
import cpw .mods .fml .common .event .FMLPostInitializationEvent ;
8
8
import cpw .mods .fml .common .event .FMLPreInitializationEvent ;
9
9
import cpw .mods .fml .common .eventhandler .SubscribeEvent ;
10
+ import cpw .mods .fml .common .gameevent .TickEvent ;
10
11
import cpw .mods .fml .common .versioning .ArtifactVersion ;
11
12
import cpw .mods .fml .common .versioning .VersionRange ;
12
13
import net .minecraft .client .gui .GuiScreen ;
16
17
import net .minecraftforge .client .event .GuiOpenEvent ;
17
18
import net .minecraftforge .client .event .GuiScreenEvent ;
18
19
import net .minecraftforge .common .MinecraftForge ;
20
+ import org .lwjgl .opengl .Display ;
19
21
20
22
import java .io .File ;
21
23
import java .lang .reflect .Field ;
@@ -38,6 +40,7 @@ public class YetAnotherInputFix{
38
40
private static InputFieldWrapper wrapper =null ;
39
41
public static GuiTextField txt = null ;
40
42
public static final Logger logger =Logger .getLogger ("YAIF" );
43
+ public static boolean needFocus =false ;
41
44
42
45
//Will be called before the Constructor! Be careful.
43
46
public static void SetupTextFieldWrapper (int W , int H ){
@@ -47,6 +50,7 @@ public static void SetupTextFieldWrapper(int W, int H){
47
50
@ Mod .EventHandler
48
51
public void load (FMLInitializationEvent event ) {
49
52
MinecraftForge .EVENT_BUS .register (this );
53
+ FMLCommonHandler .instance ().bus ().register (this );
50
54
}
51
55
52
56
@ SubscribeEvent
@@ -61,6 +65,23 @@ public void onGuiChange(GuiScreenEvent.InitGuiEvent.Post e) {
61
65
}
62
66
}
63
67
68
+ //Multi-threading is a problem
69
+ //TODO: UGLY PATCH!!!
70
+ @ SubscribeEvent
71
+ public void tryGetFocus (TickEvent .ClientTickEvent event ){
72
+ if (needFocus ){
73
+ try {
74
+ Display .makeCurrent ();
75
+ }catch (Exception e ){
76
+ e .printStackTrace ();
77
+ }
78
+ if (Display .isActive ()){
79
+ FMLClientHandler .instance ().getClient ().setIngameFocus ();
80
+ needFocus =false ;
81
+ }
82
+ }
83
+ }
84
+
64
85
public static void TextFieldFocusChange (GuiTextField textField , boolean isFocused ) {
65
86
if (isFocused ) {
66
87
/*if (currentGuiScreen != null) {
0 commit comments