Description
When Sneak or Sprint is set to toggle mode in the controls, the game forces the toggle off when a GUI (inventory, chat, container, etc) is opened. For keyboard keys, the previous toggle state is correctly restored when the GUI is closed. However, if the sneak or sprint key is bound to a mouse button (eg: mouse button 4 in a gaming mouse), the toggle is not restored and the player must manually resume sprinting/sneaking
Steps to reproduce
Set sneak or sprint to toggle mode in Options > Controls
Bind sneak or sprint to a mouse button (eg: a side mouse button if present, or just normal left/right mouse button. Temporarily unbind attack / place if needed to avoid conflicts)
Toggle sneak or sprint on by pressing that button
Open any GUI (chest, chat, inventory, etc). Observe sneaking is toggled off
Close the GUI. Observe sneaking is not toggled back on
Expected result
The previous sneak/sprint state is restored, and the player resumes sneaking/sprinting
Actual result
The player remains not sneaking/not sprinting.
This works correctly if the button is bound to a keyboard button (eg: Shift), but not when it is bound to a mouse button (eg: button 4, LMB)
Environment
macOS 15.7.3, Java 25
Comments 5
I’ve also encountered this bug: in 26.3 and I remember it from some previous versions
Environment
Windows 11, Java 25
Can confirm this has been happening since MC-163218 was fixed
thought it was an oversight when that was implemented since then, only realized it was only an issue of bound to a mouse key today
hope it gets resolved soon, very annoying having to constantly re-enable my sprinting when using the chat or inventory
It seems to be happening because ToggleKeyMapping is doing this.key.getType() == Type.KEYBOARD when determining if it should re-enable the sprinting/sneaking in method shouldRestoreStateOnScreenClosed()
Removing this check fixed the issue on my end, tho I assume the check is there for a reason I don’t know about, but if not, it should be as simple as removing that to fix this issue
(there should be an edit button) I’m gonna make an assumption that it is checking keyboard so the toggle for attacking and toggle for placing blocks/using items, which are both mouse by default, don’t keep running when you close a GUI
so my guess is then the best fix would be checking if the default key is mouse, or some other similar solution
Can confirm. This happens back in 1.21.9 and the bugged behavior persists in the released version of 26.2.
Environment
macOS 26.5.1, Java 25