Fix sneak toggle triggering when opening inventory screen #692
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes [Bug] Sneaking issue where players with Toggle Sneak enabled would unexpectedly start sneaking when opening the inventory screen while sprinting.
Problem
When a player has Toggle Sneak enabled and opens the inventory (or any screen) while sprinting, they would start sneaking after closing the screen. This happened consistently and was particularly noticeable with the following reproduction steps:
Root Cause
When a screen opens,
ControllerPlayerMovement.tick()returns early and resets all movement state, including setting the sneak state to false. When the screen closes and normal game logic resumes, the sneak toggle logic executes. Due to binding state transitions during the screen open/close cycle,sneak.justPressed()could return true on the first tick after the screen closes, causing the toggle logic to activate and switch sneaking from false to true.Solution
Added a
wasInScreenflag to track screen transitions and prevent the sneak toggle from triggering on the first tick after exiting a screen:wasInScreen = truewasInScreenis true (first tick after screen closes)wasInScreen = falseafter processing the sneak logicThis prevents spurious toggle events during screen transitions while preserving normal toggle sneak functionality in all other scenarios.
Changes
Modified
src/main/java/dev/isxander/controlify/ingame/ControllerPlayerMovement.java:wasInScreenboolean field to track screen statetick()method to set the flag when in a screen!this.wasInScreenTesting
Manual testing recommended with Toggle Sneak enabled:
Impact
Tested scenario is from the original bug report using a DualShock 4 controller, but the fix applies to all controller types.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
maven.kikugie.dev/usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx4G -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-9.0.0-bin/d6wjpkvcgsg3oed0qlfss3wgl/gradle-9.0.0/lib/gradle-daemon-main-9.0.0.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-9.0.0-bin/d6wjpkvcgsg3oed0qlfss3wgl/gradle-9.0.0/lib/agents/gradle-instrumentation-agent-9.0.0.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 9.0.0(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Fixes #688
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.