From ea1d7f678ad3657c61c50e1f468c525cd030549a Mon Sep 17 00:00:00 2001 From: Emanuel Pilz Date: Fri, 22 Nov 2024 17:27:39 +0100 Subject: [PATCH] Add config option to show/hide message Signed-off-by: Emanuel Pilz --- gradle.properties | 2 +- .../java/com/emonadeo/autorun/AutoRunMod.java | 15 +++++--- .../com/emonadeo/autorun/AutoRunModMenu.java | 36 ++++++++++++------- .../resources/assets/autorun/lang/de_de.json | 2 ++ .../resources/assets/autorun/lang/en_us.json | 2 ++ 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5a2dbe9..29e111c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.21.2+build.1 loader_version=0.16.7 # Mod Properties -mod_version=1.0.0 +mod_version=1.1.0 maven_group=com.emonadeo archives_base_name=autorun diff --git a/src/main/java/com/emonadeo/autorun/AutoRunMod.java b/src/main/java/com/emonadeo/autorun/AutoRunMod.java index 5e975d7..0026f08 100644 --- a/src/main/java/com/emonadeo/autorun/AutoRunMod.java +++ b/src/main/java/com/emonadeo/autorun/AutoRunMod.java @@ -27,9 +27,10 @@ public class AutoRunMod implements ClientModInitializer { public static final File CFG_FILE = new File(FabricLoader.getInstance().getConfigDir().toFile(), "autorun.properties"); - public static boolean toggleAutoJump = true; - public static boolean persistAutoRun = false; public static boolean alwaysSprint = false; + public static boolean persistAutoRun = false; + public static boolean showMessage = true; + public static boolean toggleAutoJump = true; public static boolean forward = false; public static boolean backward = false; @@ -93,7 +94,9 @@ public void onInitializeClient() { } private static void enableAutoRun(Minecraft client) { - client.player.displayClientMessage(Component.literal("Activating Auto-Run"), false); + if (showMessage) { + client.player.displayClientMessage(Component.literal("Activating Auto-Run"), false); + } if (toggleAutoJump) { originalAutoJumpSetting = client.options.autoJump().get(); @@ -126,7 +129,9 @@ private static void enableAutoRun(Minecraft client) { } private static void disableAutoRun(Minecraft client) { - client.player.displayClientMessage(Component.literal("Deactivating Auto-Run"), false); + if (showMessage) { + client.player.displayClientMessage(Component.literal("Deactivating Auto-Run"), false); + } forward = false; backward = false; @@ -150,6 +155,7 @@ public static void loadConfig(File file) { cfg.load(new FileInputStream(file)); alwaysSprint = Boolean.parseBoolean(cfg.getProperty("alwaysSprint", "false")); persistAutoRun = Boolean.parseBoolean(cfg.getProperty("persistAutoRun", "false")); + showMessage = Boolean.parseBoolean(cfg.getProperty("showMessage", "true")); toggleAutoJump = Boolean.parseBoolean(cfg.getProperty("toggleAutoJump", "true")); } catch (IOException e) { e.printStackTrace(); @@ -161,6 +167,7 @@ public static void saveConfig(File file) { FileOutputStream fos = new FileOutputStream(file, false); fos.write(("alwaysSprint=" + alwaysSprint + "\n").getBytes()); fos.write(("persistAutoRun=" + persistAutoRun + "\n").getBytes()); + fos.write(("showMessage=" + showMessage + "\n").getBytes()); fos.write(("toggleAutoJump=" + toggleAutoJump + "\n").getBytes()); fos.close(); } catch (IOException e) { diff --git a/src/main/java/com/emonadeo/autorun/AutoRunModMenu.java b/src/main/java/com/emonadeo/autorun/AutoRunModMenu.java index ab5beef..cf63cd2 100644 --- a/src/main/java/com/emonadeo/autorun/AutoRunModMenu.java +++ b/src/main/java/com/emonadeo/autorun/AutoRunModMenu.java @@ -26,16 +26,16 @@ public Screen create(Screen screen) { ConfigCategory general = builder .getOrCreateCategory(Component.translatable("config." + AutoRunMod.MODID + ".general")); - // Toogle Auto-Jump + // Always Sprint general.addEntry(entryBuilder .startBooleanToggle( Component.translatable( - "config." + AutoRunMod.MODID + ".toggleAutoJump"), - AutoRunMod.toggleAutoJump) - .setDefaultValue(true) + "config." + AutoRunMod.MODID + ".alwaysSprint"), + AutoRunMod.alwaysSprint) + .setDefaultValue(false) .setTooltip(Component.translatable( - "config." + AutoRunMod.MODID + ".toggleAutoJump.description")) - .setSaveConsumer((value) -> AutoRunMod.toggleAutoJump = value) + "config." + AutoRunMod.MODID + ".alwaysSprint")) + .setSaveConsumer((value) -> AutoRunMod.alwaysSprint = value) .build()); // Persist Auto-Run @@ -50,16 +50,28 @@ public Screen create(Screen screen) { .setSaveConsumer((value) -> AutoRunMod.persistAutoRun = value) .build()); - // Always Sprint + // Show Message general.addEntry(entryBuilder .startBooleanToggle( Component.translatable( - "config." + AutoRunMod.MODID + ".alwaysSprint"), - AutoRunMod.alwaysSprint) - .setDefaultValue(false) + "config." + AutoRunMod.MODID + ".showMessage"), + AutoRunMod.showMessage) + .setDefaultValue(true) .setTooltip(Component.translatable( - "config." + AutoRunMod.MODID + ".alwaysSprint")) - .setSaveConsumer((value) -> AutoRunMod.alwaysSprint = value) + "config." + AutoRunMod.MODID + ".showMessage.description")) + .setSaveConsumer((value) -> AutoRunMod.showMessage = value) + .build()); + + // Toggle Auto-Jump + general.addEntry(entryBuilder + .startBooleanToggle( + Component.translatable( + "config." + AutoRunMod.MODID + ".toggleAutoJump"), + AutoRunMod.toggleAutoJump) + .setDefaultValue(true) + .setTooltip(Component.translatable( + "config." + AutoRunMod.MODID + ".toggleAutoJump.description")) + .setSaveConsumer((value) -> AutoRunMod.toggleAutoJump = value) .build()); return builder.setSavingRunnable(() -> { diff --git a/src/main/resources/assets/autorun/lang/de_de.json b/src/main/resources/assets/autorun/lang/de_de.json index f5e6f3b..ac713ef 100644 --- a/src/main/resources/assets/autorun/lang/de_de.json +++ b/src/main/resources/assets/autorun/lang/de_de.json @@ -4,6 +4,8 @@ "config.autorun.alwaysSprint.description": "Sprinte dauerhaft beim automatischen Laufen", "config.autorun.persistAutoRun": "Automatisches Laufen speichern", "config.autorun.persistAutoRun.description": "Reaktiviere automatisches Laufen zwischen Welt- und Serverwechsel", + "config.autorun.showMessage": "Zeige Nachricht", + "config.autorun.showMessage.description": "Zeige bei (De-)Aktivierung eine Nachricht im Chat an", "config.autorun.toggleAutoJump": "Automatisch springen", "config.autorun.toggleAutoJump.description": "Aktiviere automatisches Springen beim automatischen Laufen", "key.autorun.toggle": "Automatisch laufen", diff --git a/src/main/resources/assets/autorun/lang/en_us.json b/src/main/resources/assets/autorun/lang/en_us.json index ed3ec92..747533a 100644 --- a/src/main/resources/assets/autorun/lang/en_us.json +++ b/src/main/resources/assets/autorun/lang/en_us.json @@ -4,6 +4,8 @@ "config.autorun.alwaysSprint.description": "Always sprint while Auto-Run is active", "config.autorun.persistAutoRun": "Persist Auto-Run", "config.autorun.persistAutoRun.description": "Keep Auto-Run toggled between leaving and joining worlds or servers", + "config.autorun.showMessage": "Show message", + "config.autorun.showMessage.description": "Show a chat message when Auto-Run is toggled", "config.autorun.toggleAutoJump": "Toggle Auto-Jump", "config.autorun.toggleAutoJump.description": "Enable Auto-Jump while Auto-Run is active", "key.autorun.toggle": "Toggle Auto-Run",