Skip to content

Commit

Permalink
[VirtualInput] Finished mouse documentation and tests
Browse files Browse the repository at this point in the history
- Moved MixinGuiScreen to package playbackhooks
- Removed serial warnings in Exceptions
  • Loading branch information
ScribbleTAS committed Feb 7, 2024
1 parent 2116087 commit 297be0b
Show file tree
Hide file tree
Showing 14 changed files with 475 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.minecrafttas.mctcommon.server.exception;

@SuppressWarnings("serial")
public class InvalidPacketException extends Exception {

public InvalidPacketException() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.minecrafttas.mctcommon.server.interfaces.PacketHandlerBase;
import com.minecrafttas.mctcommon.server.interfaces.PacketID;

@SuppressWarnings("serial")
public class PacketNotImplementedException extends Exception {

public PacketNotImplementedException(String msg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@

@Mixin(GameSettings.class)
public class MixinGameSettings {


/**
* Redirect Mouse.isButtonDown in keybindings
* @param i The keycode
* @param key The keybinding
* @return Whether the key is down
*/
@Redirect(method = "isKeyDown", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;isButtonDown(I)Z", remap = false))
private static boolean redirectIsKeyDown1(int i, KeyBinding key) {
return TASmodClient.virtual.isKeyDown(i + 100);
}

/**
* Redirect Keyboard.isKeyDown in keybindings
* @param i The keycode
* @param key The keybinding
* @return Whether the key is down
*/
@Redirect(method = "isKeyDown", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;isKeyDown(I)Z", remap = false))
private static boolean redirectIsKeyDown2(int i, KeyBinding key) {
return TASmodClient.virtual.isKeyDown(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

@Mixin(GuiChat.class)
public class MixinGuiChat {
/**
* @return {@link com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualMouseInput#getEventMouseScrollWheel()}
*/
@Redirect(method = "handleMouseInput", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventDWheel()I", remap = false))
public int redirectHandleMouseInput4() {
return TASmodClient.virtual.MOUSE.getEventMouseScrollWheel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

@Mixin(GuiClickableScrolledSelectionListProxy.class)
public class MixinGuiClickableScrolledSelectionListProxy {

/**
* @return {@link com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualMouseInput#getEventMouseState()}
*/
@Redirect(method = "handleMouseInput", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventButtonState()Z", ordinal = 0, remap = false))
public boolean redirectHandleMouseInput() {
return TASmodClient.virtual.MOUSE.getEventMouseState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.spongepowered.asm.mixin.injection.Redirect;

import com.minecrafttas.tasmod.TASmodClient;
import com.minecrafttas.tasmod.virtual.VirtualKey2;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
Expand All @@ -13,19 +14,29 @@
@Mixin(GuiContainer.class)
public class MixinGuiContainer {

/**
* Redirects the check for {@link VirtualKey2#LSHIFT} and {@link VirtualKey2#RSHIFT} in mouseClicked
* @param i The keycode to check for
* @return If the keycode is down
*/
@Redirect(method = "mouseClicked", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;isKeyDown(I)Z", ordinal = 0, remap = false))
private boolean redirectIsKeyDown(int i) {
return TASmodClient.virtual.isKeyDown(i);
}

/**
* Redirects the check for {@link VirtualKey2#LSHIFT} and {@link VirtualKey2#RSHIFT} in mouseReleased
* @param i The keycode to check for
* @return If the keycode is down
*/
@Redirect(method = "mouseReleased", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;isKeyDown(I)Z", ordinal = 0, remap = false))
private boolean redirectIsKeyDown2(int i) {
return TASmodClient.virtual.isKeyDown(i);
}

/**
* Fixes <a href="https://github.com/MinecraftTAS/TASmod/issues/67">#67</a>
* @param player
* @param player The current player
*/
@Redirect(method = "keyTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;closeScreen()V"))
public void redirectCloseScreen(EntityPlayerSP player) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.minecrafttas.tasmod.mixin;
package com.minecrafttas.tasmod.mixin.playbackhooks;

import org.lwjgl.input.Mouse;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -11,29 +10,36 @@

import com.minecrafttas.tasmod.TASmodClient;
import com.minecrafttas.tasmod.util.Ducks.GuiScreenDuck;
import com.minecrafttas.tasmod.virtual.VirtualInput2;
import com.minecrafttas.tasmod.virtual.VirtualKeyboardEvent;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;

@Mixin(GuiScreen.class)
public class MixinGuiScreen implements GuiScreenDuck {

// =====================================================================================================================================

/**
* Run at the start of run handleInput. Runs every tick.
* @see com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualKeyboardInput#nextKeyboardTick()
* @param ci CBI
*/
@Inject(method = "handleInput", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;isCreated()Z", shift = Shift.AFTER, remap = false))
public void injectAfterKeyboardCreated(CallbackInfo ci) {
TASmodClient.virtual.KEYBOARD.nextKeyboardTick();
}

// =====================================================================================================================================

/**
* Redirects a {@link org.lwjgl.input.Keyboard#next()}. Starts running every tick and continues as long as there are {@link VirtualKeyboardEvent}s in {@link VirtualInput2}
* @see com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualKeyboardInput#nextKeyboardSubtick()
* @return If {@link VirtualKeyboardEvent}s are present in {@link VirtualInput2}
*/
@Redirect(method = "handleInput", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;next()Z", remap = false))
public boolean redirectKeyboardNext() {
return TASmodClient.virtual.KEYBOARD.nextKeyboardSubtick();
}

// =====================================================================================================================================


@Redirect(method = "handleKeyboardInput", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventCharacter()C", remap = false))
public char redirectGetEventCharacter() {
return TASmodClient.virtual.KEYBOARD.getEventKeyboardCharacter();
Expand Down Expand Up @@ -78,8 +84,8 @@ public int redirectGetEventButton() {

@Redirect(method = "handleMouseInput", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventButtonState()Z", remap = false))
public boolean redirectGetEventButtonState() {
if (TASmodClient.controller.isPlayingback()) {
Mouse.setCursorPosition(rescaleX(TASmodClient.virtual.MOUSE.getEventCursorX()), rescaleY(TASmodClient.virtual.MOUSE.getEventCursorY()));
if (TASmodClient.controller.isPlayingback()) { // TODO replace with event
org.lwjgl.input.Mouse.setCursorPosition(rescaleX(TASmodClient.virtual.MOUSE.getEventCursorX()), rescaleY(TASmodClient.virtual.MOUSE.getEventCursorY()));
}
return TASmodClient.virtual.MOUSE.getEventMouseState();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.minecrafttas.tasmod.mixin.playbackhooks;

import org.lwjgl.input.Keyboard;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -10,7 +9,9 @@

import com.minecrafttas.tasmod.TASmodClient;
import com.minecrafttas.tasmod.virtual.VirtualInput2;
import com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualMouseInput;
import com.minecrafttas.tasmod.virtual.VirtualKeyboardEvent;
import com.minecrafttas.tasmod.virtual.VirtualMouseEvent;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
Expand All @@ -31,8 +32,11 @@ public void playback_injectRunGameLoop(CallbackInfo ci) {
TASmodClient.virtual.update(currentScreen);
}

// ============================ Keyboard

/**
* Run at the start of run tick keyboard. Runs every tick.
* @see com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualKeyboardInput#nextKeyboardTick()
* @param ci CBI
*/
@Inject(method = "runTickKeyboard", at = @At(value = "HEAD"))
Expand All @@ -41,7 +45,7 @@ public void playback_injectRunTickKeyboard(CallbackInfo ci) {
}

/**
* Redirects a {@link Keyboard#next()}. Starts running every tick and continues as long as there are {@link VirtualKeyboardEvent}s in {@link VirtualInput}
* Redirects a {@link org.lwjgl.input.Keyboard#next()}. Starts running every tick and continues as long as there are {@link VirtualKeyboardEvent}s in {@link VirtualInput2}
* @see com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualKeyboardInput#nextKeyboardSubtick()
* @return If {@link VirtualKeyboardEvent}s are present in {@link VirtualInput2}
*/
Expand All @@ -51,82 +55,104 @@ public boolean playback_redirectKeyboardNext() {
}

/**
* Runs everytime {@link #playback_redirectKeyboardNext()} has an event ready. Redirects {@link Keyboard#getEventKeyState()}
* @return The keycode for the current event in {@link VirtualInput2.VirtualKeyboardInput}
* @return {@link com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualKeyboardInput#getEventKeyboardKey()}
*/
@Redirect(method = "runTickKeyboard", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventKey()I", remap = false))
public int playback_redirectKeyboardGetEventKey() {
return TASmodClient.virtual.KEYBOARD.getEventKeyboardKey();
}

/**
* Runs everytime {@link #playback_redirectKeyboardNext()} has an event ready. Redirects {@link Keyboard#getEventKeyState()}
* @return Whether the key is down in {@link VirtualInput2}
* @return {@link com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualKeyboardInput#getEventKeyboardState()}
*/
@Redirect(method = "runTickKeyboard", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventKeyState()Z", remap = false))
public boolean playback_redirectGetEventState() {
return TASmodClient.virtual.KEYBOARD.getEventKeyboardState();
}

/**
* Runs everytime {@link #playback_redirectKeyboardNext()} has an event ready. Redirects {@link Keyboard#getEventCharacter()}
* @return The character for the current event in {@link VirtualInput2}
* @return {@link com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualKeyboardInput#getEventKeyboardCharacter()}
*/
@Redirect(method = "runTickKeyboard", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventCharacter()C", remap = false))
public char playback_redirectKeyboardGetEventCharacter() {
return TASmodClient.virtual.KEYBOARD.getEventKeyboardCharacter();
}

/**
* Runs everytime {@link #playback_redirectKeyboardNext()} has an event ready. Redirects {@link Keyboard#isKeyDown(int)}
* Runs everytime {@link #playback_redirectKeyboardNext()} has an event ready. Redirects {@link org.lwjgl.input.Keyboard#isKeyDown(int)}
* @see com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualKeyboardInput#isKeyDown(int)
* @return Whether the key is down in {@link VirtualInput2}
*/
@Redirect(method = "runTickKeyboard", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;isKeyDown(I)Z", remap = false))
public boolean playback_redirectIsKeyDown(int keyCode) {
return TASmodClient.virtual.KEYBOARD.isKeyDown(keyCode);
}

/**
* @return {@link com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualKeyboardInput#getEventKeyboardKey()}
*/
@Redirect(method = "dispatchKeypresses", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventKey()I", remap = false))
public int playback_redirectGetEventKeyDPK() {
return TASmodClient.virtual.KEYBOARD.getEventKeyboardKey();
}

/**
* @return {@link com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualKeyboardInput#getEventKeyboardState()}
*/
@Redirect(method = "dispatchKeypresses", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventKeyState()Z", remap = false))
public boolean playback_redirectGetEventKeyStateDPK() {
return TASmodClient.virtual.KEYBOARD.getEventKeyboardState();
}

/**
* @return {@link com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualKeyboardInput#getEventKeyboardCharacter()}
*/
@Redirect(method = "dispatchKeypresses", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;getEventCharacter()C", remap = false))
public char playback_redirectGetEventCharacterDPK() {
return TASmodClient.virtual.KEYBOARD.getEventKeyboardCharacter();
}

// ============================ Mouse

/**
* Run at the start of run tick mouse. Runs every tick.
* @see com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualMouseInput#nextMouseTick()
* @param ci CBI
*/
@Inject(method = "runTickMouse", at = @At(value = "HEAD"))
public void playback_injectRunTickMouse(CallbackInfo ci) {
TASmodClient.virtual.MOUSE.nextMouseTick();
}

/**
* Redirects a {@link org.lwjgl.input.Mouse#next()}. Starts running every tick and continues as long as there are {@link VirtualMouseEvent}s in {@link VirtualInput2}
* @see com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualMouseInput#nextMouseSubtick()
* @return If {@link VirtualMouseInput}s are present in {@link VirtualInput2}
*/
@Redirect(method = "runTickMouse", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;next()Z", remap = false))
public boolean playback_redirectMouseNext() {
return TASmodClient.virtual.MOUSE.nextMouseSubtick();
}

/**
* @return {@link com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualMouseInput#getEventMouseKey()}
*/
@Redirect(method = "runTickMouse", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventButton()I", remap = false))
public int playback_redirectMouseGetEventButton() {

// if(!VirtualKeybindings.isKeyCodeAlwaysBlocked(ClientProxy.virtual.getEventMouseKey()-100)) {
// TASmod.ktrngHandler.nextPlayerInput(); // Advance ktrng seed on player input
// }
return TASmodClient.virtual.MOUSE.getEventMouseKey() + 100;
}

/**
* @return {@link com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualMouseInput#getEventMouseState()}
*/
@Redirect(method = "runTickMouse", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventButtonState()Z", remap = false))
public boolean playback_redirectGetEventButtonState() {
return TASmodClient.virtual.MOUSE.getEventMouseState();
}

/**
* @return {@link com.minecrafttas.tasmod.virtual.VirtualInput2.VirtualMouseInput#getEventMouseScrollWheel()}
*/
@Redirect(method = "runTickMouse", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventDWheel()I", remap = false))
public int playback_redirectGetEventDWheel() {
return TASmodClient.virtual.MOUSE.getEventMouseScrollWheel();
Expand Down
Loading

0 comments on commit 297be0b

Please sign in to comment.