Skip to content

Add "Lock Scroll While Attacking" option#63

Open
leodesca01 wants to merge 1 commit into
hamarb123:mainfrom
leodesca01:feature/lock-scroll-while-attacking
Open

Add "Lock Scroll While Attacking" option#63
leodesca01 wants to merge 1 commit into
hamarb123:mainfrom
leodesca01:feature/lock-scroll-while-attacking

Conversation

@leodesca01

Copy link
Copy Markdown

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

  • The option is declared in ModOptions next to the existing ones, added to
    getModOptions() for both the macOS and non-macOS lists, and persisted in the
    mod options file as lockScrollWhileAttacking.
  • The scroll is cancelled in MouseHandlerMixin (which is loaded on every
    version) with a cancellable @Inject at the head of onScroll(JDD)V. Doing it
    at onScroll means it works regardless of the downstream hotbar-scroll path
    (Inventory.scrollInHotbar on older versions vs the newer handling), so no
    extra version-conditional mixin loading is needed.
  • The guard only cancels when the option is on, there is no screen/overlay open
    and the player exists, so scrolling in inventories, containers, chat and menus
    is never affected.
  • The trigger is options.keyAttack.isDown(), so it follows any rebind of the
    attack key rather than assuming a hard-coded left mouse button.

Notes / points for review

  • Screen/overlay checks reuse the existing pattern (ModernFabricReflectionHelper
    on 26.1+, direct field access on older versions) already used in
    MouseHandlerMixin11.
  • options.keyAttack.isDown() is written with plain (Mojmap) access. I have
    built and run this on 26.2, where it works. I could not test the older
    versions locally, so the intermediary stability of keyAttack / isDown
    across 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.
  • No new mixin classes, no changes to MixinPlugin or the mixin json.

I have read and agree to the CONTRIBUTING terms.

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.
@CLAassistant

CLAassistant commented Jul 22, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants