Skip to content

Commit

Permalink
Add config option to show/hide message
Browse files Browse the repository at this point in the history
Signed-off-by: Emanuel Pilz <emonadeo@gmail.com>
  • Loading branch information
emonadeo committed Nov 22, 2024
1 parent c02ea6c commit ea1d7f6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/emonadeo/autorun/AutoRunMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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) {
Expand Down
36 changes: 24 additions & 12 deletions src/main/java/com/emonadeo/autorun/AutoRunModMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(() -> {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/autorun/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/autorun/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ea1d7f6

Please # to comment.