[PR #7172] [MERGED] Mods hear every entity kind join the level #7391

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

📋 Pull Request Information

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

Base: main ← Head: refactor/entity-walk-mod-hooks


📝 Commits (4)

  • 1303351 Native mods: entity_join_level tells every kind of the entity walk, once, and removes a cancelled one
  • 2e78552 Merge remote-tracking branch 'origin/main' into refactor/entity-walk-mod-hooks
  • 96b3597 Merge origin/main
  • d927a09 Merge main into #7172

📊 Changes

8 files changed (+171 additions, -70 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+4 -6)
📝 crates/horizon-client/src/game/commands.rs (+1 -7)
📝 crates/horizon-client/src/game/entity.rs (+45 -0)
📝 crates/horizon-client/src/game/native_entities.rs (+81 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+15 -33)
📝 crates/horizon-client/src/game/persist.rs (+12 -19)
📝 crates/horizon-client/src/mod_api/generated.rs (+9 -3)
📝 docs/native-mods.md (+4 -2)

📄 Description

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

What and why

Slice 11 of #6509, part of #6546: native_entity_join_level told mods about item entities and experience orbs only. It now tells every kind in the entity walk (items, orbs, mobs, boats, minecarts, armor stands, primed TNT, falling blocks, projectiles, rockets, tridents), once each, and a cancelled join takes the entity back out.

  • Entity::native_type gives each kind's type id (minecraft:oak_boat, minecraft:chest_minecart); discard_entity(handle) takes an entity out of its list.
  • native_joins_flush replaces native_entity_joins. It walks the lists with static dispatch, announces each entity whose id is above the last one announced (lowest id first, so creation order), and removes a cancelled one. The id mark is one u32. Nothing allocates except the kind name of an entity it announces.
  • Called where entities are added at once: item and orb spawns, /summon, mobs (native_mobs_joined, which is every mob spawn site), and each entity a chunk loads. Any other gameplay spawn (a lit TNT, a shot arrow, a placed boat, a dispensed minecart) is told when the next tick starts, before it ticks.
  • No new API number: the hook keeps its signature; docs and the generated file say which kinds it tells.
  • Primed TNT, falling blocks, projectiles, tridents and rockets get their id at that point if they had none yet.

Not told, and said so in the hook's docs: end crystals, the dragon, cushions, paintings, item frames and the entities Horizon keeps without simulating. A leave hook for the new kinds (native_entity_leave_level) is not in this slice: it still tells items, orbs and mobs.

Overlaps checked against open PRs that change native hooks: #7005, #7036, #7030, #7025, #7044, #6927, #6910, #6911, #6912 and #6992 all touch native_hooks.rs, mostly the file's header and new hook functions; this change edits the entity_join_level hook's docs and the old native_entity_joins function only, and adds no API number, so it should not clash. #7037 and #7054 touch entity.rs (this adds one trait method and one generated method). #6991 and #6965 touch persist.rs, #6965 around the entity load loop.

Part of #6546

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

ServerLevel.addFreshEntity / addWithUUID end in PersistentEntitySectionManager.addEntity, which posts NeoForge's EntityJoinLevelEvent once for any entity type, before the entity is added; a cancelled event means the entity is not added and /summon reports "duplicate UUIDs". Chunk loading adds entities through the same call with loadedFromDisk true. So vanilla tells every type the same way; before this PR Horizon did so for two.

What fires for each kind here, run with a native mod that logs entity_join_level (summoned, then three ticks): cow, item, primed TNT, orb, armor stand, oak boat, minecart, arrow, snowball, falling block, firework rocket, trident each log exactly one join with their type id and a distinct entity id.

joins logged before after
the twelve summoned kinds 2 (item, orb) 12
whole run (natural spawns, saved minecarts in the test world, the twelve) 2 134
ids announced twice none none

Cancel run (the mod cancels cow, item, TNT, oak boat, arrow and trident): before, /summon of the item failed and the other five succeeded and stayed; after, all six /summon calls fail with "duplicate UUIDs", and the uncancelled six (orb, armor stand, minecart, snowball, falling block, rocket) succeed. Each cancelled kind logged one join with cancel=true.

Where it differs from vanilla: a spawn that does not go through /summon, a drop, an orb, a mob or a chunk load is told at the start of the next tick, not at the moment it is added, so such an entity can run the rest of the tick it was made in before a cancel removes it. Order within one flush is by id (creation order), as vanilla.

Tick cost

Rule from #6509: no dyn, no allocation per walk. Static dispatch only; the walk is entity_handles() with one with_entity! match per entity, and the dispatch is skipped when no mod is loaded.

Measured, one round under flock ~/horizon/.scout/bench.lock, headless integrated server, about 165 entities, 240 ticks, release-like fast profile; timer around the flush at the start of each tick:

mean per tick
no mod loaded (the early return) 56 ns
a mod loaded (walk of 126 to 164 entities; the mean includes the ticks that announce entities and the test mod's file writes) 969 ns

For scale a tick is 50 ms. Before this PR the same line did nothing. The two rows come from separate runs on a loaded machine (load average about 8), so they show the order of magnitude, not a precise cost; no rerun. The timer was a temporary patch and is not in the commit.

Harnesses

Run locally, with DISPLAY=:0 HORIZON_E2E_HEADLESS=1: tools/parity.py server_entities save_roundtrip world_reopen remote_fireworks arrow boat_authority. All six pass (arrow 24 s, boat_authority 11 s, save_roundtrip 126 s, world_reopen 17 s, server_entities 108 s, remote_fireworks 38 s). CI runs the full --changed set.

The sample-mod runs above used the command harness (HORIZON_COMMAND_SCRIPT) with a throwaway mod installed at startup; that patch is not in the commit.

A refactor with no behaviour change; proved by script, no human played this change.

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick on Valhalla, against origin/main at 0ac35dac7, 11 min 2 s)

Check Result
Scope ✅ 8 files, +171 −70
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 612 passed (37 s)
rustfmt ✅ (9 s)
Rust ⚠️ 1.98.0 is older than CI's stable (1.99): clippy may flag lints CI doesn't, update with rustup update
clippy ✅ (1 min 56 s)
tests: horizon-client, horizon-client-lib ✅ 2103 passed (7 min 53 s)
doc tests ✅ 0 passed (3 s)
content root tests ➖ content root untouched
mod API up to date ✅ (20 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 227 affected, to run in CI (--quick): armor_stand_turtle_egg, arrow, arrow_wind_charge, block_particles, block_removal, boat_authority, boat_paddle_reset, breaking_model, command_exec, composter, crafter, cursor_death and 215 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 Generated with Claude Code

https://claude.ai/code/session_018zuDTsnyHkP28bzn3u7S3m


🔄 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/7172 **Author:** [@HrafnaValkyrja](https://github.com/HrafnaValkyrja) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `refactor/entity-walk-mod-hooks` --- ### 📝 Commits (4) - [`1303351`](https://github.com/horizon-rust/horizon/commit/1303351d3dc192ccedcd8588e847820e44b20fc2) Native mods: entity_join_level tells every kind of the entity walk, once, and removes a cancelled one - [`2e78552`](https://github.com/horizon-rust/horizon/commit/2e785524f96a516bcdbd2dfc1db384fca717d1c9) Merge remote-tracking branch 'origin/main' into refactor/entity-walk-mod-hooks - [`96b3597`](https://github.com/horizon-rust/horizon/commit/96b3597a6bc631ccbdc84bd2a94b1541df184614) Merge origin/main - [`d927a09`](https://github.com/horizon-rust/horizon/commit/d927a099e7d1d60a80f9dc192298b421ec85acd5) Merge main into #7172 ### 📊 Changes **8 files changed** (+171 additions, -70 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+4 -6) 📝 `crates/horizon-client/src/game/commands.rs` (+1 -7) 📝 `crates/horizon-client/src/game/entity.rs` (+45 -0) 📝 `crates/horizon-client/src/game/native_entities.rs` (+81 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+15 -33) 📝 `crates/horizon-client/src/game/persist.rs` (+12 -19) 📝 `crates/horizon-client/src/mod_api/generated.rs` (+9 -3) 📝 `docs/native-mods.md` (+4 -2) </details> ### 📄 Description > 🤖 Opened by Valkyrie's AI agent (Claude Code, Opus 5.5), not by Valkyrie herself. ## What and why Slice 11 of #6509, part of #6546: `native_entity_join_level` told mods about item entities and experience orbs only. It now tells every kind in the entity walk (items, orbs, mobs, boats, minecarts, armor stands, primed TNT, falling blocks, projectiles, rockets, tridents), once each, and a cancelled join takes the entity back out. - `Entity::native_type` gives each kind's type id (`minecraft:oak_boat`, `minecraft:chest_minecart`); `discard_entity(handle)` takes an entity out of its list. - `native_joins_flush` replaces `native_entity_joins`. It walks the lists with static dispatch, announces each entity whose id is above the last one announced (lowest id first, so creation order), and removes a cancelled one. The id mark is one `u32`. Nothing allocates except the kind name of an entity it announces. - Called where entities are added at once: item and orb spawns, `/summon`, mobs (`native_mobs_joined`, which is every mob spawn site), and each entity a chunk loads. Any other gameplay spawn (a lit TNT, a shot arrow, a placed boat, a dispensed minecart) is told when the next tick starts, before it ticks. - No new API number: the hook keeps its signature; docs and the generated file say which kinds it tells. - Primed TNT, falling blocks, projectiles, tridents and rockets get their id at that point if they had none yet. Not told, and said so in the hook's docs: end crystals, the dragon, cushions, paintings, item frames and the entities Horizon keeps without simulating. A leave hook for the new kinds (`native_entity_leave_level`) is not in this slice: it still tells items, orbs and mobs. Overlaps checked against open PRs that change native hooks: #7005, #7036, #7030, #7025, #7044, #6927, #6910, #6911, #6912 and #6992 all touch `native_hooks.rs`, mostly the file's header and new hook functions; this change edits the `entity_join_level` hook's docs and the old `native_entity_joins` function only, and adds no API number, so it should not clash. #7037 and #7054 touch `entity.rs` (this adds one trait method and one generated method). #6991 and #6965 touch `persist.rs`, #6965 around the entity load loop. Part of #6546 ## 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 - [x] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference `ServerLevel.addFreshEntity` / `addWithUUID` end in `PersistentEntitySectionManager.addEntity`, which posts NeoForge's `EntityJoinLevelEvent` once for any entity type, before the entity is added; a cancelled event means the entity is not added and `/summon` reports "duplicate UUIDs". Chunk loading adds entities through the same call with `loadedFromDisk` true. So vanilla tells every type the same way; before this PR Horizon did so for two. What fires for each kind here, run with a native mod that logs `entity_join_level` (summoned, then three ticks): cow, item, primed TNT, orb, armor stand, oak boat, minecart, arrow, snowball, falling block, firework rocket, trident each log exactly one join with their type id and a distinct entity id. | | joins logged before | after | |---|---|---| | the twelve summoned kinds | 2 (item, orb) | 12 | | whole run (natural spawns, saved minecarts in the test world, the twelve) | 2 | 134 | | ids announced twice | none | none | Cancel run (the mod cancels cow, item, TNT, oak boat, arrow and trident): before, `/summon` of the item failed and the other five succeeded and stayed; after, all six `/summon` calls fail with "duplicate UUIDs", and the uncancelled six (orb, armor stand, minecart, snowball, falling block, rocket) succeed. Each cancelled kind logged one join with `cancel=true`. Where it differs from vanilla: a spawn that does not go through `/summon`, a drop, an orb, a mob or a chunk load is told at the start of the next tick, not at the moment it is added, so such an entity can run the rest of the tick it was made in before a cancel removes it. Order within one flush is by id (creation order), as vanilla. ## Tick cost Rule from #6509: no `dyn`, no allocation per walk. Static dispatch only; the walk is `entity_handles()` with one `with_entity!` match per entity, and the dispatch is skipped when no mod is loaded. Measured, one round under `flock ~/horizon/.scout/bench.lock`, headless integrated server, about 165 entities, 240 ticks, release-like `fast` profile; timer around the flush at the start of each tick: | | mean per tick | |---|---| | no mod loaded (the early return) | 56 ns | | a mod loaded (walk of 126 to 164 entities; the mean includes the ticks that announce entities and the test mod's file writes) | 969 ns | For scale a tick is 50 ms. Before this PR the same line did nothing. The two rows come from separate runs on a loaded machine (load average about 8), so they show the order of magnitude, not a precise cost; no rerun. The timer was a temporary patch and is not in the commit. ## Harnesses Run locally, with `DISPLAY=:0 HORIZON_E2E_HEADLESS=1`: `tools/parity.py server_entities save_roundtrip world_reopen remote_fireworks arrow boat_authority`. All six pass (arrow 24 s, boat_authority 11 s, save_roundtrip 126 s, world_reopen 17 s, server_entities 108 s, remote_fireworks 38 s). CI runs the full `--changed` set. The sample-mod runs above used the command harness (`HORIZON_COMMAND_SCRIPT`) with a throwaway mod installed at startup; that patch is not in the commit. A refactor with no behaviour change; proved by script, no human played this change. ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on Valhalla, against origin/main at 0ac35dac7, 11 min 2 s) | Check | Result | | --- | --- | | Scope | ✅ 8 files, +171 −70 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 612 passed (37 s) | | rustfmt | ✅ (9 s) | | Rust | ⚠️ 1.98.0 is older than CI's stable (1.99): clippy may flag lints CI doesn't, update with `rustup update` | | clippy | ✅ (1 min 56 s) | | tests: horizon-client, horizon-client-lib | ✅ 2103 passed (7 min 53 s) | | doc tests | ✅ 0 passed (3 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (20 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 227 affected, to run in CI (--quick): armor_stand_turtle_egg, arrow, arrow_wind_charge, block_particles, block_removal, boat_authority, boat_paddle_reset, breaking_model, command_exec, composter, crafter, cursor_death and 215 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018zuDTsnyHkP28bzn3u7S3m --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:38:49 +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#7391
No description provided.