diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f1bfb1..a3c206c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Changed the mod's build process making supporting multiple versions much easier - Relicensed under the [zlib license](LICENSE) +- Improved toggle key behavior if the vanilla key isn't pressed but is already set to Toggle ## 1.1 - 2024-02-01 diff --git a/src/main/java/me/celestialfault/toggletogglesprint/ToggleToggleSprint.java b/src/main/java/me/celestialfault/toggletogglesprint/ToggleToggleSprint.java index 1ecaf5c..643ccef 100644 --- a/src/main/java/me/celestialfault/toggletogglesprint/ToggleToggleSprint.java +++ b/src/main/java/me/celestialfault/toggletogglesprint/ToggleToggleSprint.java @@ -72,10 +72,15 @@ private void applyJoinStates(MinecraftClient client) { } private static void toggleOption(SimpleOption toggle, KeyBinding keybind, boolean activateKey) { - toggle.setValue(!toggle.getValue()); if(toggle.getValue() && activateKey && !keybind.isPressed()) { + // if the toggle latch is already enabled but the key isn't pressed, and we're configured to simulate + // the key press, then just simulate the key press instead of turning off the latch to avoid requiring + // pressing the toggle key twice to start sprinting/sneaking. keybind.setPressed(true); - } else if(!toggle.getValue()) { + return; + } + toggle.setValue(!toggle.getValue()); + 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 @@ -83,6 +88,8 @@ private static void toggleOption(SimpleOption toggle, KeyBinding keybin // 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); + } else if(activateKey && !keybind.isPressed()) { + keybind.setPressed(true); } } }