Add "Lock Scroll While Attacking" option#63
Open
leodesca01 wants to merge 1 commit into
Open
Conversation
Adds an opt-in option (default off) to the Mouse Settings screen that ignores scroll events while the attack key is held down and the player is in game (no screen or overlay open). This prevents a small finger movement on a Magic Mouse / trackpad (or any mouse) from producing an accidental horizontal scroll that switches the selected hotbar item while mining or attacking. - The option is added for all platforms and persisted in the mod options file. - The scroll is blocked in MouseHandlerMixin (loaded on every version) at the head of onScroll, so it applies regardless of the downstream hotbar-scroll path (Inventory.scrollInHotbar vs newer). - The trigger uses options.keyAttack.isDown(), so it follows any rebind of the attack key rather than a hard-coded left mouse button.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pull request: Add "Lock Scroll While Attacking" option
Copy the title and body below into the GitHub PR form.
Title
Add "Lock Scroll While Attacking" option
Body
What this adds
A new opt-in option (default off) in the Mouse Settings screen:
Lock Scroll While Attacking.
When enabled, scroll events are ignored while the attack key is held down and
the player is in game (no screen or overlay open).
Why
On a Magic Mouse or a trackpad it is very easy to let a finger rest or drift
slightly while holding left click to mine. That drift is reported as a
horizontal scroll, which switches the selected hotbar item mid-mine. This makes
it possible to hold left click for a long time without accidentally changing
slots. It is useful on any mouse that can produce stray scroll input, so the
option is available on all platforms.
How it works
ModOptionsnext to the existing ones, added togetModOptions()for both the macOS and non-macOS lists, and persisted in themod options file as
lockScrollWhileAttacking.MouseHandlerMixin(which is loaded on everyversion) with a cancellable
@Injectat the head ofonScroll(JDD)V. Doing itat
onScrollmeans it works regardless of the downstream hotbar-scroll path(
Inventory.scrollInHotbaron older versions vs the newer handling), so noextra version-conditional mixin loading is needed.
and the player exists, so scrolling in inventories, containers, chat and menus
is never affected.
options.keyAttack.isDown(), so it follows any rebind of theattack key rather than assuming a hard-coded left mouse button.
Notes / points for review
ModernFabricReflectionHelperon 26.1+, direct field access on older versions) already used in
MouseHandlerMixin11.options.keyAttack.isDown()is written with plain (Mojmap) access. I havebuilt and run this on 26.2, where it works. I could not test the older
versions locally, so the intermediary stability of
keyAttack/isDownacross 1.14 to 1.21.11 is the one thing worth confirming in CI. If you prefer,
I can move it behind a reflection helper for the legacy target.
MixinPluginor the mixin json.I have read and agree to the CONTRIBUTING terms.