[PR #5171] [MERGED] Native mods: entities leaving a level, for item entities and orbs (API next) #6117

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

📋 Pull Request Information

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

Base: main ← Head: mods/native-entity-leave


📝 Commits (3)

  • 7b0c59c Native mods: entities leaving a level, for item entities and orbs
  • 16305ab Merge origin/main into mods/native-entity-leave; API number as a fragment, gateway fix
  • c63f053 Merge main; leave hooks for main's new item and orb removals

📊 Changes

18 files changed (+118 additions, -14 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+18 -0)
📝 crates/horizon-client/src/game/allays.rs (+1 -1)
📝 crates/horizon-client/src/game/commands.rs (+7 -1)
📝 crates/horizon-client/src/game/end.rs (+2 -0)
📝 crates/horizon-client/src/game/explosion.rs (+4 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+2 -2)
📝 crates/horizon-client/src/game/lightning.rs (+2 -0)
📝 crates/horizon-client/src/game/machines.rs (+1 -1)
📝 crates/horizon-client/src/game/mob_looting.rs (+1 -1)
📝 crates/horizon-client/src/game/native_hooks.rs (+59 -1)
📝 crates/horizon-client/src/game/nether_portal.rs (+1 -1)
📝 crates/horizon-client/src/game/pandas.rs (+1 -1)
📝 crates/horizon-client/src/game/persist.rs (+4 -0)
📝 crates/horizon-client/src/game/piglins.rs (+2 -2)
📝 crates/horizon-client/src/game/raids.rs (+1 -1)
📝 crates/horizon-client/src/game/sulfur_cubes.rs (+1 -1)
📝 crates/horizon-client/src/game/villagers.rs (+1 -1)
➕ tools/native-hook-fragments/entity_leave_level.json (+10 -0)

📄 Description

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

What and why

Step 2 of #5162 (entities joining and leaving a level); step 1, the join hook, is #5167. Part of #4953 and #3911. NATIVE_HOOKS_API 40 → 41 (API next: the number is set at merge).

native_entity_leave_level(dimension, entity, kind) is NeoForge's EntityLeaveLevelEvent (javadoc: "fired whenever an entity is removed from the level in LevelCallback.onTrackingEnd(Object)", not cancellable). In the catalog it has neoforge, side: server and cancellable: false. It covers item entities and experience orbs. It runs once the entity is out of the level's lists, at every place Horizon takes one out:

  • Single removals go through two new helpers next to spawn_item / add_orb: remove_dropped(i) and remove_orb(i).
    • A hopper or hopper minecart taking an item (suck_item_entities).
    • A guest picking up an item or an orb (lan_actions).
    • Allays, piglins, pandas, villagers, sulfur cubes and raiders taking items.
    • An item going through a nether portal or an End gateway.
    • /kill of an item.
  • Sweeps take the IDs before and report the missing ones after, in the same call:
    • The item tick (merges, burning, despawn, the local player's pickups).
    • The orb tick (merges, despawn, pickups).
    • An explosion and a lightning strike destroying items.
    • /kill of orbs.
    • Chunk unload in entity_chunks(.., remove: true). That also covers a level closing because nobody is in it (close_idle_levels) and the deprecated in-frame dimension change.

As in vanilla, nothing is told for the entities still loaded when a world closes or the server stops (PersistentEntitySectionManager.close only saves). On a client of a server nothing fires.

Kind

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

Vanilla reference

26.3's PersistentEntitySectionManager:

  • stopTracking calls callbacks.onTrackingEnd.
  • Removal reaches it through Callback.onRemove (any removal reason, while the section is accessible).
  • So does a section turning inaccessible (updateChunkStatus), which is how chunk unload reaches it.
  • close() is saveAll() plus closing storage, with no stopTracking.

With no mod installed the hook is empty. The only change is the ID bookkeeping, which is skipped on a client.

Other projects' code

none

Tested in the game

A throwaway probe in the hook logs every leave (removed before the commit). Fresh mktemp -d homes, HORIZON_NO_AUDIO=1, --profile fast. Each test entity's ID was read with horizon-ctl entities right after it was summoned on a stone platform at y=100, to tell it from the world's own drops.

Single player (server thread)

Test Leave
summon item … {Age:5960s} (stone) #158 leaves when it despawns
Two apples side by side #363 leaves when it merges into #365; #365 leaves later with its chunk
summon item (stick), then kill @e[type=item,…] #410 leaves
Iron ingot dropped onto a hopper leaves as the hopper takes it
Feather next to summon tnt … {fuse:0s} #431 leaves (blown up), along with the platform's cobblestone drops later
Gold ingot at the creative player's feet #505 leaves on pickup
Emerald into a nether portal built with /fill leaves the overworld
Brick, then the player teleports 5000 blocks away #441 leaves when its chunk unloads
Two orbs on one spot plus one more, then kill @e[type=experience_orb] 3 orb leaves (one merge, two kills)

Dedicated server (--dedicated --nogui) with a horizon-ctl client, Alex (survival)

Test Leave
execute at Alex run summon item … diamond and … experience_orb item #160 and orb #161 leave as Alex picks them up (the guest pickup path)
An emerald left on the ground, then stop nothing, as in vanilla
Alex's own client nothing fires

Not verified separately: a level closing empty after 300 ticks. It goes through the same entity_chunks code as the chunk unload above.

Parity, locally (tools/parity.py server_entities dispenser spawn_loot crafter composter): 5 passed. The other 36 harnesses that cover these files are CI's.

Self-check

pr_ready (tools/pr_ready.py --quick --base hr/main on cachyos-x8664, against hr/main at 01bbb4c65, 6 min 58 s)

Check Result
Scope ✅ 18 files, +122 −14
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 495 passed (1 min 0 s)
rustfmt ✅ (8 s)
clippy ✅ (1 min 22 s)
tests: horizon-client ✅ 1340 passed (4 min 19 s)
doc tests ✅ 0 passed (1 s)
Parity ➖ 39 affected, to run in CI (--quick); 5 of them passed locally

🤖 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/5171 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `mods/native-entity-leave` --- ### 📝 Commits (3) - [`7b0c59c`](https://github.com/horizon-rust/horizon/commit/7b0c59cc0a1c599ab64fd254329c12108171e91a) Native mods: entities leaving a level, for item entities and orbs - [`16305ab`](https://github.com/horizon-rust/horizon/commit/16305ab9c39e237751ccbdce0fff5fbf05551ad2) Merge origin/main into mods/native-entity-leave; API number as a fragment, gateway fix - [`c63f053`](https://github.com/horizon-rust/horizon/commit/c63f053e2856a775ee4047477ce447a9a626edfb) Merge main; leave hooks for main's new item and orb removals ### 📊 Changes **18 files changed** (+118 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+18 -0) 📝 `crates/horizon-client/src/game/allays.rs` (+1 -1) 📝 `crates/horizon-client/src/game/commands.rs` (+7 -1) 📝 `crates/horizon-client/src/game/end.rs` (+2 -0) 📝 `crates/horizon-client/src/game/explosion.rs` (+4 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+2 -2) 📝 `crates/horizon-client/src/game/lightning.rs` (+2 -0) 📝 `crates/horizon-client/src/game/machines.rs` (+1 -1) 📝 `crates/horizon-client/src/game/mob_looting.rs` (+1 -1) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+59 -1) 📝 `crates/horizon-client/src/game/nether_portal.rs` (+1 -1) 📝 `crates/horizon-client/src/game/pandas.rs` (+1 -1) 📝 `crates/horizon-client/src/game/persist.rs` (+4 -0) 📝 `crates/horizon-client/src/game/piglins.rs` (+2 -2) 📝 `crates/horizon-client/src/game/raids.rs` (+1 -1) 📝 `crates/horizon-client/src/game/sulfur_cubes.rs` (+1 -1) 📝 `crates/horizon-client/src/game/villagers.rs` (+1 -1) ➕ `tools/native-hook-fragments/entity_leave_level.json` (+10 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. ## What and why Step 2 of #5162 (entities joining and leaving a level); step 1, the join hook, is #5167. Part of #4953 and #3911. `NATIVE_HOOKS_API` 40 → 41 (**API next**: the number is set at merge). **`native_entity_leave_level(dimension, entity, kind)`** is NeoForge's `EntityLeaveLevelEvent` ([javadoc](https://mcstreetguy.github.io/NeoForgeJavaDocs/1.20.3-20.3.8/net/neoforged/neoforge/event/entity/EntityLeaveLevelEvent.html): "fired whenever an entity is removed from the level in `LevelCallback.onTrackingEnd(Object)`", not cancellable). In the catalog it has `neoforge`, `side: server` and `cancellable: false`. It covers item entities and experience orbs. It runs once the entity is out of the level's lists, at every place Horizon takes one out: - **Single removals** go through two new helpers next to `spawn_item` / `add_orb`: `remove_dropped(i)` and `remove_orb(i)`. - A hopper or hopper minecart taking an item (`suck_item_entities`). - A guest picking up an item or an orb (`lan_actions`). - Allays, piglins, pandas, villagers, sulfur cubes and raiders taking items. - An item going through a nether portal or an End gateway. - `/kill` of an item. - **Sweeps** take the IDs before and report the missing ones after, in the same call: - The item tick (merges, burning, despawn, the local player's pickups). - The orb tick (merges, despawn, pickups). - An explosion and a lightning strike destroying items. - `/kill` of orbs. - Chunk unload in `entity_chunks(.., remove: true)`. That also covers a level closing because nobody is in it (`close_idle_levels`) and the deprecated in-frame dimension change. As in vanilla, nothing is told for the entities still loaded when a world closes or the server stops (`PersistentEntitySectionManager.close` only saves). On a client of a server nothing fires. ## Kind - [x] feature: something new for players (listed under New in the release notes) - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference 26.3's `PersistentEntitySectionManager`: - `stopTracking` calls `callbacks.onTrackingEnd`. - Removal reaches it through `Callback.onRemove` (any removal reason, while the section is accessible). - So does a section turning inaccessible (`updateChunkStatus`), which is how chunk unload reaches it. - `close()` is `saveAll()` plus closing storage, with no `stopTracking`. With no mod installed the hook is empty. The only change is the ID bookkeeping, which is skipped on a client. ## Other projects' code none ## Tested in the game A throwaway probe in the hook logs every leave (removed before the commit). Fresh `mktemp -d` homes, `HORIZON_NO_AUDIO=1`, `--profile fast`. Each test entity's ID was read with `horizon-ctl entities` right after it was summoned on a stone platform at y=100, to tell it from the world's own drops. **Single player (server thread)** | Test | Leave | |---|---| | `summon item … {Age:5960s}` (stone) | #158 leaves when it despawns | | Two apples side by side | #363 leaves when it merges into #365; #365 leaves later with its chunk | | `summon item` (stick), then `kill @e[type=item,…]` | #410 leaves | | Iron ingot dropped onto a hopper | leaves as the hopper takes it | | Feather next to `summon tnt … {fuse:0s}` | #431 leaves (blown up), along with the platform's cobblestone drops later | | Gold ingot at the creative player's feet | #505 leaves on pickup | | Emerald into a nether portal built with `/fill` | leaves the overworld | | Brick, then the player teleports 5000 blocks away | #441 leaves when its chunk unloads | | Two orbs on one spot plus one more, then `kill @e[type=experience_orb]` | 3 orb leaves (one merge, two kills) | **Dedicated server (`--dedicated --nogui`) with a `horizon-ctl` client, Alex (survival)** | Test | Leave | |---|---| | `execute at Alex run summon item … diamond` and `… experience_orb` | item #160 and orb #161 leave as Alex picks them up (the guest pickup path) | | An emerald left on the ground, then `stop` | nothing, as in vanilla | | Alex's own client | nothing fires | Not verified separately: a level closing empty after 300 ticks. It goes through the same `entity_chunks` code as the chunk unload above. Parity, locally (`tools/parity.py server_entities dispenser spawn_loot crafter composter`): 5 passed. The other 36 harnesses that cover these files are CI's. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base hr/main` on cachyos-x8664, against hr/main at 01bbb4c65, 6 min 58 s) | Check | Result | | --- | --- | | Scope | ✅ 18 files, +122 −14 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed (1 min 0 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (1 min 22 s) | | tests: horizon-client | ✅ 1340 passed (4 min 19 s) | | doc tests | ✅ 0 passed (1 s) | | Parity | ➖ 39 affected, to run in CI (--quick); 5 of them passed locally | 🤖 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:12:13 +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#6117
No description provided.