diff --git a/src/main/java/com/minecrafttas/tasmod/virtual/Subtickable.java b/src/main/java/com/minecrafttas/tasmod/virtual/Subtickable.java index c0cd892b..56a0873e 100644 --- a/src/main/java/com/minecrafttas/tasmod/virtual/Subtickable.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/Subtickable.java @@ -36,7 +36,7 @@ protected Subtickable(List subtickList, boolean ignoreFirstUpdate) { /** * Adds a peripheral to {@link #subtickList} - * + * * @param peripheral The peripheral to add */ protected void addSubtick(T peripheral) { @@ -60,11 +60,11 @@ public boolean isParent() { /** * Gets all peripheral states in an immutable list.
*
- * This list is comprised of {@link #subtickList} and the current peripheral + * This list comprises {@link #subtickList} and the current peripheral * state added after that
* This will result in a list where the first element is the oldest state and * the last being the current state. - * + * * @return An immutable list of keyboard states */ @SuppressWarnings("unchecked") @@ -78,7 +78,7 @@ protected void clear() { /** * Retrieves and sets {@link #ignoreFirstUpdate} to false - * + * * @return If the first update should be ignored */ protected boolean ignoreFirstUpdate() { diff --git a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput.java index b51a7a87..b59f7a25 100644 --- a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput.java @@ -26,8 +26,9 @@ * Main component for redirecting inputs.
*
* This class mimics the LWJGL classes {@link org.lwjgl.input.Keyboard} and - * {@link org.lwjgl.input.Mouse}.
- *
+ * {@link org.lwjgl.input.Mouse} and redirects the camera angle and player rotation
+ * + * @author Scribble */ public class VirtualInput { private final Logger LOGGER; @@ -46,7 +47,7 @@ public class VirtualInput { /** * Creates a new virtual input with an empty {@link VirtualKeyboardInput}, {@link VirtualMouseInput} and {@link VirtualCameraAngleInput} - * @param logger + * @param logger The logger instance */ public VirtualInput(Logger logger) { this(logger, new VirtualKeyboard(), new VirtualMouse(), new VirtualCameraAngle()); @@ -497,7 +498,7 @@ public boolean willKeyBeDown(int keycode) { * After extensive testing, the decision was made to conform the camera to update every tick,
* instead of every frame. By itself, this meant that moving the camera felt really laggy
*
- * Therefore an interpolation system was created that seperated the camera angle from the player head rotation,
+ * Therefore, an interpolation system was created that seperated the camera angle from the player head rotation,
* which are usually the synced. *
* While the camera is the angle displayed on screen, the player rotation is responsible for the logic,
diff --git a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKey.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKey.java index 2c175166..98e2d273 100644 --- a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKey.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKey.java @@ -1,5 +1,10 @@ package com.minecrafttas.tasmod.virtual; +/** + * List of all names and keycodes from the keyboard and the mouse. + * + * @author Scribble + */ public enum VirtualKey { // Keyboard ZERO(0), diff --git a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeybindings.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeybindings.java index c2130f56..d79cc738 100644 --- a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeybindings.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeybindings.java @@ -20,7 +20,7 @@ * Applies special rules to vanilla keybindings.
*
* Using {@link #isKeyDown(KeyBinding)}, the registered keybindings will work - * inside of gui screens
+ * inside gui screens
*
* {@link #isKeyDownExceptTextfield(KeyBinding)} does the same, but excludes * textfields, certain guiscreens, and the keybinding options
@@ -32,18 +32,33 @@ * */ public class VirtualKeybindings { - private static Minecraft mc = Minecraft.getMinecraft(); - private static long cooldown = 50*5; - private static HashMap cooldownHashMap = Maps.newHashMap(); - private static List blockedKeys = new ArrayList<>(); + /** + * The Minecraft instance + */ + private static final Minecraft mc = Minecraft.getMinecraft(); + /** + * The standard cooldown for a keybinding in milliseconds + */ + private static final long cooldown = 50*5; + /** + * Stores the start time of a keybinding, used for cooldown calculation + */ + private static final HashMap cooldownHashMap = new HashMap<>(); + /** + * A list of keybindings which will not be recorded or pressed during recording or playback. + */ + private static final List blockedKeys = new ArrayList<>(); + /** + * True when a text field is currently focused in a gui, like the creative search tab + */ public static boolean focused = false; /** * Checks whether the keycode is pressed, regardless of any gui screens * - * @param keybind - * @return + * @param keybind The keybind to check + * @return If the keybind is down */ public static boolean isKeyDown(KeyBinding keybind) { @@ -77,10 +92,12 @@ public static boolean isKeyDown(KeyBinding keybind) { } /** - * Checks whether the key is down, but stops when certain conditions apply + * Checks whether the key is down, but returns false if a text field is focused in a gui.
+ *
+ * Always returns false if GuiChat and GuiEditSign is open. * - * @param keybind - * @return + * @param keybind The keybinding to check + * @return If a keybind is pressed. Returns false if a text field in a gui is focused */ public static boolean isKeyDownExceptTextfield(KeyBinding keybind) { if (mc.currentScreen instanceof GuiChat || mc.currentScreen instanceof GuiEditSign || (focused && mc.currentScreen != null)) { @@ -92,7 +109,7 @@ public static boolean isKeyDownExceptTextfield(KeyBinding keybind) { /** * Registers keybindings that should not be recorded or played back in a TAS * - * @param keybind + * @param keybind The keybinding to block */ public static void registerBlockedKeyBinding(KeyBinding keybind) { blockedKeys.add(keybind); @@ -111,5 +128,4 @@ public static boolean isKeyCodeAlwaysBlocked(int keycode) { } return false; } - } diff --git a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboard.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboard.java index d12bea00..80adab57 100644 --- a/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboard.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboard.java @@ -52,13 +52,13 @@ * 32, true, d // D is pressed * *

Subticks

- * Minecraft updates it's keyboard every tick. All the key events that occur inbetween are stored,
+ * Minecraft updates its keyboard every tick. All the key events that occur inbetween are stored,
* then read out when a new tick has started.
We call these "inbetween" ticks subticks.
*

Parent->Subtick

* In a previous version of this keyboard, subticks were bundeled and flattened into one keyboard state.
* After all, Minecraft updates only occur once every tick, storing subticks seemed unnecessary.
*
- * However this posed some usability issues when playing in a low game speed via {@link com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient}.
+ * However, this posed some usability issues when playing in a low game speed via {@link com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient}.
* Now you had to hold the key until the next tick to get it recognised by the game.
*
* To fix this, now every subtick is stored as a keyboard state as well.
diff --git a/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualCameraAngleEvent.java b/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualCameraAngleEvent.java deleted file mode 100644 index 21e85aa4..00000000 --- a/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualCameraAngleEvent.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.minecrafttas.tasmod.virtual.event; - -public class VirtualCameraAngleEvent extends VirtualEvent { - private float pitchDelta; - private float yawDelta; - - public VirtualCameraAngleEvent(float pitchDelta, float yawDelta) { - this.pitchDelta = pitchDelta; - this.yawDelta = yawDelta; - } - - public float getDeltaPitch() { - return pitchDelta; - } - - public float getDeltaYaw() { - return yawDelta; - } - - @Override - public boolean equals(Object obj) { - if(obj instanceof VirtualCameraAngleEvent) { - return ((VirtualCameraAngleEvent)obj).pitchDelta == pitchDelta && ((VirtualCameraAngleEvent)obj).yawDelta == yawDelta; - } - return super.equals(obj); - } -} diff --git a/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualEvent.java b/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualEvent.java index ea376bfd..0c2909fd 100644 --- a/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualEvent.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualEvent.java @@ -1,33 +1,29 @@ package com.minecrafttas.tasmod.virtual.event; public class VirtualEvent { + protected final int keycode; + protected final boolean keystate; - public static class VirtualButtonEvent extends VirtualEvent{ + public VirtualEvent(int keycode, boolean keystate) { + this.keycode = keycode; + this.keystate = keystate; + } - protected final int keycode; - protected final boolean keystate; - - public VirtualButtonEvent(int keycode, boolean keystate) { - this.keycode = keycode; - this.keystate = keystate; - } + public VirtualEvent(VirtualEvent event) { + this.keycode = event.keycode; + this.keystate = event.keystate; + } - public VirtualButtonEvent(VirtualButtonEvent event) { - this.keycode = event.keycode; - this.keystate = event.keystate; - } + public int getKeyCode() { + return keycode; + } - public int getKeyCode() { - return keycode; - } + public boolean isState() { + return keystate; + } - public boolean isState() { - return keystate; - } - - @Override - public String toString() { - return String.format("%s, %s", keycode, keystate); - } + @Override + public String toString() { + return String.format("%s, %s", keycode, keystate); } } diff --git a/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualKeyboardEvent.java b/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualKeyboardEvent.java index 5c0b0cc8..3ad0e7c0 100644 --- a/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualKeyboardEvent.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualKeyboardEvent.java @@ -1,8 +1,11 @@ package com.minecrafttas.tasmod.virtual.event; -import com.minecrafttas.tasmod.virtual.event.VirtualEvent.VirtualButtonEvent; - -public class VirtualKeyboardEvent extends VirtualButtonEvent { +/** + * Template for recording {@link org.lwjgl.input.Keyboard#next()} events. + * + * @author Scribble + */ +public class VirtualKeyboardEvent extends VirtualEvent { private final char character; public VirtualKeyboardEvent(){ @@ -14,11 +17,6 @@ public VirtualKeyboardEvent(int keycode, boolean keystate, char character) { this.character = character; } - public VirtualKeyboardEvent(VirtualButtonEvent event, char character) { - super(event); - this.character = character; - } - public char getCharacter() { return character; } diff --git a/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualMouseEvent.java b/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualMouseEvent.java index 251eb865..ba57ec4c 100644 --- a/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualMouseEvent.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/event/VirtualMouseEvent.java @@ -1,13 +1,11 @@ package com.minecrafttas.tasmod.virtual.event; -import com.minecrafttas.tasmod.virtual.event.VirtualEvent.VirtualButtonEvent; - /** - * Template for recording Mouse.next() events. + * Template for recording {@link org.lwjgl.input.Mouse#next()} events. * * @author Scribble */ -public class VirtualMouseEvent extends VirtualButtonEvent { +public class VirtualMouseEvent extends VirtualEvent { private final int scrollwheel; private final int cursorX; private final int cursorY;