Skip to content

Commit

Permalink
Refactor VirtualInput (#179)
Browse files Browse the repository at this point in the history
- Changed how VirtualInput stores keyboard inputs
- Added subtick system, which replaces mouse paths and is also added to the keyboard and camera angle
- [PlaybackController, Commands] Added warnings that features might not work at the moment
- Fixed keyboard keys not being recognised when pressing them for a short amount of time in low tickrates
- Added documentation and unit tests
- Added new interpolation
- [Keybinds] Fixed numerous issues
- Removed unicode hack
  • Loading branch information
ScribbleTAS authored Feb 22, 2024
2 parents 726d213 + 4a5e9f5 commit 430fe3f
Show file tree
Hide file tree
Showing 67 changed files with 4,113 additions and 2,229 deletions.
22 changes: 13 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ loom {
// add log4jconfig
log4jConfigs.from(file('src/main/resources/log4j.xml'))

// default refmap name
mixin.defaultRefmapName = "tasmod.refmap.json"
}

// dependency repositories
Expand All @@ -44,8 +42,8 @@ configurations {
dependencies {
// tasmod dependencies
embed group: 'com.dselent', name: 'bigarraylist', version: '1.1'
compileOnly group: 'com.minecrafttas', name: 'killtherng', version: '2.0'
downloadMod group: 'com.minecrafttas', name: 'killtherng-full', version: '2.0' // for downloadKTRNG task
//compileOnly group: 'com.minecrafttas', name: 'killtherng', version: '2.0'
//downloadMod group: 'com.minecrafttas', name: 'killtherng-full', version: '2.0' // for downloadKTRNG task

// loom dependencies
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand All @@ -54,12 +52,18 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}



// task for downloading KillTheRng
task downloadKTRNG(type: Copy) {
group 'tasmod'
description 'Download KillTheRNG to the run/mods/ folder of the project'
from configurations.downloadMod
into 'run/mods/'
//task downloadKTRNG(type: Copy) {
//group 'tasmod'
//description 'Download KillTheRNG to the run/mods/ folder of the project'
//from configurations.downloadMod
//into 'run/mods/'
//}

compileJava{
options.release = 8
}

// process fabric mod json
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx3G

# Fabric properties
minecraft_version=1.12.2
loader_version=0.15.3
loom_version=1.4-SNAPSHOT
loader_version=0.15.6
loom_version=1.5-SNAPSHOT

# Mod properties
mod_name=Tool-Assisted Speedrun Mod
Expand All @@ -16,4 +16,4 @@ mod_email=scribble@minecrafttas.com
# TASmod properties
group=com.minecrafttas
artifact=TASmod-1.12.2
version=Beta1-SNAPSHOT
version=Beta1.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Map;
import java.util.Properties;

import org.apache.commons.io.FileUtils;

/**
* A <i>very</i> simple configuration class
Expand Down
42 changes: 35 additions & 7 deletions src/main/java/com/minecrafttas/mctcommon/KeybindManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@

/**
* Keybind manager
*
* @author Pancake
*/
public abstract class KeybindManager implements EventClientGameLoop {
public class KeybindManager implements EventClientGameLoop {

private final IsKeyDownFunc defaultFunction;

public static class Keybind {

private KeyBinding keyBinding;
private String category;
private Runnable onKeyDown;
private IsKeyDownFunc isKeyDownFunc;

/**
* Initialize keybind
Expand All @@ -33,19 +37,36 @@ public static class Keybind {
* @param onKeyDown Will be run when the keybind is pressed
*/
public Keybind(String name, String category, int defaultKey, Runnable onKeyDown) {
this(name, category, defaultKey, onKeyDown, null);
}

/**
* Initialize keybind with a different "isKeyDown" method
*
* @param name Name of keybind
* @param category Category of keybind
* @param defaultKey Default key of keybind
* @param onKeyDown Will be run when the keybind is pressed
*/
public Keybind(String name, String category, int defaultKey, Runnable onKeyDown, IsKeyDownFunc func) {
this.keyBinding = new KeyBinding(name, defaultKey, category);
this.category = category;
this.onKeyDown = onKeyDown;
this.isKeyDownFunc = func;
}

}

private List<Keybind> keybindings;

/**
* Initialize keybind manager
* Initialize keybind manage
*
* @param defaultFunction The default function used to determine if a keybind is
* down. Can be overridden when registering a new keybind
*/
public KeybindManager() {
public KeybindManager(IsKeyDownFunc defaultFunction) {
this.defaultFunction = defaultFunction;
this.keybindings = new ArrayList<>();
}

Expand All @@ -54,12 +75,14 @@ public KeybindManager() {
*/
@Override
public void onRunClientGameLoop(Minecraft mc) {
for (Keybind keybind : this.keybindings)
if (this.isKeyDown(keybind.keyBinding))
for (Keybind keybind : this.keybindings){
IsKeyDownFunc keyDown = keybind.isKeyDownFunc != null ? keybind.isKeyDownFunc : defaultFunction;
if(keyDown.isKeyDown(keybind.keyBinding)){
keybind.onKeyDown.run();
}
}
}

protected abstract boolean isKeyDown(KeyBinding i);
}

/**
* Register new keybind
Expand All @@ -80,4 +103,9 @@ public KeyBinding registerKeybind(Keybind keybind) {
return keyBinding;
}

@FunctionalInterface
public static interface IsKeyDownFunc {

public boolean isKeyDown(KeyBinding keybind);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ private static HashMap<String, String> loadJson(InputStream inputStream) {
}
Gson gson = new Gson();
HashMap<String, String> template = new HashMap<>();
HashMap<String, String> out = (HashMap<String, String>) gson.fromJson(new InputStreamReader(inputStream), template.getClass());

@SuppressWarnings("unchecked")
HashMap<String, String> out = (HashMap<String, String>) gson.fromJson(new InputStreamReader(inputStream), template.getClass());
out.forEach((key, value) -> {
value = PATTERN.matcher(value).replaceAll("%$1s");
});
Expand Down

This file was deleted.

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
2 changes: 1 addition & 1 deletion src/main/java/com/minecrafttas/tasmod/TASmod.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void onServerInit(MinecraftServer server) {
// Save Loadstate Count
File savestateDirectory = new File(server.getDataDirectory() + File.separator + "saves" + File.separator + "savestates" + File.separator);
try {
new SavestateTrackerFile(new File(savestateDirectory, server.getFolderName() + "-info.txt"));
new SavestateTrackerFile(new File(savestateDirectory, server.getFolderName() + "-info.txt")); // TODO Ew, remove
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Loading

0 comments on commit 430fe3f

Please sign in to comment.