[PR #7395] [MERGED] Native hooks: ArrowNockEvent and LivingGetProjectileEvent #7572

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7395
Author: @arismoko
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: v2/ses_01M6E91JFQZ707DB55V2730YTX-w1-bow


📝 Commits (10+)

  • 86db18c Add native_arrow_nock hook (ArrowNockEvent)
  • ed02ec2 Add native_living_get_projectile hook (LivingGetProjectileEvent)
  • a35e9b5 Fire living_get_projectile for creative, quick releases and crossbow mobs
  • c848175 Apply LivingGetProjectileEvent to mob crossbows, use the bow's hand, and the client's own profile
  • e9a18f8 Let every mod read and change getProjectile's ammo, start mob calls from the held projectile, fire mob crossbow rockets
  • 6f8cecd Name piglins in the getProjectile docs, skip the crossbow end sound when a mod empties the ammunition, reuse profile helpers
  • 9245872 Merge upstream main into the bow hooks
  • 5a14911 Merge upstream main into w1-bow
  • 97e4713 Bow: no projectile lookup work without native mods
  • 35c5475 Merge upstream main into w1-bow

📊 Changes

12 files changed (+426 additions, -38 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+15 -9)
📝 crates/horizon-client/src/game/creatures.rs (+46 -10)
📝 crates/horizon-client/src/game/crossbow.rs (+125 -7)
📝 crates/horizon-client/src/game/native_hooks.rs (+53 -1)
📝 crates/horizon-client/src/game/remote.rs (+2 -2)
📝 crates/horizon-client/src/mobs.rs (+21 -0)
📝 crates/horizon-client/src/mobs/illager.rs (+23 -7)
📝 crates/horizon-client/src/mobs/undead.rs (+14 -1)
📝 crates/horizon-client/src/mod_api/generated.rs (+92 -1)
📝 docs/native-mods.md (+2 -0)
➕ tools/native-hook-fragments/arrow_nock.json (+17 -0)
➕ tools/native-hook-fragments/living_get_projectile.json (+16 -0)

📄 Description

🤖 Opened by Aria's agent swarm, Dyna, not by Aria.

Native hooks: ArrowNockEvent and LivingGetProjectileEvent (arrow_nock, living_get_projectile).

Part of #4953.

Hook NeoForge 26.3 counterpart Side Contract Fires where vanilla calls
arrow_nock ArrowNockEvent (cancellable) both cancel: the bow use fails and the bow isn't drawn BowItem.use, after getProjectile and before the no-ammunition FAIL
living_get_projectile LivingGetProjectileEvent (not cancellable, the projectile stack is settable) both collect: every mod gets the stack in turn and may change it or empty it LivingEntity.getProjectile for a player (BowItem.use, BowItem.releaseUsing, CrossbowItem.use, the crossbow draw, and the client's prediction of a use start) and Monster.getProjectile for a mob (AbstractSkeleton.performRangedAttack, and the crossbow load of a pillager or piglin)

What changed and why

  • One ammunition lookup. crossbow.rs gets get_projectile(weapon) -> Option<Ammo>, which is Player.getProjectile as the event leaves it. Ammo is a named struct: the stack, plus the inventory slot while the stack is still the one found there. A creative player with no arrows gets hasInfiniteMaterials' arrow. A stack a mod replaced is not taken from the inventory.
    • The bow's use and release, the crossbow's use and draw, and the remote client's use prediction all call it now, instead of each reading projectile_slot and making its own default arrow.
    • projectile_slot stays: #7005's player_ready_arrow uses it.
  • arrow_nock. BowItem.use asks for the projectile, fires the nock with has_ammo (projectile found, or creative), and starts using the bow only if the nock wasn't cancelled.
  • #7030's arrow_loose now takes has_ammo from the same lookup. Its doc no longer says the nock is missing.
  • Mobs.
    • A skeleton's or illusioner's shot is now a MobEvent::BowShot, so the game can ask for the ammunition before the arrow flies. A replaced arrow carries its item and effect, as in ProjectileUtil.getMobArrow: spectral gives Glowing, and tipped arrows give their potion.
    • A pillager's or piglin's finished charge is now a MobEvent::CrossbowLoad. The crossbow is charged with what getProjectile returned. An emptied stack leaves it uncharged, and the loading_end sound doesn't play, as in tryLoadProjectiles.
    • MobEvent::CrossbowShot fires the charged projectile, so a firework rocket flies as a rocket.
  • Hot path. With no native mod loaded, get_projectile and the mob bow shot return before they build the event.

Overlap: question for review

#7005 (merged) added player_ready_arrow, Bukkit's PlayerReadyArrowEvent. It is listen-only and reports the arrow found in the inventory on a guest's release. living_get_projectile is NeoForge's contract: it can change the ammunition, and it covers mobs. So we kept both. player_ready_arrow still reports the inventory arrow even when a mod replaced the projectile. Should it report the replaced stack instead?

Tests

Hook How it was checked
arrow_nock In game at 9245872736: it fires once per use in single player and on a dedicated server, and a cancel stops the draw (single player)
living_get_projectile In game at 9245872736, single player and dedicated server: a replaced projectile flies as a spectral arrow, and the inventory arrow isn't spent
Mob shots and crossbow paths Clippy, plus a read of AbstractSkeleton.performRangedAttack, Monster.getProjectile and CrossbowItem.tryLoadProjectiles in 26.3. Not run in game: a player's shot exercises the same getProjectile replacement, and the mob paths change only where the ammunition comes from

The xtask mod_api tests cover the generated dispatch: cancel and the in-order mutation.

Tested in game

The test mod was a throwaway trait mod from the sample's trait-api-example, built through the launcher with --trust-native-code at 9245872736. Each hook logged one line per call, and env vars switched what it did. The player was in survival, with a bow and one arrow.

  • No env: the arrow flew, the arrow count dropped to 0, and the bow lost 1 durability. Both hooks logged: W1 living_get_projectile … kind=minecraft:player weapon=minecraft:bow projectile=Some("minecraft:arrow"), then W1 arrow_nock … has_ammo=true hand=Main.
  • arrow_nock cancelled: holding use and releasing didn't draw the bow. The arrow stayed at 1 and the bow wasn't damaged.
  • Projectile replaced with a spectral arrow: the shot hit a cow, and the cow got Glowing (active_effects: [{id: "minecraft:glowing", …}]). The normal arrow stayed at 1.
  • Dedicated server: a launcher-exported server with a client joined, the projectile replaced with a spectral arrow. The shot left the normal arrow at 1, and the arrow picked up from the wall was a spectral arrow. One shot logged exactly one nock and two lookups, which is vanilla's order: getProjectile in use, the nock, then getProjectile in releaseUsing. No replay doubled it.

The head adds merges of main (up to f4a9e85d7b), the no-mod early returns, and fa876269f3 (a crossbow mob draws its attack delay before the loading sound's pitch, keeping the old random order). With a mod loaded, the hook path is the same as at 9245872736.

The recommended end-to-end route for native mods is horizon-machine-sample. It was used here: its trait-mod bundle (trait-api-example), built through the launcher at 9245872736.

pr_ready

At the head, d9b0388195:

pr_ready (tools/pr_ready.py --quick --base f4a9e85d7b111c7b6820dfc6949498256dc38524 on dd4facee92d8, against f4a9e85d7b at f4a9e85d7, 14 min 48 s)

Check Result
Scope ✅ 12 files, +426 −38
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 614 passed (1 min 5 s)
rustfmt ✅ (13 s)
clippy ✅ (2 min 20 s)
tests: horizon-client, horizon-client-lib ✅ 2175 passed (10 min 38 s)
doc tests ✅ 0 passed (6 s)
content root tests ➖ content root untouched
mod API up to date ✅ (26 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 Generated with Dyna.


🔄 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/7395 **Author:** [@arismoko](https://github.com/arismoko) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `v2/ses_01M6E91JFQZ707DB55V2730YTX-w1-bow` --- ### 📝 Commits (10+) - [`86db18c`](https://github.com/horizon-rust/horizon/commit/86db18cd6eb423dd63c94f6f4de2cabb448c3c4f) Add native_arrow_nock hook (ArrowNockEvent) - [`ed02ec2`](https://github.com/horizon-rust/horizon/commit/ed02ec25c24bf40c83fed54f584754df1ee8135f) Add native_living_get_projectile hook (LivingGetProjectileEvent) - [`a35e9b5`](https://github.com/horizon-rust/horizon/commit/a35e9b5e3f8f4a0c7d4acfe7adf437183d4afdc5) Fire living_get_projectile for creative, quick releases and crossbow mobs - [`c848175`](https://github.com/horizon-rust/horizon/commit/c848175bed2abe59418cc4c3f4525a2bf078a70f) Apply LivingGetProjectileEvent to mob crossbows, use the bow's hand, and the client's own profile - [`e9a18f8`](https://github.com/horizon-rust/horizon/commit/e9a18f8fbe87511e8e9f8f3366844be492136dfe) Let every mod read and change getProjectile's ammo, start mob calls from the held projectile, fire mob crossbow rockets - [`6f8cecd`](https://github.com/horizon-rust/horizon/commit/6f8cecd0dbaef809b77a05e37c2c466a5ca5225b) Name piglins in the getProjectile docs, skip the crossbow end sound when a mod empties the ammunition, reuse profile helpers - [`9245872`](https://github.com/horizon-rust/horizon/commit/9245872736f4275262d7639f64ef7b0f4a276136) Merge upstream main into the bow hooks - [`5a14911`](https://github.com/horizon-rust/horizon/commit/5a1491137ea4a650d209861caad58f98a69eb0e8) Merge upstream main into w1-bow - [`97e4713`](https://github.com/horizon-rust/horizon/commit/97e4713f375090ea0564c709426102eacb40c993) Bow: no projectile lookup work without native mods - [`35c5475`](https://github.com/horizon-rust/horizon/commit/35c5475d142033b832bb3322f9ed9ff79c34fe51) Merge upstream main into w1-bow ### 📊 Changes **12 files changed** (+426 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+15 -9) 📝 `crates/horizon-client/src/game/creatures.rs` (+46 -10) 📝 `crates/horizon-client/src/game/crossbow.rs` (+125 -7) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+53 -1) 📝 `crates/horizon-client/src/game/remote.rs` (+2 -2) 📝 `crates/horizon-client/src/mobs.rs` (+21 -0) 📝 `crates/horizon-client/src/mobs/illager.rs` (+23 -7) 📝 `crates/horizon-client/src/mobs/undead.rs` (+14 -1) 📝 `crates/horizon-client/src/mod_api/generated.rs` (+92 -1) 📝 `docs/native-mods.md` (+2 -0) ➕ `tools/native-hook-fragments/arrow_nock.json` (+17 -0) ➕ `tools/native-hook-fragments/living_get_projectile.json` (+16 -0) </details> ### 📄 Description > 🤖 Opened by Aria's agent swarm, Dyna, not by Aria. Native hooks: `ArrowNockEvent` and `LivingGetProjectileEvent` (`arrow_nock`, `living_get_projectile`). Part of #4953. | Hook | NeoForge 26.3 counterpart | Side | Contract | Fires where vanilla calls | | --- | --- | --- | --- | --- | | `arrow_nock` | `ArrowNockEvent` (cancellable) | both | `cancel`: the bow use fails and the bow isn't drawn | `BowItem.use`, after `getProjectile` and before the no-ammunition `FAIL` | | `living_get_projectile` | `LivingGetProjectileEvent` (not cancellable, the projectile stack is settable) | both | `collect`: every mod gets the stack in turn and may change it or empty it | `LivingEntity.getProjectile` for a player (`BowItem.use`, `BowItem.releaseUsing`, `CrossbowItem.use`, the crossbow draw, and the client's prediction of a use start) and `Monster.getProjectile` for a mob (`AbstractSkeleton.performRangedAttack`, and the crossbow load of a pillager or piglin) | ## What changed and why - **One ammunition lookup.** `crossbow.rs` gets `get_projectile(weapon) -> Option<Ammo>`, which is `Player.getProjectile` as the event leaves it. `Ammo` is a named struct: the stack, plus the inventory slot while the stack is still the one found there. A creative player with no arrows gets `hasInfiniteMaterials`' arrow. A stack a mod replaced is not taken from the inventory. - The bow's use and release, the crossbow's use and draw, and the remote client's use prediction all call it now, instead of each reading `projectile_slot` and making its own default arrow. - `projectile_slot` stays: #7005's `player_ready_arrow` uses it. - **`arrow_nock`.** `BowItem.use` asks for the projectile, fires the nock with `has_ammo` (projectile found, or creative), and starts using the bow only if the nock wasn't cancelled. - **#7030's `arrow_loose`** now takes `has_ammo` from the same lookup. Its doc no longer says the nock is missing. - **Mobs.** - A skeleton's or illusioner's shot is now a `MobEvent::BowShot`, so the game can ask for the ammunition before the arrow flies. A replaced arrow carries its item and effect, as in `ProjectileUtil.getMobArrow`: spectral gives Glowing, and tipped arrows give their potion. - A pillager's or piglin's finished charge is now a `MobEvent::CrossbowLoad`. The crossbow is charged with what `getProjectile` returned. An emptied stack leaves it uncharged, and the `loading_end` sound doesn't play, as in `tryLoadProjectiles`. - `MobEvent::CrossbowShot` fires the charged projectile, so a firework rocket flies as a rocket. - **Hot path.** With no native mod loaded, `get_projectile` and the mob bow shot return before they build the event. ## Overlap: question for review #7005 (merged) added `player_ready_arrow`, Bukkit's `PlayerReadyArrowEvent`. It is listen-only and reports the arrow found in the inventory on a guest's release. `living_get_projectile` is NeoForge's contract: it can change the ammunition, and it covers mobs. So we kept both. `player_ready_arrow` still reports the inventory arrow even when a mod replaced the projectile. Should it report the replaced stack instead? ## Tests | Hook | How it was checked | | --- | --- | | `arrow_nock` | In game at 9245872736: it fires once per use in single player and on a dedicated server, and a cancel stops the draw (single player) | | `living_get_projectile` | In game at 9245872736, single player and dedicated server: a replaced projectile flies as a spectral arrow, and the inventory arrow isn't spent | | Mob shots and crossbow paths | Clippy, plus a read of `AbstractSkeleton.performRangedAttack`, `Monster.getProjectile` and `CrossbowItem.tryLoadProjectiles` in 26.3. Not run in game: a player's shot exercises the same `getProjectile` replacement, and the mob paths change only where the ammunition comes from | The xtask `mod_api` tests cover the generated dispatch: cancel and the in-order mutation. ## Tested in game The test mod was a throwaway trait mod from the sample's `trait-api-example`, built through the launcher with `--trust-native-code` at 9245872736. Each hook logged one line per call, and env vars switched what it did. The player was in survival, with a bow and one arrow. - **No env:** the arrow flew, the arrow count dropped to 0, and the bow lost 1 durability. Both hooks logged: `W1 living_get_projectile … kind=minecraft:player weapon=minecraft:bow projectile=Some("minecraft:arrow")`, then `W1 arrow_nock … has_ammo=true hand=Main`. - **`arrow_nock` cancelled:** holding use and releasing didn't draw the bow. The arrow stayed at 1 and the bow wasn't damaged. - **Projectile replaced with a spectral arrow:** the shot hit a cow, and the cow got Glowing (`active_effects: [{id: "minecraft:glowing", …}]`). The normal arrow stayed at 1. - **Dedicated server:** a launcher-exported server with a client joined, the projectile replaced with a spectral arrow. The shot left the normal arrow at 1, and the arrow picked up from the wall was a spectral arrow. One shot logged exactly one nock and two lookups, which is vanilla's order: `getProjectile` in `use`, the nock, then `getProjectile` in `releaseUsing`. No replay doubled it. The head adds merges of main (up to f4a9e85d7b), the no-mod early returns, and fa876269f3 (a crossbow mob draws its attack delay before the loading sound's pitch, keeping the old random order). With a mod loaded, the hook path is the same as at 9245872736. The recommended end-to-end route for native mods is [horizon-machine-sample](https://github.com/arismoko/horizon-machine-sample). It was used here: its trait-mod bundle (`trait-api-example`), built through the launcher at 9245872736. ## pr_ready At the head, d9b0388195: **pr_ready** (`tools/pr_ready.py --quick --base f4a9e85d7b111c7b6820dfc6949498256dc38524` on dd4facee92d8, against f4a9e85d7b111c7b6820dfc6949498256dc38524 at f4a9e85d7, 14 min 48 s) | Check | Result | | --- | --- | | Scope | ✅ 12 files, +426 −38 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 614 passed (1 min 5 s) | | rustfmt | ✅ (13 s) | | clippy | ✅ (2 min 20 s) | | tests: horizon-client, horizon-client-lib | ✅ 2175 passed (10 min 38 s) | | doc tests | ✅ 0 passed (6 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (26 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 Generated with Dyna. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 07:20:07 +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#7572
No description provided.