From 7f66e4653a67659023f96409783601ff8f849527 Mon Sep 17 00:00:00 2001 From: Wylie Fowler Date: Tue, 16 Jan 2024 22:00:46 -0500 Subject: [PATCH 1/2] Add Run On Start --- .../java/com/emonadeo/autorun/AutoRunMod.java | 20 +++++++++++++++++-- .../com/emonadeo/autorun/AutoRunModMenu.java | 8 ++++++++ .../resources/assets/autorun/lang/en_us.json | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/client/java/com/emonadeo/autorun/AutoRunMod.java b/src/client/java/com/emonadeo/autorun/AutoRunMod.java index 6305637..ceb6417 100644 --- a/src/client/java/com/emonadeo/autorun/AutoRunMod.java +++ b/src/client/java/com/emonadeo/autorun/AutoRunMod.java @@ -33,6 +33,7 @@ public class AutoRunMod implements ClientModInitializer { private static boolean originalAutoJumpSetting; private static boolean toggleAutoJump; + private static boolean toggleRunOnStart; @Override public void onInitializeClient() { @@ -40,6 +41,7 @@ public void onInitializeClient() { AutoRunMod.timeActivated = -1; AutoRunMod.delayBuffer = 20; AutoRunMod.toggleAutoJump = true; + AutoRunMod.toggleRunOnStart = false; AutoRunMod.keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( "key.autorun.toggle", InputUtil.Type.KEYSYM, @@ -95,8 +97,11 @@ public void onInitializeClient() { ClientEntityEvents.ENTITY_UNLOAD.register((entity, clientWorld) -> { if (entity instanceof ClientPlayerEntity) { restoreAutoJump(MinecraftClient.getInstance()); - toggled.clear(); - } + if (!toggleRunOnStart){ + toggled.clear(); + } + }; + }); } @@ -127,6 +132,7 @@ public static void loadConfig(File file) { cfg.load(new FileInputStream(file)); delayBuffer = Integer.parseInt(cfg.getProperty("delayBuffer", "20")); toggleAutoJump = Boolean.parseBoolean(cfg.getProperty("toggleAutoJump", "true")); + toggleRunOnStart = Boolean.parseBoolean(cfg.getProperty("runOnStart", "false")); // Re-save so that new properties will appear in old config files saveConfig(file); @@ -140,6 +146,7 @@ public static void saveConfig(File file) { FileOutputStream fos = new FileOutputStream(file, false); fos.write(("delayBuffer=" + delayBuffer + "\n").getBytes()); fos.write(("toggleAutoJump=" + toggleAutoJump + "\n").getBytes()); + fos.write(("runOnStart=" + toggleRunOnStart + "\n").getBytes()); fos.close(); } catch (IOException e) { e.printStackTrace(); @@ -165,4 +172,13 @@ public static boolean isToggleAutoJump() { public static void setToggleAutoJump(boolean toggleAutoJump) { AutoRunMod.toggleAutoJump = toggleAutoJump; } + + public static boolean isRunOnStart() { + return toggleRunOnStart; + } + + public static void setToggleRunOnStart(boolean toggleRunOnStart) { + AutoRunMod.toggleRunOnStart = toggleRunOnStart; + } + } diff --git a/src/client/java/com/emonadeo/autorun/AutoRunModMenu.java b/src/client/java/com/emonadeo/autorun/AutoRunModMenu.java index 5859442..5372389 100644 --- a/src/client/java/com/emonadeo/autorun/AutoRunModMenu.java +++ b/src/client/java/com/emonadeo/autorun/AutoRunModMenu.java @@ -30,6 +30,14 @@ public Screen create(Screen screen) { .setSaveConsumer(AutoRunMod::setToggleAutoJump) .build()); + // Toogle run on start + general.addEntry(entryBuilder.startBooleanToggle(Text.translatable("config." + AutoRunMod.MODID + ".toggleRunOnStart"), AutoRunMod.isRunOnStart()) + .setDefaultValue(false) + .setTooltip(Text.translatable("config." + AutoRunMod.MODID + ".toggleRunOnStart.description")) + .setSaveConsumer(AutoRunMod::setToggleRunOnStart) + .build()); + + // Delay Buffer general.addEntry(entryBuilder.startIntField(Text.translatable("config." + AutoRunMod.MODID + ".delayBuffer"), AutoRunMod.getDelayBuffer()) .setDefaultValue(20) diff --git a/src/main/resources/assets/autorun/lang/en_us.json b/src/main/resources/assets/autorun/lang/en_us.json index 286bea6..26fad84 100644 --- a/src/main/resources/assets/autorun/lang/en_us.json +++ b/src/main/resources/assets/autorun/lang/en_us.json @@ -1,5 +1,7 @@ { "key.autorun.toggle": "Toggle Auto-Run", + "config.autorun.toggleRunOnStart": "Toggle Run On Start", + "config.autorun.toggleRunOnStart.description": "Should the game start with last key presed?", "title.autorun.config": "AutoRun", "config.autorun.general": "General", "config.autorun.delayBuffer": "Delay Buffer", From e3eb95c03b958d28ff3eed50f4ebce9fc4529f81 Mon Sep 17 00:00:00 2001 From: Wylie Fowler Date: Sun, 21 Jan 2024 19:28:58 +0000 Subject: [PATCH 2/2] Rename toggle --- .../java/com/emonadeo/autorun/AutoRunMod.java | 18 +++++++++--------- .../com/emonadeo/autorun/AutoRunModMenu.java | 6 +++--- .../resources/assets/autorun/lang/en_us.json | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/client/java/com/emonadeo/autorun/AutoRunMod.java b/src/client/java/com/emonadeo/autorun/AutoRunMod.java index ceb6417..7afea4c 100644 --- a/src/client/java/com/emonadeo/autorun/AutoRunMod.java +++ b/src/client/java/com/emonadeo/autorun/AutoRunMod.java @@ -33,7 +33,7 @@ public class AutoRunMod implements ClientModInitializer { private static boolean originalAutoJumpSetting; private static boolean toggleAutoJump; - private static boolean toggleRunOnStart; + private static boolean togglePersistAutoRun; @Override public void onInitializeClient() { @@ -41,7 +41,7 @@ public void onInitializeClient() { AutoRunMod.timeActivated = -1; AutoRunMod.delayBuffer = 20; AutoRunMod.toggleAutoJump = true; - AutoRunMod.toggleRunOnStart = false; + AutoRunMod.togglePersistAutoRun = false; AutoRunMod.keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( "key.autorun.toggle", InputUtil.Type.KEYSYM, @@ -97,7 +97,7 @@ public void onInitializeClient() { ClientEntityEvents.ENTITY_UNLOAD.register((entity, clientWorld) -> { if (entity instanceof ClientPlayerEntity) { restoreAutoJump(MinecraftClient.getInstance()); - if (!toggleRunOnStart){ + if (!togglePersistAutoRun){ toggled.clear(); } }; @@ -132,7 +132,7 @@ public static void loadConfig(File file) { cfg.load(new FileInputStream(file)); delayBuffer = Integer.parseInt(cfg.getProperty("delayBuffer", "20")); toggleAutoJump = Boolean.parseBoolean(cfg.getProperty("toggleAutoJump", "true")); - toggleRunOnStart = Boolean.parseBoolean(cfg.getProperty("runOnStart", "false")); + togglePersistAutoRun = Boolean.parseBoolean(cfg.getProperty("togglePersistAutoRun", "false")); // Re-save so that new properties will appear in old config files saveConfig(file); @@ -146,7 +146,7 @@ public static void saveConfig(File file) { FileOutputStream fos = new FileOutputStream(file, false); fos.write(("delayBuffer=" + delayBuffer + "\n").getBytes()); fos.write(("toggleAutoJump=" + toggleAutoJump + "\n").getBytes()); - fos.write(("runOnStart=" + toggleRunOnStart + "\n").getBytes()); + fos.write(("togglePersistAutoRun=" + togglePersistAutoRun + "\n").getBytes()); fos.close(); } catch (IOException e) { e.printStackTrace(); @@ -173,12 +173,12 @@ public static void setToggleAutoJump(boolean toggleAutoJump) { AutoRunMod.toggleAutoJump = toggleAutoJump; } - public static boolean isRunOnStart() { - return toggleRunOnStart; + public static boolean isPersistAutoRun() { + return togglePersistAutoRun; } - public static void setToggleRunOnStart(boolean toggleRunOnStart) { - AutoRunMod.toggleRunOnStart = toggleRunOnStart; + public static void setPersistAutoRun(boolean togglePersistAutoRun) { + AutoRunMod.togglePersistAutoRun = togglePersistAutoRun; } } diff --git a/src/client/java/com/emonadeo/autorun/AutoRunModMenu.java b/src/client/java/com/emonadeo/autorun/AutoRunModMenu.java index 5372389..9b3983c 100644 --- a/src/client/java/com/emonadeo/autorun/AutoRunModMenu.java +++ b/src/client/java/com/emonadeo/autorun/AutoRunModMenu.java @@ -31,10 +31,10 @@ public Screen create(Screen screen) { .build()); // Toogle run on start - general.addEntry(entryBuilder.startBooleanToggle(Text.translatable("config." + AutoRunMod.MODID + ".toggleRunOnStart"), AutoRunMod.isRunOnStart()) + general.addEntry(entryBuilder.startBooleanToggle(Text.translatable("config." + AutoRunMod.MODID + ".togglePersistAutoRun"), AutoRunMod.isPersistAutoRun()) .setDefaultValue(false) - .setTooltip(Text.translatable("config." + AutoRunMod.MODID + ".toggleRunOnStart.description")) - .setSaveConsumer(AutoRunMod::setToggleRunOnStart) + .setTooltip(Text.translatable("config." + AutoRunMod.MODID + ".togglePersistAutoRun.description")) + .setSaveConsumer(AutoRunMod::setPersistAutoRun) .build()); diff --git a/src/main/resources/assets/autorun/lang/en_us.json b/src/main/resources/assets/autorun/lang/en_us.json index 26fad84..ddd70c2 100644 --- a/src/main/resources/assets/autorun/lang/en_us.json +++ b/src/main/resources/assets/autorun/lang/en_us.json @@ -1,7 +1,7 @@ { "key.autorun.toggle": "Toggle Auto-Run", - "config.autorun.toggleRunOnStart": "Toggle Run On Start", - "config.autorun.toggleRunOnStart.description": "Should the game start with last key presed?", + "config.autorun.togglePersistAutoRun": "Persist Auto-Run", + "config.autorun.togglePersistAutoRun.description": "Keep Auto-Run toggled between leaving and joining worlds or servers", "title.autorun.config": "AutoRun", "config.autorun.general": "General", "config.autorun.delayBuffer": "Delay Buffer",