mojira.dev
MC-308595

The toggled sneaking/sprinting state is not restored after closing a GUI when bound to a mouse button

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

  1. Set sneak or sprint to toggle mode in Options > Controls

  2. 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)

  3. Toggle sneak or sprint on by pressing that button

  4. Open any GUI (chest, chat, inventory, etc). Observe sneaking is toggled off

  5. 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

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

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

AdyTech99

(Unassigned)

Confirmed

Platform HC

Normal

Input

26.2 Pre-Release 3

Retrieved