diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinMinecraft.java b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinMinecraft.java index 9929f356..31fe25c3 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinMinecraft.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinMinecraft.java @@ -88,15 +88,6 @@ public int playback_redirectKeyboardGetEventKey() { return TASmodClient.virtual.getEventKeyboardKey(); } - /** - * Runs everytime {@link #playback_redirectKeyboardNext()} has an event ready. Redirects {@link Keyboard#getEventCharacter()} - * @return The character for the current event in {@link VirtualInput2} - */ - @Redirect(method = "runTickKeyboard", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventCharacter()C", remap = false)) - public char playback_redirectKeyboardGetEventCharacter() { - return TASmodClient.virtual.getEventKeyboardCharacter(); - } - /** * Runs everytime {@link #playback_redirectKeyboardNext()} has an event ready. Redirects {@link Keyboard#getEventKeyState()} * @return Whether the key is down in {@link VirtualInput2} @@ -106,6 +97,15 @@ public boolean playback_redirectGetEventState() { return TASmodClient.virtual.getEventKeyboardState(); } + /** + * Runs everytime {@link #playback_redirectKeyboardNext()} has an event ready. Redirects {@link Keyboard#getEventCharacter()} + * @return The character for the current event in {@link VirtualInput2} + */ + @Redirect(method = "runTickKeyboard", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventCharacter()C", remap = false)) + public char playback_redirectKeyboardGetEventCharacter() { + return TASmodClient.virtual.getEventKeyboardCharacter(); + } + /** * Runs everytime {@link #playback_redirectKeyboardNext()} has an event ready. Redirects {@link Keyboard#isKeyDown(int)} * @return Whether the key is down in {@link VirtualInput2} @@ -115,6 +115,21 @@ public boolean playback_redirectIsKeyDown(int keyCode) { return TASmodClient.virtual.isKeyDown(keyCode); } + @Redirect(method = "dispatchKeypresses", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventKey()I", remap = false)) + public int playback_redirectGetEventKeyDPK() { + return TASmodClient.virtual.getEventKeyboardKey(); + } + + @Redirect(method = "dispatchKeypresses", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventKeyState()Z", remap = false)) + public boolean playback_redirectGetEventKeyStateDPK() { + return TASmodClient.virtual.getEventKeyboardState(); + } + + @Redirect(method = "dispatchKeypresses", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventCharacter()C", remap = false)) + public char playback_redirectGetEventCharacterDPK() { + return TASmodClient.virtual.getEventKeyboardCharacter(); + } + // ============================ Mouse @Inject(method = "runTickMouse", at = @At(value = "HEAD")) @@ -146,18 +161,4 @@ public int playback_redirectGetEventDWheel() { return TASmodClient.virtual.getEventMouseScrollWheel(); } - @Redirect(method = "dispatchKeypresses", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventKey()I", remap = false)) - public int playback_redirectGetEventKeyDPK() { - return TASmodClient.virtual.getEventKeyboardKey(); - } - - @Redirect(method = "dispatchKeypresses", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventCharacter()C", remap = false)) - public char playback_redirectGetEventCharacterDPK() { - return TASmodClient.virtual.getEventKeyboardCharacter(); - } - - @Redirect(method = "dispatchKeypresses", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventKeyState()Z", remap = false)) - public boolean playback_redirectGetEventKeyStateDPK() { - return TASmodClient.virtual.getEventKeyboardState(); - } } diff --git a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualCameraAngle2.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualCameraAngle2.java index a0bd06d4..94cbb38d 100644 --- a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualCameraAngle2.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualCameraAngle2.java @@ -45,7 +45,9 @@ public boolean isParent() { } public void getCameraAngleSubticks(Queue reference) { - reference.addAll(subtickList); + if(isParent()) { + reference.addAll(subtickList); + } } @Override diff --git a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput2.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput2.java index ab343ef2..420e2406 100644 --- a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput2.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput2.java @@ -14,12 +14,14 @@ /** * Main component for redirecting inputs.
*
- * This class mimics the LWJGL classes {@link org.lwjgl.input.Keyboard} and {@link org.lwjgl.input.Mouse}.
+ * This class mimics the LWJGL classes {@link org.lwjgl.input.Keyboard} and + * {@link org.lwjgl.input.Mouse}.
*
*/ public class VirtualInput2 { private final VirtualKeyboardInput keyboardInput; private final VirtualMouseInput mouseInput; + private final VirtualCameraAngleInput cameraAngleInput; public VirtualInput2() { this(new VirtualKeyboard2(), new VirtualMouse2(), new VirtualCameraAngle(0, 0)); @@ -27,6 +29,7 @@ public VirtualInput2() { /** * Creates a virtual input with pre-loaded values + * * @param preloadedKeyboard * @param preloadedMouse * @param preloadedCamera @@ -34,39 +37,29 @@ public VirtualInput2() { public VirtualInput2(VirtualKeyboard2 preloadedKeyboard, VirtualMouse2 preloadedMouse, VirtualCameraAngle preloadedCamera) { keyboardInput = new VirtualKeyboardInput(preloadedKeyboard); mouseInput = new VirtualMouseInput(preloadedMouse); - this.cameraAngle = preloadedCamera; + cameraAngleInput = new VirtualCameraAngleInput(preloadedCamera); } /** - * Updates the logic for {@link #keyboardInput}, {@link #mouseInput} and {@link #cameraAngle}
+ * Updates the logic for {@link #keyboardInput}, {@link #mouseInput} and + * {@link #cameraAngle}
* Runs every frame + * * @see MixinMinecraft#playback_injectRunGameLoop(CallbackInfo) - * @param currentScreen The current screen from Minecraft.class. - * Used for checking if the mouse logic should be adapted to GUIScreens + * @param currentScreen The current screen from Minecraft.class. Used for + * checking if the mouse logic should be adapted to + * GUIScreens */ - public void update(GuiScreen currentScreen){ + public void update(GuiScreen currentScreen) { while (Keyboard.next()) { - keyboardInput.updateNextKeyboard( - Keyboard.getEventKey(), - Keyboard.getEventKeyState(), - Keyboard.getEventCharacter()); + keyboardInput.updateNextKeyboard(Keyboard.getEventKey(), Keyboard.getEventKeyState(), Keyboard.getEventCharacter()); } while (Mouse.next()) { - if(currentScreen == null) { - mouseInput.updateNextMouse( - Mouse.getEventButton(), - Mouse.getEventButtonState(), - Mouse.getEventDWheel(), - null, - null); + if (currentScreen == null) { + mouseInput.updateNextMouse(Mouse.getEventButton(), Mouse.getEventButtonState(), Mouse.getEventDWheel(), null, null); } else { Ducks.GuiScreenDuck screen = (Ducks.GuiScreenDuck) currentScreen; - mouseInput.updateNextMouse( - Mouse.getEventButton(), - Mouse.getEventButtonState(), - Mouse.getEventDWheel(), - screen.calcX(Mouse.getEventX()), - screen.calcY(Mouse.getEventY())); + mouseInput.updateNextMouse(Mouse.getEventButton(), Mouse.getEventButtonState(), Mouse.getEventDWheel(), screen.calcX(Mouse.getEventX()), screen.calcY(Mouse.getEventY())); } } } @@ -79,14 +72,15 @@ public VirtualMouseInput getMouseInput() { return mouseInput; } - public VirtualCameraAngle getCameraAngle() { - return cameraAngle; + public VirtualCameraAngleInput getCameraAngle() { + return cameraAngleInput; } /** * Subclass of {@link VirtualInput} handling keyboard logic.
*
* Vanilla keyboard handling looks something like this: + * *
 	 *	public void runTickKeyboard()  { // Executed every tick in runTick()
 	 *		while({@linkplain Keyboard#next()}){
@@ -98,7 +92,10 @@ public VirtualCameraAngle getCameraAngle() {
 	 *		}
 	 *	}
 	 * 
- * After redirecting the calls in {@link MixinMinecraft}, the resulting logic now looks like this: + * + * After redirecting the calls in {@link MixinMinecraft}, the resulting logic + * now looks like this: + * *
 	 *	public void runTickKeyboard()  {
 	 *		{@linkplain #nextKeyboardTick()}
@@ -116,7 +113,8 @@ public VirtualCameraAngle getCameraAngle() {
 	private static class VirtualKeyboardInput {
 		/**
 		 * The keyboard "state" that is currently recognized by the game,
- * meaning it is a direct copy of the vanilla keybindings. Updated every tick.
+ * meaning it is a direct copy of the vanilla keybindings. Updated every + * tick.
* Updated in {@link #nextKeyboardTick()} */ private final VirtualKeyboard2 currentKeyboard; @@ -128,25 +126,29 @@ private static class VirtualKeyboardInput { private final VirtualKeyboard2 nextKeyboard = new VirtualKeyboard2(); /** * Queue for keyboard events.
- * Is filled in {@link #nextKeyboardTick()} and read in {@link #nextKeyboardSubtick()} + * Is filled in {@link #nextKeyboardTick()} and read in + * {@link #nextKeyboardSubtick()} */ private final Queue keyboardEventQueue = new ConcurrentLinkedQueue(); /** - * The current keyboard event where the vanilla keybindings are reading from.
- * Updated in {@link #nextKeyboardSubtick()} and read out in {@link #getEventKeyboardKey()}, {@link #getEventKeyboardState()} and {@link #getEventKeyboardCharacter()} + * The current keyboard event where the vanilla keybindings are reading + * from.
+ * Updated in {@link #nextKeyboardSubtick()} and read out in + * {@link #getEventKeyboardKey()}, {@link #getEventKeyboardState()} and + * {@link #getEventKeyboardCharacter()} */ private VirtualKeyboardEvent currentKeyboardEvent = new VirtualKeyboardEvent(); - - public VirtualKeyboardInput(VirtualKeyboard2 preloadedKeyboard){ + public VirtualKeyboardInput(VirtualKeyboard2 preloadedKeyboard) { currentKeyboard = preloadedKeyboard; } /** * Updates the next keyboard + * * @see VirtualInput2#update(GuiScreen) - * @param keycode The keycode of this event - * @param keystate The keystate of this event + * @param keycode The keycode of this event + * @param keystate The keystate of this event * @param character The character of this event */ public void updateNextKeyboard(int keycode, boolean keystate, char character) { @@ -155,7 +157,9 @@ public void updateNextKeyboard(int keycode, boolean keystate, char character) { /** * Runs when the next keyboard tick is about to occur.
- * Used to load {@link #nextKeyboard} into {@link #currentKeyboard}, creating {@link VirtualKeyboardEvent}s in the process. + * Used to load {@link #nextKeyboard} into {@link #currentKeyboard}, creating + * {@link VirtualKeyboardEvent}s in the process. + * * @see MixinMinecraft#playback_injectRunTickKeyboard(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) */ public void nextKeyboardTick() { @@ -164,14 +168,16 @@ public void nextKeyboardTick() { } /** - * Runs in a while loop. Used for updating {@link #currentKeyboardEvent} and ending the while loop. + * Runs in a while loop. Used for updating {@link #currentKeyboardEvent} and + * ending the while loop. + * * @see MixinMinecraft#playback_redirectKeyboardNext() * @return If a keyboard event is in {@link #keyboardEventQueue} */ public boolean nextKeyboardSubtick() { return (currentKeyboardEvent = keyboardEventQueue.poll()) != null; } - + /** * @return The keycode of {@link #currentKeyboardEvent} */ @@ -200,11 +206,11 @@ private static class VirtualMouseInput { private final Queue mouseEventQueue = new ConcurrentLinkedQueue<>(); private VirtualMouseEvent currentMouseEvent = new VirtualMouseEvent(); - public VirtualMouseInput(){ + public VirtualMouseInput() { this(new VirtualMouse2()); } - public VirtualMouseInput(VirtualMouse2 preloadedMouse){ + public VirtualMouseInput(VirtualMouse2 preloadedMouse) { currentMouse = preloadedMouse; } @@ -243,6 +249,13 @@ public int getEventCursorY() { } - private VirtualCameraAngle cameraAngle; - + private static class VirtualCameraAngleInput { + + private VirtualCameraAngle cameraAngle; + + public VirtualCameraAngleInput(VirtualCameraAngle preloadedCamera) { + cameraAngle = preloadedCamera; + } + + } } diff --git a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboard2.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboard2.java index ed149ed6..dbd30500 100644 --- a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboard2.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboard2.java @@ -173,11 +173,13 @@ private char getOrMinChar(Character charr){ * should be the one from tick 16 * @param reference The queue to fill. Passed in by reference. */ - public void getVirtualEvents(VirtualKeyboard2 nextKeyboard, Queue reference) { - getSubticks().forEach(keyboard -> { - keyboard.getDifference(nextKeyboard, reference); - }); - } + public void getVirtualEvents(VirtualKeyboard2 nextKeyboard, Queue reference) { + if (isParent()) { + getSubticks().forEach(keyboard -> { + keyboard.getDifference(nextKeyboard, reference); + }); + } + } /** * Add a character to the {@link #charList}
diff --git a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualMouse2.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualMouse2.java index 38c0f738..bbf163b8 100644 --- a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualMouse2.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualMouse2.java @@ -104,9 +104,11 @@ public void getDifference(VirtualMouse2 nextPeripheral, Queue } public void getVirtualEvents(VirtualMouse2 nextPeripheral, Queue reference) { - getSubticks().forEach(mouse -> { - mouse.getDifference(nextPeripheral, reference); - }); + if(isParent()) { + getSubticks().forEach(mouse -> { + mouse.getDifference(nextPeripheral, reference); + }); + } } @Override