[PR #6289] [MERGED] Native mods: the attack, use and pick keys, InputEvent.InteractionKeyMappingTriggered #6770

Closed
opened 2026-11-03 06:26:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6289
Author: @levzzz5154
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @levzzz5154

Base: main ← Head: mods/native-interaction-key


📝 Commits (1)

  • 3cad899 Native mods: interaction key presses (InputEvent.InteractionKeyMappingTriggered)

📊 Changes

3 files changed (+103 additions, -10 deletions)

View changed files

📝 crates/horizon-client/src/game/native_hooks.rs (+38 -0)
📝 crates/horizon-client/src/game/remote.rs (+52 -10)
➕ tools/native-hook-fragments/interaction_key.json (+13 -0)

📄 Description

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

What and why

Fixes #6213; part of #4953 ("Interaction-key events"). A native mod can already read raw keys, mouse buttons and scrolling, but those come before the game decides what a press means. native_interaction_key(button, key_mapping, hand, swing_hand, canceled) is NeoForge's InputEvent.InteractionKeyMappingTriggered: it fires when the attack key (button 0, key.attack), the use key (1, key.use) or pick block (2, key.pickItem) is about to act on the crosshair. A mod sets canceled to skip the action, and may clear swing_hand (true on entry) to skip the swing a cancel otherwise still makes.

Where it fires (the window's Game with remote set: single player on the server thread, a LAN guest, a server's player; all in game/remote.rs):

  • Attack: remote_start_attack, after the checks that stop an attack (miss time, spectator, a spear that cannot attack yet), and remote_continue_attack each tick a held key would keep digging a non-air block.
  • Use: remote_use for the main hand (after the hands-busy check, before a mod's claimed item starts and before the target), and remote_use_hands for the off hand. A cancelled use returns from the whole click, so the other hand gets no turn.
  • Pick: RemoteInputWorld::pick, only with an entity or block aimed at.

The swing of a cancel uses the default animation (the spear's own attack animation for a spear). The deprecated in-frame path is not touched. The hook is a client hook; no new helper beyond native_interaction, which calls it and returns whether the hand should swing.

Kind

  • feature: something new for players (a mod can stop or replace what the interaction keys do)

Vanilla reference

Minecraft.handleKeybinds, startAttack, continueAttack, startUseItem and pickBlockOrEntity in the pinned 26.3 sources (.local/minecraft/26.3/sources/client/net/minecraft/client/Minecraft.java). NeoForge's public contract (InputEvent.InteractionKeyMappingTriggered: button, key mapping, hand, setSwingHand) for names and semantics. Horizon's difference: the off hand's turn is a separate event inside remote_use_hands, since Horizon runs the main hand's target and item first.

Other projects' code

None; names and contracts only.

Proof in the real game

Offscreen client, single player on the server thread, a throwaway probe in the hook body (removed before commit, git diff shows no TESTHOOK) that logged the call and cancelled the buttons in IK_CANCEL; horizon-ctl mouse left|right|middle click:

  • No cancel: TESTHOOK interaction_key 0 key.attack Main swing=true and the aimed block broke; 1 key.use Main and a block was placed against the face; 2 key.pickItem Main and the pick went through.

  • Cancel 0,1,2 with the swing kept: block stayed, nothing placed, pick did nothing (hand stayed on the held item), and one swing for each cancelled attack and use.

  • Cancel 0,1,2 with swing_hand cleared: same, swings 0 in state.

  • Survival, attack key held on a block, cancelled: the hook fired every tick (61 calls in 3 s), mining stayed null and the block kept; not cancelled: mining progressed.

  • Empty main hand, stone in the off hand, aimed at the sky: 1 key.use Main then 1 key.use Off; cancelling button 1 stops after the main event (the off hand never fires).

Not run: a cancel of only the off hand's turn, a dedicated server (client hook only; the hook runs in the window), a real native mod bundle.

Self-check

pr_ready (tools/pr_ready.py --quick --base hr/main, against hr/main at 1bd24e404)

Check Result
Scope ✅ 3 files, +103 −10
Public tree ✅
Python tests ✅ 586 passed
rustfmt ✅
clippy ✅
tests: horizon-client ✅ 1804 passed
doc tests ✅
Parity ➖ not run (--quick)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/6289 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `mods/native-interaction-key` --- ### 📝 Commits (1) - [`3cad899`](https://github.com/horizon-rust/horizon/commit/3cad89933a83e79acdbc55027b428c97e19c634f) Native mods: interaction key presses (InputEvent.InteractionKeyMappingTriggered) ### 📊 Changes **3 files changed** (+103 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/native_hooks.rs` (+38 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+52 -10) ➕ `tools/native-hook-fragments/interaction_key.json` (+13 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally. ## What and why Fixes #6213; part of #4953 ("Interaction-key events"). A native mod can already read raw keys, mouse buttons and scrolling, but those come before the game decides what a press means. `native_interaction_key(button, key_mapping, hand, swing_hand, canceled)` is NeoForge's `InputEvent.InteractionKeyMappingTriggered`: it fires when the attack key (`button` 0, `key.attack`), the use key (1, `key.use`) or pick block (2, `key.pickItem`) is about to act on the crosshair. A mod sets `canceled` to skip the action, and may clear `swing_hand` (true on entry) to skip the swing a cancel otherwise still makes. Where it fires (the window's `Game` with `remote` set: single player on the server thread, a LAN guest, a server's player; all in `game/remote.rs`): - Attack: `remote_start_attack`, after the checks that stop an attack (miss time, spectator, a spear that cannot attack yet), and `remote_continue_attack` each tick a held key would keep digging a non-air block. - Use: `remote_use` for the main hand (after the hands-busy check, before a mod's claimed item starts and before the target), and `remote_use_hands` for the off hand. A cancelled use returns from the whole click, so the other hand gets no turn. - Pick: `RemoteInputWorld::pick`, only with an entity or block aimed at. The swing of a cancel uses the default animation (the spear's own attack animation for a spear). The deprecated in-frame path is not touched. The hook is a client hook; no new helper beyond `native_interaction`, which calls it and returns whether the hand should swing. ## Kind - [x] feature: something new for players (a mod can stop or replace what the interaction keys do) ## Vanilla reference `Minecraft.handleKeybinds`, `startAttack`, `continueAttack`, `startUseItem` and `pickBlockOrEntity` in the pinned 26.3 sources (`.local/minecraft/26.3/sources/client/net/minecraft/client/Minecraft.java`). NeoForge's public contract (`InputEvent.InteractionKeyMappingTriggered`: button, key mapping, hand, `setSwingHand`) for names and semantics. Horizon's difference: the off hand's turn is a separate event inside `remote_use_hands`, since Horizon runs the main hand's target and item first. ## Other projects' code None; names and contracts only. ## Proof in the real game Offscreen client, single player on the server thread, a throwaway probe in the hook body (removed before commit, `git diff` shows no TESTHOOK) that logged the call and cancelled the buttons in `IK_CANCEL`; `horizon-ctl mouse left|right|middle click`: - No cancel: `TESTHOOK interaction_key 0 key.attack Main swing=true` and the aimed block broke; `1 key.use Main` and a block was placed against the face; `2 key.pickItem Main` and the pick went through. - Cancel 0,1,2 with the swing kept: block stayed, nothing placed, pick did nothing (hand stayed on the held item), and one swing for each cancelled attack and use. - Cancel 0,1,2 with `swing_hand` cleared: same, `swings` 0 in `state`. - Survival, attack key held on a block, cancelled: the hook fired every tick (61 calls in 3 s), `mining` stayed null and the block kept; not cancelled: `mining` progressed. - Empty main hand, stone in the off hand, aimed at the sky: `1 key.use Main` then `1 key.use Off`; cancelling button 1 stops after the main event (the off hand never fires). Not run: a cancel of only the off hand's turn, a dedicated server (client hook only; the hook runs in the window), a real native mod bundle. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base hr/main`, against hr/main at 1bd24e404) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +103 −10 | | Public tree | ✅ | | Python tests | ✅ 586 passed | | rustfmt | ✅ | | clippy | ✅ | | tests: horizon-client | ✅ 1804 passed | | doc tests | ✅ | | Parity | ➖ not run (--quick) | 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:26:21 +07:00
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#6770
No description provided.