Skip to content

Commit

Permalink
improve behavior when the vanilla key isnt pressed but is set to toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
celestialfault committed Sep 11, 2024
1 parent 463c94e commit 4fe200d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,24 @@ private void applyJoinStates(MinecraftClient client) {
}

private static void toggleOption(SimpleOption<Boolean> 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
// 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);
} else if(activateKey && !keybind.isPressed()) {
keybind.setPressed(true);
}
}
}

0 comments on commit 4fe200d

Please sign in to comment.