@@ -16,15 +16,15 @@ public class KeyBindHandler {
1616 static Minecraft mc = Minecraft .getMinecraft ();
1717 static KeyBinding [] customKeyBinds = new KeyBinding [4 ];
1818 static int setmode = 0 ;
19- public static int keybindA = mc .gameSettings .keyBindLeft . getKeyCode () ;
20- public static int keybindD = mc .gameSettings .keyBindRight . getKeyCode () ;
21- public static int keybindW = mc .gameSettings .keyBindForward . getKeyCode () ;
22- public static int keybindS = mc .gameSettings .keyBindBack . getKeyCode () ;
23- public static int keybindAttack = mc .gameSettings .keyBindAttack . getKeyCode () ;
24- public static int keybindUseItem = mc .gameSettings .keyBindUseItem . getKeyCode () ;
25- public static int keyBindSpace = mc .gameSettings .keyBindJump . getKeyCode () ;
26- public static int keyBindShift = mc .gameSettings .keyBindSneak . getKeyCode () ;
27- public static int keyBindJump = mc . gameSettings . keyBindJump . getKeyCode ();
19+ public static KeyBinding keybindA = mc .gameSettings .keyBindLeft ;
20+ public static KeyBinding keybindD = mc .gameSettings .keyBindRight ;
21+ public static KeyBinding keybindW = mc .gameSettings .keyBindForward ;
22+ public static KeyBinding keybindS = mc .gameSettings .keyBindBack ;
23+ public static KeyBinding keybindAttack = mc .gameSettings .keyBindAttack ;
24+ public static KeyBinding keybindUseItem = mc .gameSettings .keyBindUseItem ;
25+ public static KeyBinding keyBindShift = mc .gameSettings .keyBindSneak ;
26+ public static KeyBinding keyBindJump = mc .gameSettings .keyBindJump ;
27+
2828
2929
3030 public static void initializeCustomKeybindings () {
@@ -83,51 +83,69 @@ public void onKeyPress(InputEvent.KeyInputEvent event) {
8383
8484
8585
86- public static void setKeyBindState (int keyCode , boolean pressed ) {
86+ public static void setKeyBindState (KeyBinding key , boolean pressed ) {
8787 if (pressed ) {
8888 if (mc .currentScreen != null ) {
89- LogUtils .addCustomLog ("In GUI, pausing" );
90- KeyBinding .setKeyBindState (keyCode , false );
89+ realSetKeyBindState (key , false );
9190 return ;
9291 }
9392 }
94- KeyBinding . setKeyBindState ( keyCode , pressed );
93+ realSetKeyBindState ( key , pressed );
9594 }
9695
9796 public static void updateKeys (boolean wBool , boolean sBool , boolean aBool , boolean dBool , boolean atkBool , boolean useBool , boolean shiftBool ) {
9897 if (mc .currentScreen != null ) {
9998 resetKeybindState ();
10099 return ;
101100 }
102- KeyBinding . setKeyBindState (keybindW , wBool );
103- KeyBinding . setKeyBindState (keybindS , sBool );
104- KeyBinding . setKeyBindState (keybindA , aBool );
105- KeyBinding . setKeyBindState (keybindD , dBool );
106- KeyBinding . setKeyBindState (keybindAttack , atkBool );
107- KeyBinding . setKeyBindState (keybindUseItem , useBool );
108- KeyBinding . setKeyBindState (keyBindShift , shiftBool );
101+ realSetKeyBindState (keybindW , wBool );
102+ realSetKeyBindState (keybindS , sBool );
103+ realSetKeyBindState (keybindA , aBool );
104+ realSetKeyBindState (keybindD , dBool );
105+ realSetKeyBindState (keybindAttack , atkBool );
106+ realSetKeyBindState (keybindUseItem , useBool );
107+ realSetKeyBindState (keyBindShift , shiftBool );
109108 }
110109
111110 public static void updateKeys (boolean wBool , boolean sBool , boolean aBool , boolean dBool , boolean atkBool ) {
112111 if (mc .currentScreen != null ) {
113112 resetKeybindState ();
114113 return ;
115114 }
116- KeyBinding .setKeyBindState (keybindW , wBool );
117- KeyBinding .setKeyBindState (keybindS , sBool );
118- KeyBinding .setKeyBindState (keybindA , aBool );
119- KeyBinding .setKeyBindState (keybindD , dBool );
120- KeyBinding .setKeyBindState (keybindAttack , atkBool );
115+ realSetKeyBindState (keybindW , wBool );
116+ realSetKeyBindState (keybindS , sBool );
117+ realSetKeyBindState (keybindA , aBool );
118+ realSetKeyBindState (keybindD , dBool );
119+ realSetKeyBindState (keybindAttack , atkBool );
120+ }
121+
122+ public static void onTick (KeyBinding key ) {
123+ if (mc .currentScreen == null ) {
124+ KeyBinding .onTick (key .getKeyCode ());
125+ }
121126 }
122127
123128 public static void resetKeybindState () {
124- KeyBinding .setKeyBindState (keybindA , false );
125- KeyBinding .setKeyBindState (keybindS , false );
126- KeyBinding .setKeyBindState (keybindW , false );
127- KeyBinding .setKeyBindState (keybindD , false );
128- KeyBinding .setKeyBindState (keyBindShift , false );
129- KeyBinding .setKeyBindState (keyBindJump , false );
130- KeyBinding .setKeyBindState (keybindAttack , false );
131- KeyBinding .setKeyBindState (keybindUseItem , false );
129+ realSetKeyBindState (keybindA , false );
130+ realSetKeyBindState (keybindS , false );
131+ realSetKeyBindState (keybindW , false );
132+ realSetKeyBindState (keybindD , false );
133+ realSetKeyBindState (keyBindShift , false );
134+ realSetKeyBindState (keyBindJump , false );
135+ realSetKeyBindState (keybindAttack , false );
136+ realSetKeyBindState (keybindUseItem , false );
137+ }
138+
139+ private static void realSetKeyBindState (KeyBinding key , boolean pressed ){
140+ if (pressed ){
141+ if (!key .isKeyDown ()){
142+ KeyBinding .onTick (key .getKeyCode ());
143+ }
144+ KeyBinding .setKeyBindState (key .getKeyCode (), true );
145+
146+ } else {
147+ KeyBinding .setKeyBindState (key .getKeyCode (), false );
148+ }
149+
132150 }
133151}
0 commit comments