Skip to content

Commit

Permalink
Fixed indentation in some files
Browse files Browse the repository at this point in the history
  • Loading branch information
ScribbleTAS committed Feb 22, 2024
1 parent 513e015 commit c5b8c0e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 68 deletions.
142 changes: 75 additions & 67 deletions src/main/java/com/minecrafttas/tasmod/virtual/VirtualPeripheral.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,98 +12,104 @@
* Base class for {@link VirtualKeyboard} and {@link VirtualMouse}<br>
* <br>
* Contains the shared code for keeping track of which buttons are pressed.<br>
* This works by storing the keycodes of the buttons in a set, as keycodes are supposed to be unique<br>
* This works by storing the keycodes of the buttons in a set, as keycodes are
* supposed to be unique<br>
* <br>
* Generating {@link VirtualEvent}s is handled in the child classes.
*
* @author Scribble
*/
public abstract class VirtualPeripheral<T extends VirtualPeripheral<T>> extends Subtickable<T> implements Serializable {

/**
* The list of keycodes that are currently pressed on this peripheral.
*/
protected final Set<Integer> pressedKeys;

/**
* Creates a VirtualPeripheral
* @param pressedKeys The {@link #pressedKeys}
* @param subtickList The {@link #subtickList}
* @param ignoreFirstUpdate The {@link #ignoreFirstUpdate} state
*/
protected VirtualPeripheral(Set<Integer> pressedKeys, List<T> subtickList, boolean ignoreFirstUpdate) {
super(subtickList, ignoreFirstUpdate);
this.pressedKeys = pressedKeys;
}
/**
* The list of keycodes that are currently pressed on this peripheral.
*/
protected final Set<Integer> pressedKeys;

/**
* Set the specified keycode to pressed
* @param keycode The keycode to check
* @param keystate The keystate of the keycode
*/
protected void setPressed(int keycode, boolean keystate) {
if (VirtualKeybindings.isKeyCodeAlwaysBlocked(keycode)) { //TODO Maybe a better system?
/**
* Creates a VirtualPeripheral
*
* @param pressedKeys The {@link #pressedKeys}
* @param subtickList The {@link #subtickList}
* @param ignoreFirstUpdate The {@link #ignoreFirstUpdate} state
*/
protected VirtualPeripheral(Set<Integer> pressedKeys, List<T> subtickList, boolean ignoreFirstUpdate) {
super(subtickList, ignoreFirstUpdate);
this.pressedKeys = pressedKeys;
}

/**
* Set the specified keycode to pressed
*
* @param keycode The keycode to check
* @param keystate The keystate of the keycode
*/
protected void setPressed(int keycode, boolean keystate) {
if (VirtualKeybindings.isKeyCodeAlwaysBlocked(keycode)) { // TODO Maybe a better system?
return;
}
if (keystate)
pressedKeys.add(keycode);
else
pressedKeys.remove(keycode);
}

/**
* Set the specified keyname to pressed
* @param keyname The keyname to check
* @param keystate The keystate of the keyname
*/
public void setPressed(String keyname, boolean keystate) {
Integer keycode = VirtualKey.getKeycode(keyname);
if (keycode != null) {
setPressed(keycode, keystate);
}
}
if (keystate)
pressedKeys.add(keycode);
else
pressedKeys.remove(keycode);
}

/**
* @return A list of all currently pressed keynames
*/
public List<String> getCurrentPresses() {
List<String> out = new ArrayList<>();
pressedKeys.forEach(keycode -> {
out.add(VirtualKey.getName(keycode));
});
return out;
}
/**
* Set the specified keyname to pressed
*
* @param keyname The keyname to check
* @param keystate The keystate of the keyname
*/
public void setPressed(String keyname, boolean keystate) {
Integer keycode = VirtualKey.getKeycode(keyname);
if (keycode != null) {
setPressed(keycode, keystate);
}
}

@Override
public String toString() {
return String.join(",", getCurrentPresses());
}
/**
* @return A list of all currently pressed keynames
*/
public List<String> getCurrentPresses() {
List<String> out = new ArrayList<>();
pressedKeys.forEach(keycode -> {
out.add(VirtualKey.getName(keycode));
});
return out;
}

/**
* @return An immutable set of pressed keycodes
*/
@Override
public String toString() {
return String.join(",", getCurrentPresses());
}

/**
* @return An immutable set of pressed keycodes
*/
public Set<Integer> getPressedKeys() {
return ImmutableSet.copyOf(pressedKeys);
}

/**
* If the key is available in {@link #pressedKeys}
*
* @param keycode The keycode in question
* @return If the key is pressed
*/
public boolean isKeyDown(int keycode) {
return pressedKeys.contains(keycode);
}

/**
* If the key is available in {@link #pressedKeys}
*
* @param keyname The keyname in question
* @return If the key is pressed
*/
public boolean isKeyDown(String keyname) {
return pressedKeys.contains(VirtualKey.getKeycode(keyname));
}

/**
* Clears pressed keys and subticks
*/
Expand All @@ -112,25 +118,27 @@ protected void clear() {
pressedKeys.clear();
super.clear();
}

@Override
public boolean equals(Object obj) {
if(obj instanceof VirtualPeripheral) {
if (obj instanceof VirtualPeripheral) {
VirtualPeripheral<?> peripheral = (VirtualPeripheral<?>) obj;
for (Integer keycode : pressedKeys) {
if(!peripheral.pressedKeys.contains(keycode)) {
if (!peripheral.pressedKeys.contains(keycode)) {
return false;
}
}
return true;
}
return super.equals(obj);
}

/**
* Copies the data from another virtual peripheral into this peripheral without creating a new object.
* @param peripheral The peripheral to move from
*/

/**
* Copies the data from another virtual peripheral into this peripheral without
* creating a new object.
*
* @param peripheral The peripheral to move from
*/
protected void copyFrom(T peripheral) {
this.pressedKeys.clear();
this.pressedKeys.addAll(peripheral.pressedKeys);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/tasmod.mixin.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

//Playbackhooks
"playbackhooks.MixinMinecraft",
"playbackhooks.MixinEntityRenderer",
"playbackhooks.MixinEntityRenderer",
"playbackhooks.MixinGuiScreen",
"playbackhooks.MixinGameSettings",
"playbackhooks.MixinGuiChat",
Expand Down

0 comments on commit c5b8c0e

Please sign in to comment.