11package com .minecrafttas .tasmod .mixin .playbackhooks ;
22
3- import com .minecrafttas .tasmod .virtual .VirtualInput ;
43import org .spongepowered .asm .mixin .Mixin ;
54import org .spongepowered .asm .mixin .Shadow ;
65import org .spongepowered .asm .mixin .injection .At ;
98import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
109
1110import com .minecrafttas .tasmod .TASmodClient ;
11+ import com .minecrafttas .tasmod .virtual .VirtualInput ;
1212import com .minecrafttas .tasmod .virtual .VirtualInput .VirtualMouseInput ;
1313import com .minecrafttas .tasmod .virtual .event .VirtualKeyboardEvent ;
1414import com .minecrafttas .tasmod .virtual .event .VirtualMouseEvent ;
1818
1919@ Mixin (Minecraft .class )
2020public class MixinMinecraft {
21-
21+
2222 @ Shadow
2323 private GuiScreen currentScreen ;
24-
24+
2525 /**
2626 * Runs every frame.
2727 * @see VirtualInput#update(GuiScreen)
@@ -31,19 +31,29 @@ public class MixinMinecraft {
3131 public void playback_injectRunGameLoop (CallbackInfo ci ) {
3232 TASmodClient .virtual .update (currentScreen );
3333 }
34-
34+
3535 // ============================ Keyboard
36-
36+
3737 /**
3838 * Run at the start of run tick keyboard. Runs every tick.
3939 * @see VirtualInput.VirtualKeyboardInput#nextKeyboardTick()
4040 * @param ci CBI
4141 */
4242 @ Inject (method = "runTickKeyboard" , at = @ At (value = "HEAD" ))
4343 public void playback_injectRunTickKeyboard (CallbackInfo ci ) {
44- TASmodClient .virtual .KEYBOARD .nextKeyboardTick ();
44+ /*
45+ * This "currentScreen == null" (and the one in runTickMouse) fixes
46+ * a particularly interesting bug where subticks are not recorded in GuiScreens...
47+ *
48+ * The reason this failed is because nextKeyboardTick is called twice in a row,
49+ * when a gui screen is open. The subticks are cleared after calling this
50+ * once, so having it be called twice essentially removes subticks alltogether.
51+ */
52+ if (currentScreen == null ) {
53+ TASmodClient .virtual .KEYBOARD .nextKeyboardTick ();
54+ }
4555 }
46-
56+
4757 /**
4858 * Redirects a {@link org.lwjgl.input.Keyboard#next()}. Starts running every tick and continues as long as there are {@link VirtualKeyboardEvent}s in {@link VirtualInput}
4959 * @see VirtualInput.VirtualKeyboardInput#nextKeyboardSubtick()
@@ -53,31 +63,31 @@ public void playback_injectRunTickKeyboard(CallbackInfo ci) {
5363 public boolean playback_redirectKeyboardNext () {
5464 return TASmodClient .virtual .KEYBOARD .nextKeyboardSubtick ();
5565 }
56-
66+
5767 /**
5868 * @return {@link VirtualInput.VirtualKeyboardInput#getEventKeyboardKey()}
5969 */
6070 @ Redirect (method = "runTickKeyboard" , at = @ At (value = "INVOKE" , target = "Lorg/lwjgl/input/Keyboard;getEventKey()I" , remap = false ))
6171 public int playback_redirectKeyboardGetEventKey () {
6272 return TASmodClient .virtual .KEYBOARD .getEventKeyboardKey ();
6373 }
64-
74+
6575 /**
6676 * @return {@link VirtualInput.VirtualKeyboardInput#getEventKeyboardState()}
6777 */
6878 @ Redirect (method = "runTickKeyboard" , at = @ At (value = "INVOKE" , target = "Lorg/lwjgl/input/Keyboard;getEventKeyState()Z" , remap = false ))
6979 public boolean playback_redirectGetEventState () {
7080 return TASmodClient .virtual .KEYBOARD .getEventKeyboardState ();
7181 }
72-
82+
7383 /**
7484 * @return {@link VirtualInput.VirtualKeyboardInput#getEventKeyboardCharacter()}
7585 */
7686 @ Redirect (method = "runTickKeyboard" , at = @ At (value = "INVOKE" , target = "Lorg/lwjgl/input/Keyboard;getEventCharacter()C" , remap = false ))
7787 public char playback_redirectKeyboardGetEventCharacter () {
7888 return TASmodClient .virtual .KEYBOARD .getEventKeyboardCharacter ();
7989 }
80-
90+
8191 /**
8292 * Runs everytime {@link #playback_redirectKeyboardNext()} has an event ready. Redirects {@link org.lwjgl.input.Keyboard#isKeyDown(int)}
8393 * @see VirtualInput.VirtualKeyboardInput#isKeyDown(int)
@@ -87,43 +97,45 @@ public char playback_redirectKeyboardGetEventCharacter() {
8797 public boolean playback_redirectIsKeyDown (int keyCode ) {
8898 return TASmodClient .virtual .KEYBOARD .isKeyDown (keyCode );
8999 }
90-
100+
91101 /**
92102 * @return {@link VirtualInput.VirtualKeyboardInput#getEventKeyboardKey()}
93103 */
94104 @ Redirect (method = "dispatchKeypresses" , at = @ At (value = "INVOKE" , target = "Lorg/lwjgl/input/Keyboard;getEventKey()I" , remap = false ))
95105 public int playback_redirectGetEventKeyDPK () {
96106 return TASmodClient .virtual .KEYBOARD .getEventKeyboardKey ();
97107 }
98-
108+
99109 /**
100110 * @return {@link VirtualInput.VirtualKeyboardInput#getEventKeyboardState()}
101111 */
102112 @ Redirect (method = "dispatchKeypresses" , at = @ At (value = "INVOKE" , target = "Lorg/lwjgl/input/Keyboard;getEventKeyState()Z" , remap = false ))
103113 public boolean playback_redirectGetEventKeyStateDPK () {
104114 return TASmodClient .virtual .KEYBOARD .getEventKeyboardState ();
105115 }
106-
116+
107117 /**
108118 * @return {@link VirtualInput.VirtualKeyboardInput#getEventKeyboardCharacter()}
109119 */
110120 @ Redirect (method = "dispatchKeypresses" , at = @ At (value = "INVOKE" , target = "Lorg/lwjgl/input/Keyboard;getEventCharacter()C" , remap = false ))
111121 public char playback_redirectGetEventCharacterDPK () {
112122 return TASmodClient .virtual .KEYBOARD .getEventKeyboardCharacter ();
113123 }
114-
124+
115125 // ============================ Mouse
116-
126+
117127 /**
118128 * Run at the start of run tick mouse. Runs every tick.
119129 * @see VirtualInput.VirtualMouseInput#nextMouseTick()
120130 * @param ci CBI
121131 */
122132 @ Inject (method = "runTickMouse" , at = @ At (value = "HEAD" ))
123133 public void playback_injectRunTickMouse (CallbackInfo ci ) {
124- TASmodClient .virtual .MOUSE .nextMouseTick ();
134+ if (currentScreen == null ) {
135+ TASmodClient .virtual .MOUSE .nextMouseTick ();
136+ }
125137 }
126-
138+
127139 /**
128140 * Redirects a {@link org.lwjgl.input.Mouse#next()}. Starts running every tick and continues as long as there are {@link VirtualMouseEvent}s in {@link VirtualInput}
129141 * @see VirtualInput.VirtualMouseInput#nextMouseSubtick()
@@ -133,29 +145,29 @@ public void playback_injectRunTickMouse(CallbackInfo ci) {
133145 public boolean playback_redirectMouseNext () {
134146 return TASmodClient .virtual .MOUSE .nextMouseSubtick ();
135147 }
136-
148+
137149 /**
138150 * @return {@link VirtualInput.VirtualMouseInput#getEventMouseKey()}
139151 */
140152 @ Redirect (method = "runTickMouse" , at = @ At (value = "INVOKE" , target = "Lorg/lwjgl/input/Mouse;getEventButton()I" , remap = false ))
141153 public int playback_redirectMouseGetEventButton () {
142154 return TASmodClient .virtual .MOUSE .getEventMouseKey () + 100 ;
143155 }
144-
156+
145157 /**
146158 * @return {@link VirtualInput.VirtualMouseInput#getEventMouseState()}
147159 */
148160 @ Redirect (method = "runTickMouse" , at = @ At (value = "INVOKE" , target = "Lorg/lwjgl/input/Mouse;getEventButtonState()Z" , remap = false ))
149161 public boolean playback_redirectGetEventButtonState () {
150162 return TASmodClient .virtual .MOUSE .getEventMouseState ();
151163 }
152-
164+
153165 /**
154166 * @return {@link VirtualInput.VirtualMouseInput#getEventMouseScrollWheel()}
155167 */
156168 @ Redirect (method = "runTickMouse" , at = @ At (value = "INVOKE" , target = "Lorg/lwjgl/input/Mouse;getEventDWheel()I" , remap = false ))
157169 public int playback_redirectGetEventDWheel () {
158170 return TASmodClient .virtual .MOUSE .getEventMouseScrollWheel ();
159171 }
160-
172+
161173}
0 commit comments