File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package xyz .imcodist .mixins ;
2+
3+ import net .minecraft .client .option .KeyBinding ;
4+ import org .spongepowered .asm .mixin .Mixin ;
5+ import org .spongepowered .asm .mixin .gen .Accessor ;
6+
7+ @ Mixin (KeyBinding .class )
8+ public interface KeyBindingMixin {
9+ @ Accessor ("timesPressed" )
10+ void setTimesPressed (int timesPressed );
11+ }
Original file line number Diff line number Diff line change 22
33import net .minecraft .client .MinecraftClient ;
44import net .minecraft .client .option .KeyBinding ;
5+ import xyz .imcodist .mixins .KeyBindingMixin ;
56
6- import java .lang .reflect .Field ;
77import java .util .ArrayList ;
88
99public class KeybindHandler {
@@ -23,16 +23,13 @@ public static void runQueue() {
2323 }
2424
2525 for (KeyBinding keyBinding : queuedKeys ) {
26- try {
27- Field field = keyBinding .getClass ().getDeclaredField ("timesPressed" );
28- field .setAccessible (true );
26+ KeyBindingMixin keyBindingMixin = (KeyBindingMixin ) keyBinding ;
2927
30- keyBinding . setPressed ( true );
31- field . set ( keyBinding , 1 );
28+ keyBindingMixin . setTimesPressed ( 1 );
29+ keyBinding . setPressed ( true );
3230
33- didPress = true ;
34- queuedRelease .add (keyBinding );
35- } catch (Exception ignored ) {}
31+ didPress = true ;
32+ queuedRelease .add (keyBinding );
3633 }
3734
3835 queuedKeys .clear ();
Original file line number Diff line number Diff line change 11{
2- "required" : false ,
3- "package" : " " ,
2+ "required" : true ,
3+ "package" : " xyz.imcodist.mixins " ,
44 "compatibilityLevel" : " JAVA_17" ,
5- "mixins" : [],
5+ "client" : [
6+ " KeyBindingMixin"
7+ ],
68 "injectors" : {
79 "defaultRequire" : 1
810 }
You can’t perform that action at this time.
0 commit comments