From f4d10c76e5f0c8efd893f0413181c888862720de Mon Sep 17 00:00:00 2001 From: Emanuel Pilz Date: Tue, 19 Mar 2024 20:44:36 +0100 Subject: [PATCH] Update to 24w11a --- .gitignore | 1 + build.gradle | 18 +- gradle.properties | 18 +- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 2 +- .../java/com/emonadeo/autorun/AutoRunMod.java | 302 +++++++++--------- .../com/emonadeo/autorun/AutoRunModMenu.java | 58 ++-- .../emonadeo/autorun/MovementDirection.java | 58 ++-- .../autorun/mixin/client/AutoRunMixin.java | 56 ++-- src/main/java/.gitkeep | 0 10 files changed, 252 insertions(+), 263 deletions(-) create mode 100644 src/main/java/.gitkeep diff --git a/.gitignore b/.gitignore index c476faf..7436235 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ hs_err_*.log replay_*.log *.hprof *.jfr +.factorypath diff --git a/build.gradle b/build.gradle index 8ff2b94..fdc8900 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,9 @@ plugins { - id 'fabric-loom' version '1.2-SNAPSHOT' + id 'fabric-loom' version '1.5-SNAPSHOT' id 'maven-publish' id "com.matthewprenger.cursegradle" version "1.4.0" id "com.modrinth.minotaur" version "2.+" + id "com.diffplug.spotless" version "6.25.0" } version = "${project.supported_versions}-${project.mod_version}" @@ -18,7 +19,7 @@ repositories { } loom { - splitEnvironmentSourceSets() + splitEnvironmentSourceSets() mods { "autorun" { @@ -129,3 +130,16 @@ modrinth { gameVersions = ["1.20", "1.20.1"] loaders = ["fabric"] } + +spotless { +format 'misc', { + target '*.gradle', '.gitattributes', '.gitignore' + + trimTrailingWhitespace() + indentWithTabs() + endWithNewline() +} +java { +eclipse() +} +} diff --git a/gradle.properties b/gradle.properties index e77b002..fa34eac 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,21 +4,21 @@ org.gradle.parallel=false # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.20 -yarn_mappings=1.20+build.1 -loader_version=0.14.21 +minecraft_version=24w11a +yarn_mappings=24w11a+build.5 +loader_version=0.15.7 # Mod Properties -mod_version=0.5.0 -supported_versions=1.20.X +mod_version=1.0.0-beta.1 +supported_versions=1.20.4 maven_group=com.emonadeo archives_base_name=autorun # Dependencies -fabric_version=0.83.0+1.20 -modmenu_version=7.0.1 -cloth_version=11.0.99 +fabric_version=0.96.11+1.20.5 +modmenu_version=10.0.0-alpha.1 +cloth_version=14.0.122 # CurseGradle project_id=279429 -release_type=release \ No newline at end of file +release_type=release diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37aef8d..509c4a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 75c4d72..dfacbd1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,4 +7,4 @@ pluginManagement { mavenCentral() gradlePluginPortal() } -} \ No newline at end of file +} diff --git a/src/client/java/com/emonadeo/autorun/AutoRunMod.java b/src/client/java/com/emonadeo/autorun/AutoRunMod.java index 6305637..e04d4ba 100644 --- a/src/client/java/com/emonadeo/autorun/AutoRunMod.java +++ b/src/client/java/com/emonadeo/autorun/AutoRunMod.java @@ -1,5 +1,14 @@ package com.emonadeo.autorun; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; +import java.util.stream.Collectors; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; @@ -11,158 +20,147 @@ import net.minecraft.client.util.InputUtil; import org.lwjgl.glfw.GLFW; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Properties; -import java.util.Set; -import java.util.stream.Collectors; - public class AutoRunMod implements ClientModInitializer { - public static final String MODID = "autorun"; - public static final File CFG_FILE = new File(FabricLoader.getInstance().getConfigDir().toFile(), "autorun.properties"); - - private static KeyBinding keyBinding; - private static Set toggled; - private static long timeActivated; - private static int delayBuffer; - - private static boolean originalAutoJumpSetting; - private static boolean toggleAutoJump; - - @Override - public void onInitializeClient() { - AutoRunMod.toggled = new HashSet<>(); - AutoRunMod.timeActivated = -1; - AutoRunMod.delayBuffer = 20; - AutoRunMod.toggleAutoJump = true; - AutoRunMod.keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( - "key.autorun.toggle", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_O, // Default to 'o' - "key.categories.movement" // Append movement category - )); - - loadConfig(CFG_FILE); - - ClientTickEvents.END_CLIENT_TICK.register(client -> { - if (client.world != null && keyBinding.wasPressed()) { - boolean activating = toggled.isEmpty(); - - if (!activating) { - // Deactivating by pressing AutoRun key - toggled.clear(); - restoreAutoJump(client); - } else { - // Activating - Set pressedDirections = Arrays.stream(MovementDirection.values()) - .filter(dir -> dir.getKeyBinding(client).isPressed()).collect(Collectors.toSet()); - - if (!pressedDirections.isEmpty()) { - // Activate pressed directions - toggled.addAll(pressedDirections); - } else { - // Activate forward by default - toggled.add(MovementDirection.FORWARD); - } - - timeActivated = client.world.getTime(); - enableAutoJump(client); - } - } - - if (timeActivated != -1 && client.world != null - && client.world.getTime() - timeActivated >= delayBuffer) { - x: - for (MovementDirection dir : toggled) { - for (KeyBinding terminator : dir.getTerminators(client)) { - if (terminator.isPressed()) { - // Deactivating by pressing movement key - toggled.clear(); - timeActivated = -1; - restoreAutoJump(client); - break x; - } - } - } - } - }); - - ClientEntityEvents.ENTITY_UNLOAD.register((entity, clientWorld) -> { - if (entity instanceof ClientPlayerEntity) { - restoreAutoJump(MinecraftClient.getInstance()); - toggled.clear(); - } - }); - } - - public static void enableAutoJump(MinecraftClient client) { - if (!toggleAutoJump) - return; - - originalAutoJumpSetting = client.options.getAutoJump().getValue(); - - client.options.getAutoJump().setValue(true); - client.options.sendClientSettings(); - } - - public static void restoreAutoJump(MinecraftClient client) { - if (!toggleAutoJump) - return; - - client.options.getAutoJump().setValue(originalAutoJumpSetting); - client.options.sendClientSettings(); - } - - public static void loadConfig(File file) { - try { - Properties cfg = new Properties(); - if (!file.exists()) { - saveConfig(file); - } - cfg.load(new FileInputStream(file)); - delayBuffer = Integer.parseInt(cfg.getProperty("delayBuffer", "20")); - toggleAutoJump = Boolean.parseBoolean(cfg.getProperty("toggleAutoJump", "true")); - - // Re-save so that new properties will appear in old config files - saveConfig(file); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static void saveConfig(File file) { - try { - FileOutputStream fos = new FileOutputStream(file, false); - fos.write(("delayBuffer=" + delayBuffer + "\n").getBytes()); - fos.write(("toggleAutoJump=" + toggleAutoJump + "\n").getBytes()); - fos.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static Set getToggled() { - return toggled; - } - - public static int getDelayBuffer() { - return delayBuffer; - } - - public static void setDelayBuffer(int delayBuffer) { - AutoRunMod.delayBuffer = delayBuffer; - } - - public static boolean isToggleAutoJump() { - return toggleAutoJump; - } - - public static void setToggleAutoJump(boolean toggleAutoJump) { - AutoRunMod.toggleAutoJump = toggleAutoJump; - } + public static final String MODID = "autorun"; + public static final File CFG_FILE = new File(FabricLoader.getInstance().getConfigDir().toFile(), + "autorun.properties"); + + private static KeyBinding keyBinding; + private static Set toggled; + private static long timeActivated; + private static int delayBuffer; + + private static boolean originalAutoJumpSetting; + private static boolean toggleAutoJump; + + @Override + public void onInitializeClient() { + AutoRunMod.toggled = new HashSet<>(); + AutoRunMod.timeActivated = -1; + AutoRunMod.delayBuffer = 20; + AutoRunMod.toggleAutoJump = true; + AutoRunMod.keyBinding = KeyBindingHelper + .registerKeyBinding(new KeyBinding("key.autorun.toggle", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_O, // Default + // to + // 'o' + "key.categories.movement" // Append movement category + )); + + loadConfig(CFG_FILE); + + ClientTickEvents.END_CLIENT_TICK.register(client -> { + if (client.world != null && keyBinding.wasPressed()) { + boolean activating = toggled.isEmpty(); + + if (!activating) { + // Deactivating by pressing AutoRun key + toggled.clear(); + restoreAutoJump(client); + } else { + // Activating + Set pressedDirections = Arrays.stream(MovementDirection.values()) + .filter(dir -> dir.getKeyBinding(client).isPressed()).collect(Collectors.toSet()); + + if (!pressedDirections.isEmpty()) { + // Activate pressed directions + toggled.addAll(pressedDirections); + } else { + // Activate forward by default + toggled.add(MovementDirection.FORWARD); + } + + timeActivated = client.world.getTime(); + enableAutoJump(client); + } + } + + if (timeActivated != -1 && client.world != null && client.world.getTime() - timeActivated >= delayBuffer) { + x : for (MovementDirection dir : toggled) { + for (KeyBinding terminator : dir.getTerminators(client)) { + if (terminator.isPressed()) { + // Deactivating by pressing movement key + toggled.clear(); + timeActivated = -1; + restoreAutoJump(client); + break x; + } + } + } + } + }); + + ClientEntityEvents.ENTITY_UNLOAD.register((entity, clientWorld) -> { + if (entity instanceof ClientPlayerEntity) { + restoreAutoJump(MinecraftClient.getInstance()); + toggled.clear(); + } + }); + } + + public static void enableAutoJump(MinecraftClient client) { + if (!toggleAutoJump) + return; + + originalAutoJumpSetting = client.options.getAutoJump().getValue(); + + client.options.getAutoJump().setValue(true); + client.options.sendClientSettings(); + } + + public static void restoreAutoJump(MinecraftClient client) { + if (!toggleAutoJump) + return; + + client.options.getAutoJump().setValue(originalAutoJumpSetting); + client.options.sendClientSettings(); + } + + public static void loadConfig(File file) { + try { + Properties cfg = new Properties(); + if (!file.exists()) { + saveConfig(file); + } + cfg.load(new FileInputStream(file)); + delayBuffer = Integer.parseInt(cfg.getProperty("delayBuffer", "20")); + toggleAutoJump = Boolean.parseBoolean(cfg.getProperty("toggleAutoJump", "true")); + + // Re-save so that new properties will appear in old config files + saveConfig(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void saveConfig(File file) { + try { + FileOutputStream fos = new FileOutputStream(file, false); + fos.write(("delayBuffer=" + delayBuffer + "\n").getBytes()); + fos.write(("toggleAutoJump=" + toggleAutoJump + "\n").getBytes()); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static Set getToggled() { + return toggled; + } + + public static int getDelayBuffer() { + return delayBuffer; + } + + public static void setDelayBuffer(int delayBuffer) { + AutoRunMod.delayBuffer = delayBuffer; + } + + public static boolean isToggleAutoJump() { + return toggleAutoJump; + } + + public static void setToggleAutoJump(boolean toggleAutoJump) { + AutoRunMod.toggleAutoJump = toggleAutoJump; + } } diff --git a/src/client/java/com/emonadeo/autorun/AutoRunModMenu.java b/src/client/java/com/emonadeo/autorun/AutoRunModMenu.java index 5859442..458f5c1 100644 --- a/src/client/java/com/emonadeo/autorun/AutoRunModMenu.java +++ b/src/client/java/com/emonadeo/autorun/AutoRunModMenu.java @@ -9,37 +9,39 @@ import net.minecraft.text.Text; public class AutoRunModMenu implements ModMenuApi, ConfigScreenFactory { - @Override - public ConfigScreenFactory getModConfigScreenFactory() { - return this; - } + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return this; + } - @Override - public Screen create(Screen screen) { - ConfigBuilder builder = ConfigBuilder.create() - .setParentScreen(screen) - .setTitle(Text.translatable("title." + AutoRunMod.MODID + ".config")); + @Override + public Screen create(Screen screen) { + ConfigBuilder builder = ConfigBuilder.create().setParentScreen(screen) + .setTitle(Text.translatable("title." + AutoRunMod.MODID + ".config")); - ConfigEntryBuilder entryBuilder = builder.entryBuilder(); - ConfigCategory general = builder.getOrCreateCategory(Text.translatable("config." + AutoRunMod.MODID + ".general")); + ConfigEntryBuilder entryBuilder = builder.entryBuilder(); + ConfigCategory general = builder + .getOrCreateCategory(Text.translatable("config." + AutoRunMod.MODID + ".general")); - // Toogle Auto-Jump - general.addEntry(entryBuilder.startBooleanToggle(Text.translatable("config." + AutoRunMod.MODID + ".toggleAutoJump"), AutoRunMod.isToggleAutoJump()) - .setDefaultValue(true) - .setTooltip(Text.translatable("config." + AutoRunMod.MODID + ".toggleAutoJump.description")) - .setSaveConsumer(AutoRunMod::setToggleAutoJump) - .build()); + // Toogle Auto-Jump + general.addEntry(entryBuilder + .startBooleanToggle(Text.translatable("config." + AutoRunMod.MODID + ".toggleAutoJump"), + AutoRunMod.isToggleAutoJump()) + .setDefaultValue(true) + .setTooltip(Text.translatable("config." + AutoRunMod.MODID + ".toggleAutoJump.description")) + .setSaveConsumer(AutoRunMod::setToggleAutoJump).build()); - // Delay Buffer - general.addEntry(entryBuilder.startIntField(Text.translatable("config." + AutoRunMod.MODID + ".delayBuffer"), AutoRunMod.getDelayBuffer()) - .setDefaultValue(20) - .setTooltip(Text.translatable("config." + AutoRunMod.MODID + ".delayBuffer.description")) - .setSaveConsumer(AutoRunMod::setDelayBuffer) - .build()); + // Delay Buffer + general.addEntry(entryBuilder + .startIntField(Text.translatable("config." + AutoRunMod.MODID + ".delayBuffer"), + AutoRunMod.getDelayBuffer()) + .setDefaultValue(20) + .setTooltip(Text.translatable("config." + AutoRunMod.MODID + ".delayBuffer.description")) + .setSaveConsumer(AutoRunMod::setDelayBuffer).build()); - return builder.setSavingRunnable(() -> { - AutoRunMod.saveConfig(AutoRunMod.CFG_FILE); - AutoRunMod.loadConfig(AutoRunMod.CFG_FILE); - }).build(); - } + return builder.setSavingRunnable(() -> { + AutoRunMod.saveConfig(AutoRunMod.CFG_FILE); + AutoRunMod.loadConfig(AutoRunMod.CFG_FILE); + }).build(); + } } diff --git a/src/client/java/com/emonadeo/autorun/MovementDirection.java b/src/client/java/com/emonadeo/autorun/MovementDirection.java index 5e9d895..5ad1861 100644 --- a/src/client/java/com/emonadeo/autorun/MovementDirection.java +++ b/src/client/java/com/emonadeo/autorun/MovementDirection.java @@ -1,44 +1,34 @@ package com.emonadeo.autorun; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.option.KeyBinding; - import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.option.KeyBinding; public enum MovementDirection { - FORWARD, - BACK, - LEFT, - RIGHT; + FORWARD, BACK, LEFT, RIGHT; - public KeyBinding getKeyBinding(MinecraftClient client) { - switch (this) { - default: - return client.options.forwardKey; - case BACK: - return client.options.backKey; - case LEFT: - return client.options.leftKey; - case RIGHT: - return client.options.rightKey; - } - } + public KeyBinding getKeyBinding(MinecraftClient client) { + switch (this) { + default : + return client.options.forwardKey; + case BACK : + return client.options.backKey; + case LEFT : + return client.options.leftKey; + case RIGHT : + return client.options.rightKey; + } + } - public Set getTerminators(MinecraftClient client) { - switch (this) { - default: - return Stream.of( - client.options.forwardKey, - client.options.backKey) - .collect(Collectors.toSet()); - case LEFT: - case RIGHT: - return Stream.of( - client.options.leftKey, - client.options.rightKey) - .collect(Collectors.toSet()); - } - } + public Set getTerminators(MinecraftClient client) { + switch (this) { + default : + return Stream.of(client.options.forwardKey, client.options.backKey).collect(Collectors.toSet()); + case LEFT : + case RIGHT : + return Stream.of(client.options.leftKey, client.options.rightKey).collect(Collectors.toSet()); + } + } } diff --git a/src/client/java/com/emonadeo/autorun/mixin/client/AutoRunMixin.java b/src/client/java/com/emonadeo/autorun/mixin/client/AutoRunMixin.java index 71cfc99..8d8c4ea 100644 --- a/src/client/java/com/emonadeo/autorun/mixin/client/AutoRunMixin.java +++ b/src/client/java/com/emonadeo/autorun/mixin/client/AutoRunMixin.java @@ -14,43 +14,27 @@ @Mixin(KeyboardInput.class) public class AutoRunMixin { - @Redirect(method = "tick", at = @At( - value = "FIELD", - target = "net/minecraft/client/input/KeyboardInput.pressingForward:Z", - opcode = Opcodes.GETFIELD, - ordinal = 0)) - private boolean onPressingForward(KeyboardInput input) { - input.pressingForward = input.pressingForward || AutoRunMod.getToggled().contains(MovementDirection.FORWARD); - return input.pressingForward; - } + @Redirect(method = "tick", at = @At(value = "FIELD", target = "net/minecraft/client/input/KeyboardInput.pressingForward:Z", opcode = Opcodes.GETFIELD, ordinal = 0)) + private boolean onPressingForward(KeyboardInput input) { + input.pressingForward = input.pressingForward || AutoRunMod.getToggled().contains(MovementDirection.FORWARD); + return input.pressingForward; + } - @Redirect(method = "tick", at = @At( - value = "FIELD", - target = "net/minecraft/client/input/KeyboardInput.pressingBack:Z", - opcode = Opcodes.GETFIELD, - ordinal = 0)) - private boolean onPressingBack(KeyboardInput input) { - input.pressingBack = input.pressingBack || AutoRunMod.getToggled().contains(MovementDirection.BACK); - return input.pressingBack; - } + @Redirect(method = "tick", at = @At(value = "FIELD", target = "net/minecraft/client/input/KeyboardInput.pressingBack:Z", opcode = Opcodes.GETFIELD, ordinal = 0)) + private boolean onPressingBack(KeyboardInput input) { + input.pressingBack = input.pressingBack || AutoRunMod.getToggled().contains(MovementDirection.BACK); + return input.pressingBack; + } - @Redirect(method = "tick", at = @At( - value = "FIELD", - target = "net/minecraft/client/input/KeyboardInput.pressingLeft:Z", - opcode = Opcodes.GETFIELD, - ordinal = 0)) - private boolean onPressingLeft(KeyboardInput input) { - input.pressingLeft = input.pressingLeft || AutoRunMod.getToggled().contains(MovementDirection.LEFT); - return input.pressingLeft; - } + @Redirect(method = "tick", at = @At(value = "FIELD", target = "net/minecraft/client/input/KeyboardInput.pressingLeft:Z", opcode = Opcodes.GETFIELD, ordinal = 0)) + private boolean onPressingLeft(KeyboardInput input) { + input.pressingLeft = input.pressingLeft || AutoRunMod.getToggled().contains(MovementDirection.LEFT); + return input.pressingLeft; + } - @Redirect(method = "tick", at = @At( - value = "FIELD", - target = "net/minecraft/client/input/KeyboardInput.pressingRight:Z", - opcode = Opcodes.GETFIELD, - ordinal = 0)) - private boolean onPressingRight(KeyboardInput input) { - input.pressingRight = input.pressingRight || AutoRunMod.getToggled().contains(MovementDirection.RIGHT); - return input.pressingRight; - } + @Redirect(method = "tick", at = @At(value = "FIELD", target = "net/minecraft/client/input/KeyboardInput.pressingRight:Z", opcode = Opcodes.GETFIELD, ordinal = 0)) + private boolean onPressingRight(KeyboardInput input) { + input.pressingRight = input.pressingRight || AutoRunMod.getToggled().contains(MovementDirection.RIGHT); + return input.pressingRight; + } } diff --git a/src/main/java/.gitkeep b/src/main/java/.gitkeep new file mode 100644 index 0000000..e69de29