Skip to content

Commit

Permalink
Add option to persist Auto-Run between disconnects (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
wylie39 authored Mar 19, 2024
1 parent d658487 commit 071aed3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/client/java/com/emonadeo/autorun/AutoRunMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ public class AutoRunMod implements ClientModInitializer {

private static boolean originalAutoJumpSetting;
private static boolean toggleAutoJump;
private static boolean togglePersistAutoRun;

@Override
public void onInitializeClient() {
AutoRunMod.toggled = new HashSet<>();
AutoRunMod.timeActivated = -1;
AutoRunMod.delayBuffer = 20;
AutoRunMod.toggleAutoJump = true;
AutoRunMod.togglePersistAutoRun = false;
AutoRunMod.keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.autorun.toggle",
InputUtil.Type.KEYSYM,
Expand Down Expand Up @@ -95,8 +97,11 @@ public void onInitializeClient() {
ClientEntityEvents.ENTITY_UNLOAD.register((entity, clientWorld) -> {
if (entity instanceof ClientPlayerEntity) {
restoreAutoJump(MinecraftClient.getInstance());
toggled.clear();
}
if (!togglePersistAutoRun){
toggled.clear();
}
};

});
}

Expand Down Expand Up @@ -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"));
togglePersistAutoRun = Boolean.parseBoolean(cfg.getProperty("togglePersistAutoRun", "false"));

// Re-save so that new properties will appear in old config files
saveConfig(file);
Expand All @@ -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(("togglePersistAutoRun=" + togglePersistAutoRun + "\n").getBytes());
fos.close();
} catch (IOException e) {
e.printStackTrace();
Expand All @@ -165,4 +172,13 @@ public static boolean isToggleAutoJump() {
public static void setToggleAutoJump(boolean toggleAutoJump) {
AutoRunMod.toggleAutoJump = toggleAutoJump;
}

public static boolean isPersistAutoRun() {
return togglePersistAutoRun;
}

public static void setPersistAutoRun(boolean togglePersistAutoRun) {
AutoRunMod.togglePersistAutoRun = togglePersistAutoRun;
}

}
8 changes: 8 additions & 0 deletions src/client/java/com/emonadeo/autorun/AutoRunModMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ".togglePersistAutoRun"), AutoRunMod.isPersistAutoRun())
.setDefaultValue(false)
.setTooltip(Text.translatable("config." + AutoRunMod.MODID + ".togglePersistAutoRun.description"))
.setSaveConsumer(AutoRunMod::setPersistAutoRun)
.build());


// Delay Buffer
general.addEntry(entryBuilder.startIntField(Text.translatable("config." + AutoRunMod.MODID + ".delayBuffer"), AutoRunMod.getDelayBuffer())
.setDefaultValue(20)
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
@@ -1,5 +1,7 @@
{
"key.autorun.toggle": "Toggle Auto-Run",
"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",
Expand Down

0 comments on commit 071aed3

Please sign in to comment.