Skip to content

Commit

Permalink
[VirtualInput] Various documentation improvements
Browse files Browse the repository at this point in the history
- Removed VirtualButtonEvent inner class in VirtualEvent
  • Loading branch information
ScribbleTAS committed Feb 22, 2024
1 parent 7006c51 commit 5044ecd
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected Subtickable(List<T> subtickList, boolean ignoreFirstUpdate) {

/**
* Adds a peripheral to {@link #subtickList}
*
*
* @param peripheral The peripheral to add
*/
protected void addSubtick(T peripheral) {
Expand All @@ -60,11 +60,11 @@ public boolean isParent() {
/**
* Gets all peripheral states in an immutable list.<br>
* <br>
* This list is comprised of {@link #subtickList} and the current peripheral
* This list comprises {@link #subtickList} and the current peripheral
* state added after that<br>
* 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")
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
* Main component for redirecting inputs.<br>
* <br>
* This class mimics the LWJGL classes {@link org.lwjgl.input.Keyboard} and
* {@link org.lwjgl.input.Mouse}.<br>
* <br>
* {@link org.lwjgl.input.Mouse} and redirects the camera angle and player rotation<br>
*
* @author Scribble
*/
public class VirtualInput {
private final Logger LOGGER;
Expand All @@ -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());
Expand Down Expand Up @@ -497,7 +498,7 @@ public boolean willKeyBeDown(int keycode) {
* After extensive testing, the decision was made to conform the camera to update every <em>tick</em>,<br>
* instead of every frame. By itself, this meant that moving the camera felt really laggy<br>
* <br>
* Therefore an interpolation system was created that seperated the camera angle from the player head rotation,<br>
* Therefore, an interpolation system was created that seperated the camera angle from the player head rotation,<br>
* which are usually the synced.
* <br>
* While the camera is the angle displayed on screen, the player rotation is responsible for the logic,<br>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/minecrafttas/tasmod/virtual/VirtualKey.java
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Applies special rules to vanilla keybindings. <br>
* <br>
* Using {@link #isKeyDown(KeyBinding)}, the registered keybindings will work
* inside of gui screens <br>
* inside gui screens <br>
* <br>
* {@link #isKeyDownExceptTextfield(KeyBinding)} does the same, but excludes
* textfields, certain guiscreens, and the keybinding options<br>
Expand All @@ -32,18 +32,33 @@
*
*/
public class VirtualKeybindings {
private static Minecraft mc = Minecraft.getMinecraft();
private static long cooldown = 50*5;
private static HashMap<KeyBinding, Long> cooldownHashMap = Maps.<KeyBinding, Long>newHashMap();
private static List<KeyBinding> 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<KeyBinding, Long> cooldownHashMap = new HashMap<>();
/**
* A list of keybindings which will not be recorded or pressed during recording or playback.
*/
private static final List<KeyBinding> 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) {

Expand Down Expand Up @@ -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.<br>
* <br>
* 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)) {
Expand All @@ -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);
Expand All @@ -111,5 +128,4 @@ public static boolean isKeyCodeAlwaysBlocked(int keycode) {
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
* 32, true, d // D is pressed
* </pre>
* <h2>Subticks</h2>
* Minecraft updates it's keyboard every tick. All the key events that occur inbetween are stored,<br>
* Minecraft updates its keyboard every tick. All the key events that occur inbetween are stored,<br>
* then read out when a new tick has started.<br> We call these "inbetween" ticks <em>subticks</em>.<br>
* <h3>Parent->Subtick</h3>
* In a previous version of this keyboard, subticks were bundeled and flattened into one keyboard state.<br>
* After all, Minecraft updates only occur once every tick, storing subticks seemed unnecessary.<br>
* <br>
* However this posed some usability issues when playing in a low game speed via {@link com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient}.<br>
* However, this posed some usability issues when playing in a low game speed via {@link com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient}.<br>
* Now you had to hold the key until the next tick to get it recognised by the game.<br>
* <br>
* To fix this, now every subtick is stored as a keyboard state as well.<br>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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(){
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 5044ecd

Please sign in to comment.