diff --git a/.editorconfig b/.editorconfig index a71173d..2cde7e5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,6 +5,13 @@ insert_final_newline = true tab_width = 4 indent_style = tab +[*.java] +ij_any_space_before_if_parentheses = false +ij_any_space_before_for_parentheses = false +ij_any_space_before_while_parentheses = false +ij_any_space_before_try_parentheses = false +ij_any_space_before_catch_parentheses = false + [*.md] indent_style = space indent_size = 2 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ab6f403 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,25 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## 1.1 - Unreleased + +### Added + +- This changelog file +- Added default bindings for the toggle keys using the right-side versions of the default vanilla key, such as Right Shift + to match the default Left Shift for the Sneak key + +### Changed + +- Improved behavior around toggling a key off while the vanilla key is still being held + - In other words: if you toggle sprint off while holding the vanilla sprint key, you will now continue to sprint after + toggling it off, instead of having to stop holding and then press the vanilla key again +- Changed some configuration menu names and descriptions to better describe the relevant settings + +## 1.0 - 2024-01-05 + +- Initial release diff --git a/README.md b/README.md index f5d393f..e8efbdf 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # Toggle Toggle Sprint [![Requires Fabric API](https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/requires/fabric-api_vector.svg)](https://modrinth.com/mod/fabric-api) +[![Available on Modrinth](https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/available/modrinth_vector.svg)](https://modrinth.com/mod/toggle-toggle-sprint) + +This is a Fabric mod for Minecraft adding toggle-sprint/sneak keybinds, making use of the existing Toggle options +in the Controls menu, ensuring it also remains as anti-cheat friendly as possible. -This is a Fabric mod for Minecraft adding toggle-sprint/sneak keybinds, making use of the vanilla toggle states in the -Controls menu to ensure that it remains as anti-cheat friendly as possible. This also includes a fix for preventing the game from resetting your toggle sprint upon death. If both [Mod Menu] and [YACL] are installed, this mod also contains a few configuration options that can be modified in-game. @@ -20,6 +22,12 @@ to do so in vanilla!)*, making it trivially easy to be flagged (and subsequently Instead, as this mod simply reuses the existing Toggle option in the Controls menu, this ensures that it remains as close to the vanilla sprinting behavior as possible, avoiding anti-cheats getting angry in the process. +## Modpacks? + +Go for it. I'd prefer that the download remains within the Modrinth ecosystem, but as this mod is licensed under [CC-0], +you're free to redistribute it however you see fit (but I'd still appreciate credit where possible). + [YACL]: https://modrinth.com/mod/yacl [Mod Menu]: https://modrinth.com/mod/modmenu [Toggle Sneak & Sprint]: https://modrinth.com/mod/toggle-sneak-sprint +[CC-0]: https://github.com/celestialfault/toggle-toggle-sprint/blob/main/LICENSE diff --git a/gradle.properties b/gradle.properties index 4f38a00..5e9fb4c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.20.2+build.4 loader_version=0.15.3 # Mod Properties -mod_version=1.0.0 +mod_version=1.1 maven_group=me.celestialfault.toggletogglesprint archives_base_name=toggle-toggle-sprint diff --git a/src/main/java/me/celestialfault/toggletogglesprint/Config.java b/src/main/java/me/celestialfault/toggletogglesprint/Config.java index 06e6e62..8f1ecda 100644 --- a/src/main/java/me/celestialfault/toggletogglesprint/Config.java +++ b/src/main/java/me/celestialfault/toggletogglesprint/Config.java @@ -93,7 +93,7 @@ public Screen getConfigScreen(Screen parent) { return YetAnotherConfigLib.createBuilder() .title(Text.translatable("toggle-toggle-sprint.name")) .category(ConfigCategory.createBuilder() - .name(Text.translatable("toggle-toggle-sprint.name")) + .name(Text.translatable("toggle-toggle-sprint.config")) .group(buildGeneral()) .group(buildSprint()) .group(buildSneak()) @@ -108,7 +108,12 @@ private OptionGroup buildGeneral() { .name(Text.translatable("toggle-toggle-sprint.general")) .option(Option.createBuilder() .name(Text.translatable("toggle-toggle-sprint.sprintOnDeath")) - .description(OptionDescription.of(Text.translatable("toggle-toggle-sprint.sprintOnDeath.description"))) + .description(OptionDescription.of( + Text.translatable("toggle-toggle-sprint.sprintOnDeath.description.line1") + .append("\n\n") + .append(Text.translatable("toggle-toggle-sprint.sprintOnDeath.description.line2")) + .append("\n\n") + .append(Text.translatable("toggle-toggle-sprint.sprintOnDeath.description.line3")))) .binding(true, () -> keepSprintingOnDeath, value -> this.keepSprintingOnDeath = value) .controller(TickBoxControllerBuilderImpl::new) .build()) @@ -154,7 +159,7 @@ private OptionGroup buildSneak() { .description(OptionDescription.of( Text.translatable("toggle-toggle-sprint.sneakOnJoin.description") .append("\n\n") - .append(Text.translatable("toggle-toggle-sprint.sneakOnJoin.warning").formatted(Formatting.RED)))) + .append(Text.translatable("toggle-toggle-sprint.potentiallyCheaty").formatted(Formatting.RED)))) .binding(false, () -> sneakOnJoin, sneakOnJoin -> this.sneakOnJoin = sneakOnJoin) .controller(TickBoxControllerBuilderImpl::new) .build()) diff --git a/src/main/java/me/celestialfault/toggletogglesprint/ToggleToggleSprint.java b/src/main/java/me/celestialfault/toggletogglesprint/ToggleToggleSprint.java index abaa3de..d0d3427 100644 --- a/src/main/java/me/celestialfault/toggletogglesprint/ToggleToggleSprint.java +++ b/src/main/java/me/celestialfault/toggletogglesprint/ToggleToggleSprint.java @@ -8,6 +8,7 @@ import net.minecraft.client.option.KeyBinding; import net.minecraft.client.option.SimpleOption; import net.minecraft.client.util.InputUtil; +import org.lwjgl.glfw.GLFW; import org.slf4j.Logger; public class ToggleToggleSprint implements ClientModInitializer { @@ -15,12 +16,12 @@ public class ToggleToggleSprint implements ClientModInitializer { public static final Logger LOGGER = LogUtils.getLogger(); private boolean inWorld = false; - public static final OnPressKeyBinding TOGGLE_SPRINT = new OnPressKeyBinding("key.toggle-toggle-sprint.sprint", InputUtil.UNKNOWN_KEY.getCode(), KeyBinding.MOVEMENT_CATEGORY, () -> { + public static final OnPressKeyBinding TOGGLE_SPRINT = new OnPressKeyBinding("key.toggle-toggle-sprint.sprint", GLFW.GLFW_KEY_RIGHT_CONTROL, KeyBinding.MOVEMENT_CATEGORY, () -> { MinecraftClient client = MinecraftClient.getInstance(); toggleOption(client.options.sprintToggled, client.options.sprintKey, Config.INSTANCE.alsoStartSprinting); }); - public static final OnPressKeyBinding TOGGLE_SNEAK = new OnPressKeyBinding("key.toggle-toggle-sprint.sneak", InputUtil.UNKNOWN_KEY.getCode(), KeyBinding.MOVEMENT_CATEGORY, () -> { + public static final OnPressKeyBinding TOGGLE_SNEAK = new OnPressKeyBinding("key.toggle-toggle-sprint.sneak", GLFW.GLFW_KEY_RIGHT_SHIFT, KeyBinding.MOVEMENT_CATEGORY, () -> { MinecraftClient client = MinecraftClient.getInstance(); toggleOption(client.options.sneakToggled, client.options.sneakKey, Config.INSTANCE.alsoStartSneaking); }); @@ -36,17 +37,16 @@ private void onTick(MinecraftClient client) { if(client.world == null && inWorld) { inWorld = false; } else if(client.world != null && !inWorld) { - doDefaultState(client); - setKeybindStates(client); + applyJoinStates(client); inWorld = true; } } - private void doDefaultState(MinecraftClient client) { + private void applyJoinStates(MinecraftClient client) { // Default sprint state if(Config.INSTANCE.defaultSprintState == Config.ToggleState.ON) { client.options.sprintToggled.setValue(true); - // pressing the key is dealt with by #setKeybindStates() + // pressing the key is done later } else if(Config.INSTANCE.defaultSprintState == Config.ToggleState.OFF) { client.options.sprintToggled.setValue(false); // ... but, we still want to ensure that the key is unpressed if we're loading into a world for a @@ -61,9 +61,8 @@ private void doDefaultState(MinecraftClient client) { client.options.sneakToggled.setValue(false); client.options.sneakKey.setPressed(false); } - } - private void setKeybindStates(MinecraftClient client) { + // Press the keys if they're configured to be pressed when joining a world, and the relevant toggle latch is on if(Config.INSTANCE.sprintOnJoin && client.options.sprintToggled.getValue() && !client.options.sprintKey.isPressed()) { client.options.sprintKey.setPressed(true); } @@ -74,6 +73,16 @@ private void setKeybindStates(MinecraftClient client) { private static void toggleOption(SimpleOption toggle, KeyBinding keybind, boolean activateKey) { toggle.setValue(!toggle.getValue()); - if(activateKey && !keybind.isPressed() || !toggle.getValue()) keybind.setPressed(toggle.getValue()); + if(toggle.getValue() && activateKey && !keybind.isPressed()) { + keybind.setPressed(true); + } else if(!toggle.getValue()) { + long handle = MinecraftClient.getInstance().getWindow().getHandle(); + boolean manuallyHeld = InputUtil.isKeyPressed(handle, KeyBindingHelper.getBoundKeyOf(keybind).getCode()); + // note that we always call this with the value of manuallyHeld in order to handle the case where the player + // presses the vanilla key, thereby toggling the key's held state off, and then pressing our toggle key, + // turning off the toggle latch; in such a case, the game wouldn't think the key is being pressed, when + // it should logically be pressed. + keybind.setPressed(manuallyHeld); + } } } diff --git a/src/main/resources/assets/toggle-toggle-sprint/lang/en_us.json b/src/main/resources/assets/toggle-toggle-sprint/lang/en_us.json index 5c48bb3..3df2745 100644 --- a/src/main/resources/assets/toggle-toggle-sprint/lang/en_us.json +++ b/src/main/resources/assets/toggle-toggle-sprint/lang/en_us.json @@ -1,10 +1,13 @@ { "toggle-toggle-sprint.name": "Toggle Toggle Sprint", + "toggle-toggle-sprint.config": "Configuration", "toggle-toggle-sprint.noYacl": "This requires Yet Another Config Lib to be installed!", "toggle-toggle-sprint.general": "General", "toggle-toggle-sprint.sprint": "Sprint", "toggle-toggle-sprint.sneak": "Sneak", + "toggle-toggle-sprint.potentiallyCheaty": "Some servers may consider this feature to be a cheat, use at your own risk!", + "key.toggle-toggle-sprint.sprint": "Toggle Sprint", "key.toggle-toggle-sprint.sneak": "Toggle Sneak", @@ -12,27 +15,28 @@ "toggle-toggle-sprint.state.off": "Off", "toggle-toggle-sprint.state.unchanged": "Don't modify", - "toggle-toggle-sprint.sprintOnDeath": "Keep sprinting on death", - "toggle-toggle-sprint.sprintOnDeath.description": "If enabled, your sprinting won't be broken upon respawning", + "toggle-toggle-sprint.sprintOnDeath": "Keep sprinting after death", + "toggle-toggle-sprint.sprintOnDeath.description.line1": "As of 1.20.1, the game will release all toggled keys when the player respawns, including the Sprint key.", + "toggle-toggle-sprint.sprintOnDeath.description.line2": "This feature prevents vanilla from releasing your sprint key, ensuring that you continue to sprint after respawning.", + "toggle-toggle-sprint.sprintOnDeath.description.line3": "Note that this feature only affects the Sprint key, and all other toggle keys (such as the Sneak key) will still be released.", - "toggle-toggle-sprint.sprintOnJoin": "Sprint when joining", - "toggle-toggle-sprint.sprintOnJoin.description": "If enabled, you'll start sprinting upon joining a world if your sprint key is set to toggle", + "toggle-toggle-sprint.sprintOnJoin": "Start sprinting", + "toggle-toggle-sprint.sprintOnJoin.description": "If enabled, you'll start sprinting when loading into a world if your Sprint control is set to Toggle", "toggle-toggle-sprint.sprintState": "Default sprinting state", - "toggle-toggle-sprint.sprintState.description": "Changes your default state for sprinting when joining a world", - "toggle-toggle-sprint.sprintState.on": "Your sprint option will be changed to Toggle when joining a world", - "toggle-toggle-sprint.sprintState.off": "Your sprint option will be changed to Hold when joining a world", - "toggle-toggle-sprint.sprintState.unchanged": "Your sprint option won't be changed when joining a world", + "toggle-toggle-sprint.sprintState.description": "Changes your default state for sprinting", + "toggle-toggle-sprint.sprintState.on": "Your Sprint control will be changed to Toggle when joining a world", + "toggle-toggle-sprint.sprintState.off": "Your Sprint control will be changed to Hold when joining a world", + "toggle-toggle-sprint.sprintState.unchanged": "Your Sprint control won't be modified when joining a world", "toggle-toggle-sprint.alsoStartSprinting": "Also start sprinting", - "toggle-toggle-sprint.alsoStartSprinting.description": "When enabled, the toggle key will also simulate a sprint key press when activated", + "toggle-toggle-sprint.alsoStartSprinting.description": "When enabled, the toggle key will also simulate a Sprint key press when activated if you're not already sprinting", - "toggle-toggle-sprint.sneakOnJoin": "Sneak when joining", - "toggle-toggle-sprint.sneakOnJoin.description": "If enabled, you'll start sneaking whenever you join a world if your sneak key is set to toggle", - "toggle-toggle-sprint.sneakOnJoin.warning": "WARNING: Some servers may consider this to be a cheat, use at your own risk!", + "toggle-toggle-sprint.sneakOnJoin": "Start sneaking", + "toggle-toggle-sprint.sneakOnJoin.description": "If enabled, you'll start sneaking when loading into a world if your Sneak control is set to Toggle", "toggle-toggle-sprint.sneakState": "Default sneaking state", - "toggle-toggle-sprint.sneakState.description": "Changes your default state for sneaking when joining a world", - "toggle-toggle-sprint.sneakState.on": "Your sneak option will be changed to Toggle when joining a world", - "toggle-toggle-sprint.sneakState.off": "Your sneak option will be changed to Hold when joining a world", - "toggle-toggle-sprint.sneakState.unchanged": "Your sneak option won't be changed when joining a world", + "toggle-toggle-sprint.sneakState.description": "Changes the default state for your Sneak control", + "toggle-toggle-sprint.sneakState.on": "Your Sneak control will be changed to Toggle when joining a world", + "toggle-toggle-sprint.sneakState.off": "Your Sneak control will be changed to Hold when joining a world", + "toggle-toggle-sprint.sneakState.unchanged": "Your Sneak control won't be modified when joining a world", "toggle-toggle-sprint.alsoStartSneaking": "Also start sneaking", - "toggle-toggle-sprint.alsoStartSneaking.description": "When enabled, the toggle key will also simulate a sneak key press when activated" + "toggle-toggle-sprint.alsoStartSneaking.description": "When enabled, the toggle key will also simulate a Sneak key press when activated if you're not already sneaking" } \ No newline at end of file