Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Run On Start #20

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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