[GH-ISSUE #6213] Native mods: interaction key presses, InputEvent.InteractionKeyMappingTriggered #2019

Closed
opened 2026-11-02 15:51:24 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @levzzz5154 on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6213

Originally assigned to: @levzzz5154 on GitHub.

🤖 Filed by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally.

Part of #4953 ("Interaction-key events (InputEvent.InteractionKeyMappingTriggered); raw mouse buttons, keyboard input and scrolling are done (#6010, #6023, #6027)").

A native mod can read raw keys and mouse buttons (native_input_key, native_mouse_button_pre, native_mouse_scrolling), but those come before the game decides what the press means. A mod that wants to stop "attack", "use item" or "pick block" itself (a wrench that takes the use key on its own blocks, a tool that must not start digging, a mode that turns the attack key into something else) has to guess from the raw button and the key bindings. NeoForge answers with InputEvent.InteractionKeyMappingTriggered, a cancellable event for the three key mappings that act on the crosshair.

Vanilla 26.3 and NeoForge:

  • Minecraft.handleKeybinds drains keyAttack, keyUse and keyPickItem clicks into startAttack, startUseItem and pickBlockOrEntity, then continueAttack for the held attack key and startUseItem for the held use key.
  • NeoForge posts the event with (button, keyMapping, hand): button 0 (attack) in startAttack after the checks that stop an attack (miss time, busy hands, spectator, cannotAttackWithItem) and in continueAttack just before continueDestroyBlock; button 1 (use) once per hand in startUseItem, before that hand's target and item; button 2 (pick) in pickBlockOrEntity once there is a target. A cancel skips the action; setSwingHand(true) (the default) swings the hand anyway.

Horizon's client (the window of a single player on the server thread, a LAN guest or a server's player, remote set) runs this in remote_start_attack, remote_continue_attack, remote_use / remote_use_hands and the pick in RemoteInputWorld. Proposed hook, in the shape of the other client input hooks:

  • native_interaction_key(button, key_mapping, hand, swing_hand, canceled): button 0 attack, 1 use, 2 pick; key_mapping the vanilla name (key.attack, key.use, key.pickItem); hand the hand acting. A mod sets canceled to skip the action and may clear swing_hand to skip the swing a cancel otherwise still makes.

Client side only. The deprecated in-frame path is not touched. API from a fragment.

Originally created by @levzzz5154 on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6213 Originally assigned to: @levzzz5154 on GitHub. > 🤖 Filed by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally. Part of #4953 ("Interaction-key events (`InputEvent.InteractionKeyMappingTriggered`); raw mouse buttons, keyboard input and scrolling are done (#6010, #6023, #6027)"). A native mod can read raw keys and mouse buttons (`native_input_key`, `native_mouse_button_pre`, `native_mouse_scrolling`), but those come before the game decides what the press means. A mod that wants to stop "attack", "use item" or "pick block" itself (a wrench that takes the use key on its own blocks, a tool that must not start digging, a mode that turns the attack key into something else) has to guess from the raw button and the key bindings. NeoForge answers with `InputEvent.InteractionKeyMappingTriggered`, a cancellable event for the three key mappings that act on the crosshair. Vanilla 26.3 and NeoForge: - `Minecraft.handleKeybinds` drains `keyAttack`, `keyUse` and `keyPickItem` clicks into `startAttack`, `startUseItem` and `pickBlockOrEntity`, then `continueAttack` for the held attack key and `startUseItem` for the held use key. - NeoForge posts the event with `(button, keyMapping, hand)`: button 0 (attack) in `startAttack` after the checks that stop an attack (miss time, busy hands, spectator, `cannotAttackWithItem`) and in `continueAttack` just before `continueDestroyBlock`; button 1 (use) once per hand in `startUseItem`, before that hand's target and item; button 2 (pick) in `pickBlockOrEntity` once there is a target. A cancel skips the action; `setSwingHand(true)` (the default) swings the hand anyway. Horizon's client (the window of a single player on the server thread, a LAN guest or a server's player, `remote` set) runs this in `remote_start_attack`, `remote_continue_attack`, `remote_use` / `remote_use_hands` and the pick in `RemoteInputWorld`. Proposed hook, in the shape of the other client input hooks: - `native_interaction_key(button, key_mapping, hand, swing_hand, canceled)`: `button` 0 attack, 1 use, 2 pick; `key_mapping` the vanilla name (`key.attack`, `key.use`, `key.pickItem`); `hand` the hand acting. A mod sets `canceled` to skip the action and may clear `swing_hand` to skip the swing a cancel otherwise still makes. Client side only. The deprecated in-frame path is not touched. API from a fragment.
Author
Owner

@levzzz5154 commented on GitHub (Nov 1, 2026):

/claim

<!-- gh-comment-id:6561848468 --> @levzzz5154 commented on GitHub (Nov 1, 2026): /claim
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2019
No description provided.