Controlify icon indicating copy to clipboard operation
Controlify copied to clipboard

Fix sneak toggle triggering when opening inventory screen

Open Copilot opened this issue 2 months ago • 0 comments

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:

  1. Enable Toggle Sneak in Controlify settings
  2. Hold sprint button and walk forward
  3. Press the Inventory button
  4. Close the inventory → Player is now sneaking unexpectedly

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 wasInScreen flag to track screen transitions and prevent the sneak toggle from triggering on the first tick after exiting a screen:

  • When a screen is open, set wasInScreen = true
  • Skip the sneak toggle logic if wasInScreen is true (first tick after screen closes)
  • Reset wasInScreen = false after processing the sneak logic

This 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:

  • Added wasInScreen boolean field to track screen state
  • Updated tick() method to set the flag when in a screen
  • Modified sneak toggle condition to check !this.wasInScreen
  • Reset flag after sneak processing

Testing

Manual testing recommended with Toggle Sneak enabled:

  • Sprint and open inventory → No unexpected sneaking ✓
  • Normal toggle sneak functionality → Works as expected ✓
  • Other movement states → Unaffected ✓

Impact

  • Fixes: Unexpected sneaking when opening screens while sprinting
  • Preserves: All existing toggle sneak functionality
  • Side effects: None - existing behavior where sneak state resets when entering screens is maintained

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
    • Triggering command: /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

This section details on the original issue you should resolve

<issue_title>[Bug] Sneaking</issue_title> <issue_description>### Current Behaviour

Whenever I press the Inventory button while sprinting, I sneak.

Expected Behaviour

I don't sneak when I press the Inventory button.

Screenshots

No response

Reproduction Steps

  1. Sprint walk
  2. Open the Inventory screen

Logs


Mod Version

v2.4.2+1.21.8

Controller

DualShock 4 Controller

Bluetooth

  • [x] Yes

Operating System

Windows

ARM

  • [ ] Yes

Additional Information

I had Toggle Sneak on.

Just to make sure...

  • [ ] I have made sure I am using the latest version of Controlify for the latest version of Minecraft.
  • [x] I have made sure there are no other issues describing the same problem on the issue tracker.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes isXander/Controlify#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.

Copilot avatar Oct 16 '25 20:10 Copilot