[PR #4648] [MERGED] Native mods: a hook point for right-clicking an entity (API 20) #5754

Closed
opened 2026-11-03 05:14:46 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4648
Author: @ludovicthenot
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @levzzz5154

Base: main ← Head: native-interact-entity-hook


📝 Commits (3)

  • 1698ff4 Native mods: a hook point for right-clicking an entity (API 20)
  • d27ec41 Merge hr/main; renumber right-click-entity hook to API 28
  • 2959076 Merge hr/main; renumber right-click-entity hook to API 29

📊 Changes

4 files changed (+42 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+14 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+19 -1)
📝 docs/native-mods.md (+4 -0)
📝 native-hooks.json (+5 -0)

📄 Description

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

What and why

Fixes #4647. Part of #3911 (Mods), gap I of #1854, next to #4302 (using an item) in the priority list of #4402: a native mod can now react when a player right-clicks an entity, which items used on mobs (a wand, a capture tool, a mod's own lead or saddle), mobs with a mod's right-click action and entities that open a mod's screen need. Named after the vanilla call it sits in, as agreed on #4402.

  • native_interact_entity(&mut self, entity: i32, kind: &str, stack: Option<&ItemStack>, claimed: &mut bool): the entity's id (Entity.getId), its type (minecraft:cow, minecraft:item_frame...), the stack in self.hand (none in an empty hand), and claimed. A mod that sets it takes the click: the hand swings and neither the entity's interact nor the item's interactLivingEntity runs.
  • Called at the top of interact_entity (game.rs), where Player.interactOn starts, on the entity the click targets (pick_entity_hit; its type from level_entity and target_type, as the commands name it). Every player goes through it on the server (the single player server thread, LAN guests through Interact, dedicated servers), so it is authoritative; the helpers (native_player...) read the acting player. It is asked once per hand, as Minecraft.startUseItem tries the main hand, then the off hand.
  • Another player as the target isn't heard yet (pick_entity_hit gives players no id).
  • Not claimed, the click goes on exactly as before: nothing changes without a native mod.
  • NATIVE_HOOKS_API 19 → 20, its native-hooks.json entry (interact_entity, version 1), and an "API 20" paragraph in docs/native-mods.md. The number is the next free one on main and moves with whatever merges first.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Horizon-only (a hook point; it does nothing in Horizon). It sits where ServerGamePacketListenerImpl.handleInteract reaches Player.interactOn, before Entity.interact and ItemStack.interactLivingEntity. Without a native mod entity interactions are unchanged; CI's parity job picks the harnesses that cover game.rs.

Tested in the game

A throwaway local change (not in this pull request) logged the hook and claimed when an environment variable was set. Fresh survival worlds on the server thread, through horizon-ctl (--offscreen): a cow (/summon minecraft:cow ~ ~ ~ {NoAI:1b}) next to the player, /give @s minecraft:wheat 4, then interact-entity on the cow:

Run Hook called Wheat after
no claim interact_entity 363 minecraft:cow with Some("minecraft:wheat") hand Main 3 (the cow ate one)
claim the same, on the new cow 4 (nothing happened)

Self-check

On this commit: cargo fmt --check ✅, cargo clippy -p horizon-client --bin horizon-client ✅ (no warnings), native_hooks::tests ✅ 6 passed (the catalog test checks the new entry). tools/pr_ready.py was not run.

Label: feature (players get something new).


🔄 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/4648 **Author:** [@ludovicthenot](https://github.com/ludovicthenot) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `native-interact-entity-hook` --- ### 📝 Commits (3) - [`1698ff4`](https://github.com/horizon-rust/horizon/commit/1698ff41f81c2fe7657c76eb8d840c937c0a0113) Native mods: a hook point for right-clicking an entity (API 20) - [`d27ec41`](https://github.com/horizon-rust/horizon/commit/d27ec4143419abc68858e2e22d1a53aa17123617) Merge hr/main; renumber right-click-entity hook to API 28 - [`2959076`](https://github.com/horizon-rust/horizon/commit/2959076c754b674379002b029defddbd5da4a6a3) Merge hr/main; renumber right-click-entity hook to API 29 ### 📊 Changes **4 files changed** (+42 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+14 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+19 -1) 📝 `docs/native-mods.md` (+4 -0) 📝 `native-hooks.json` (+5 -0) </details> ### 📄 Description > 🤖 Opened by ludovicthenot's AI agent (Claude Code, Claude Opus 5.5), not by ludovicthenot personally. ## What and why Fixes #4647. Part of #3911 (Mods), gap **I** of #1854, next to #4302 (using an item) in the priority list of #4402: a native mod can now react when a player right-clicks an entity, which items used on mobs (a wand, a capture tool, a mod's own lead or saddle), mobs with a mod's right-click action and entities that open a mod's screen need. Named after the vanilla call it sits in, as agreed on #4402. - **`native_interact_entity(&mut self, entity: i32, kind: &str, stack: Option<&ItemStack>, claimed: &mut bool)`**: the entity's id (`Entity.getId`), its type (`minecraft:cow`, `minecraft:item_frame`...), the stack in `self.hand` (none in an empty hand), and `claimed`. A mod that sets it takes the click: the hand swings and neither the entity's `interact` nor the item's `interactLivingEntity` runs. - Called at the top of `interact_entity` (game.rs), where `Player.interactOn` starts, on the entity the click targets (`pick_entity_hit`; its type from `level_entity` and `target_type`, as the commands name it). Every player goes through it on the server (the single player server thread, LAN guests through `Interact`, dedicated servers), so it is authoritative; the helpers (`native_player`...) read the acting player. It is asked once per hand, as `Minecraft.startUseItem` tries the main hand, then the off hand. - Another player as the target isn't heard yet (`pick_entity_hit` gives players no id). - Not claimed, the click goes on exactly as before: nothing changes without a native mod. - `NATIVE_HOOKS_API` 19 → 20, its `native-hooks.json` entry (`interact_entity`, version 1), and an "API 20" paragraph in `docs/native-mods.md`. The number is the next free one on main and moves with whatever merges first. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [x] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Horizon-only (a hook point; it does nothing in Horizon). It sits where `ServerGamePacketListenerImpl.handleInteract` reaches `Player.interactOn`, before `Entity.interact` and `ItemStack.interactLivingEntity`. Without a native mod entity interactions are unchanged; CI's parity job picks the harnesses that cover `game.rs`. ## Tested in the game A throwaway local change (not in this pull request) logged the hook and claimed when an environment variable was set. Fresh survival worlds on the server thread, through `horizon-ctl` (`--offscreen`): a cow (`/summon minecraft:cow ~ ~ ~ {NoAI:1b}`) next to the player, `/give @s minecraft:wheat 4`, then `interact-entity` on the cow: | Run | Hook called | Wheat after | | --- | --- | --- | | no claim | `interact_entity 363 minecraft:cow with Some("minecraft:wheat") hand Main` | 3 (the cow ate one) | | claim | the same, on the new cow | 4 (nothing happened) | ## Self-check On this commit: `cargo fmt --check` ✅, `cargo clippy -p horizon-client --bin horizon-client` ✅ (no warnings), `native_hooks::tests` ✅ 6 passed (the catalog test checks the new entry). `tools/pr_ready.py` was not run. Label: `feature` (players get something new). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:14:46 +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#5754
No description provided.