[PR #7471] Loading goes through the entity trait #7619

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7471
Author: @HrafnaValkyrja
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: refactor/entity-walk-loads


📝 Commits (4)

  • a17637b Load saved entities through Entity::load_nbt
  • 8162a02 Merge origin/main into refactor/entity-walk-loads
  • 6c8cff2 Merge remote-tracking branch 'origin/main' into refactor/entity-walk-loads
  • a8d94a9 Merge origin/main into refactor/entity-walk-loads

📊 Changes

2 files changed (+577 additions, -290 deletions)

View changed files

📝 crates/horizon-client/src/game/entity.rs (+249 -0)
📝 crates/horizon-client/src/game/persist.rs (+328 -290)

📄 Description

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

What and why

Slice 10b of #6509, the load half of #6545 (the save half is #7094): loading a saved entity now goes through the Entity trait.

  • New required trait method Entity::load_nbt(game, kind, uuid, player_uuid, tag) -> Result<(), Tag>: Ok when this kind claims the type id and loads it, Err(tag) hands the compound back. The 11 kinds in entity_lists! implement it; the bodies moved unchanged into Game::load_* methods in persist.rs.
  • One macro-generated chain over entity_lists! (load_entity_of_any_kind!, same pattern as save_entities_of_every_kind!): static dispatch, no dyn, no allocation (the compound moves through, nothing is cloned).
  • load_nbt has no default, so a kind added to entity_lists! cannot be left out of loading, as save_nbt cannot be left out of saving.
  • Dragon, end crystals, ominous item spawners, item frames, cushions, paintings, unsimulated compounds and unknown compounds are not in entity_lists!; they keep their arms in load_unlisted and the fallback.
  • Order of the checks: unlisted kinds, then entity_lists! order, then the compound fallback. Before, mob_types was tested last; now Mob is first among the listed kinds. A unit test checks that no mob species shares an id with another kind, so the result is the same.
  • No change to file order, entity id assignment or what is written. Diff: +576 -289 in two files (entity.rs +249, persist.rs +327 -289), most of it moved code.
  • Tick cost: loading does not run in the tick. Per loaded entity the chain is at most 11 type-id tests before the fallback; nothing is allocated per entity that was not before. I did not time it.

Overlap: a branch that touches persist.rs doc comments and the save round-trip test, and one that may touch projectile summon, can conflict textually in persist.rs; this PR does not change their behaviour. Merged with main after #7172, #7267 and #7284: spectral arrows, llama spit and shulker bullets load through Projectile::load_nbt.

Fixes #6545

Fixes #6545

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

Real 26.3 server.jar as the oracle, same console script on both sides: forceload, tick freeze, summon, tick step 40, save-all flush, stop, read the entity region files, restart, save-all flush, stop, read again. Vanilla's own entity order is not asserted. Nothing about vanilla's behaviour is changed by this PR.

Proof

World with every kind Horizon simulates plus the unsimulated ones (98 summons x 2 groups, one group unloaded before saving; painting summon is refused by Horizon so paintings are not in the Horizon worlds). Dumps compared field by field with entities matched by id and position. "Old" is main at the merge point, "new" is this branch, both built with the fast profile.

Horizon summon, save, load, save (165 entities matched):

comparison fields compared differing fields
old vs new, first save 3,580 12, all random UUIDs
old vs a second run of old (noise), first save 3,580 12, same UUIDs
old vs new, save after reload 3,580 12, same UUIDs
old vs a second run of old (noise), after reload 3,580 12, same UUIDs

The random UUIDs are on pigs, bees, tridents and spectral arrows whose summoned UUID Horizon does not keep; they change between two runs of the old build too (existing behaviour, cause not investigated). Entity order and chunk slot and index are identical.

One outlier to report: my first run of the new build gave 164 matched entities and 55 differing fields (entities ticked two ticks further: arrow HasBeenShot, orb age). A second run of the new build is the row above. I take the first for a timing difference between tick freeze and the summons in the harness, not a load difference, but I did not find the cause; that run is kept in the proof folder.

Vanilla save loaded in Horizon, saved (169 entities in the vanilla save, 168 saved by Horizon), old vs new:

comparison fields compared differing fields
old vs new, first save 4,002 4 (trident and spectral arrow UUIDs) in the second new run; 13 in the first
old vs a second run of old 4,002 4 (same UUIDs)
old vs new, save after reload 4,002 7 in the second new run (the UUIDs plus one zombie Fire and HurtTime and one minecart rider Fire), 10 in the first
old vs a second run of old 4,002 14 (UUIDs, boat passenger Rotation, sunburnt zombie, skeleton and horse rider Fire, Health, HurtTime)

The extra fields in the old-vs-new rows are the sunburn and rider-rotation fields that also differ between two runs of the old build.

Horizon-saved world loaded back into vanilla and saved (166 vs 166 entities matched, old vs new): 46 differing fields in the first save and 61 after the reload, all of the kind that depends on how many ticks vanilla ran (zombie and skeleton Fire, Health, HurtTime, TNT fuse, trident life, orb and cloud Age). I did not run the old build twice here, so there is no noise row for this pair.

Vanilla vs Horizon (not changed by this PR): Horizon saves 168 of vanilla's 169 entities (a firework rocket and an ominous item spawner are missing from the matched set), and 91 fields differ; old and new show the same differences. Cause of each not investigated.

Not run: sbs.py (side by side), which compares live scenes; there is no scene for loading a saved entity, and the field comparison above covers it.

Raw dumps and diffs are kept locally.

Harnesses

Run locally in the build fence with DISPLAY=:0 HORIZON_E2E_HEADLESS=1, after merging main. CI runs the full --changed set.

PASS world_reopen 17s
PASS server_entities 90s
PASS save_roundtrip 104s

pr_ready --quick: rustfmt, clippy and horizon-client tests (693) pass.

Proved by script against the real 26.3 server; no human played this change.

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick on Valhalla, against origin/main at f696adc89, 4 min 4 s)

Check Result
Scope ⚠️ 2 files, +576 −289; 865 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 614 passed (28 s)
rustfmt ✅ (7 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 36 s)
tests: horizon-client ✅ 695 passed (1 min 34 s)
doc tests ✅ 0 passed (1 s)
content root tests ➖ content root untouched
mod API up to date ✅ (12 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 225 affected, to run in CI (--quick): anvil_turtle_egg, armor_stand_turtle_egg, arrow, arrow_wind_charge, block_removal, boat_authority, boat_paddle_reset, command_exec, composter, crafter, cursor_death, dedicated_server and 213 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/7471 **Author:** [@HrafnaValkyrja](https://github.com/HrafnaValkyrja) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `refactor/entity-walk-loads` --- ### 📝 Commits (4) - [`a17637b`](https://github.com/horizon-rust/horizon/commit/a17637bdd2cedb46a39fe7a1c2c390509a5fc205) Load saved entities through Entity::load_nbt - [`8162a02`](https://github.com/horizon-rust/horizon/commit/8162a02e53537b8478646953067c98e30ff0f451) Merge origin/main into refactor/entity-walk-loads - [`6c8cff2`](https://github.com/horizon-rust/horizon/commit/6c8cff263066601b5aa49a39db56468184884727) Merge remote-tracking branch 'origin/main' into refactor/entity-walk-loads - [`a8d94a9`](https://github.com/horizon-rust/horizon/commit/a8d94a97c7ece0b71f1807ad68bd3109d797a471) Merge origin/main into refactor/entity-walk-loads ### 📊 Changes **2 files changed** (+577 additions, -290 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/entity.rs` (+249 -0) 📝 `crates/horizon-client/src/game/persist.rs` (+328 -290) </details> ### 📄 Description > 🤖 Opened by Valkyrie's AI agent (Claude Code, Opus 5.5), not by Valkyrie herself. ## What and why Slice 10b of #6509, the load half of #6545 (the save half is #7094): loading a saved entity now goes through the `Entity` trait. - New required trait method `Entity::load_nbt(game, kind, uuid, player_uuid, tag) -> Result<(), Tag>`: `Ok` when this kind claims the type id and loads it, `Err(tag)` hands the compound back. The 11 kinds in `entity_lists!` implement it; the bodies moved unchanged into `Game::load_*` methods in `persist.rs`. - One macro-generated chain over `entity_lists!` (`load_entity_of_any_kind!`, same pattern as `save_entities_of_every_kind!`): static dispatch, no `dyn`, no allocation (the compound moves through, nothing is cloned). - `load_nbt` has no default, so a kind added to `entity_lists!` cannot be left out of loading, as `save_nbt` cannot be left out of saving. - Dragon, end crystals, ominous item spawners, item frames, cushions, paintings, unsimulated compounds and unknown compounds are not in `entity_lists!`; they keep their arms in `load_unlisted` and the fallback. - Order of the checks: unlisted kinds, then `entity_lists!` order, then the compound fallback. Before, `mob_types` was tested last; now `Mob` is first among the listed kinds. A unit test checks that no mob species shares an id with another kind, so the result is the same. - No change to file order, entity id assignment or what is written. Diff: +576 -289 in two files (`entity.rs` +249, `persist.rs` +327 -289), most of it moved code. - Tick cost: loading does not run in the tick. Per loaded entity the chain is at most 11 type-id tests before the fallback; nothing is allocated per entity that was not before. I did not time it. Overlap: a branch that touches `persist.rs` doc comments and the save round-trip test, and one that may touch projectile summon, can conflict textually in `persist.rs`; this PR does not change their behaviour. Merged with main after #7172, #7267 and #7284: spectral arrows, llama spit and shulker bullets load through `Projectile::load_nbt`. Fixes #6545 Fixes #6545 ## Kind - [x] 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 Real 26.3 `server.jar` as the oracle, same console script on both sides: forceload, `tick freeze`, summon, `tick step 40`, `save-all flush`, stop, read the entity region files, restart, `save-all flush`, stop, read again. Vanilla's own entity order is not asserted. Nothing about vanilla's behaviour is changed by this PR. ## Proof World with every kind Horizon simulates plus the unsimulated ones (98 summons x 2 groups, one group unloaded before saving; painting `summon` is refused by Horizon so paintings are not in the Horizon worlds). Dumps compared field by field with entities matched by id and position. "Old" is main at the merge point, "new" is this branch, both built with the `fast` profile. Horizon summon, save, load, save (165 entities matched): | comparison | fields compared | differing fields | |---|---|---| | old vs new, first save | 3,580 | 12, all random UUIDs | | old vs a second run of old (noise), first save | 3,580 | 12, same UUIDs | | old vs new, save after reload | 3,580 | 12, same UUIDs | | old vs a second run of old (noise), after reload | 3,580 | 12, same UUIDs | The random UUIDs are on pigs, bees, tridents and spectral arrows whose summoned UUID Horizon does not keep; they change between two runs of the old build too (existing behaviour, cause not investigated). Entity order and chunk slot and index are identical. One outlier to report: my first run of the new build gave 164 matched entities and 55 differing fields (entities ticked two ticks further: arrow `HasBeenShot`, orb age). A second run of the new build is the row above. I take the first for a timing difference between `tick freeze` and the summons in the harness, not a load difference, but I did not find the cause; that run is kept in the proof folder. Vanilla save loaded in Horizon, saved (169 entities in the vanilla save, 168 saved by Horizon), old vs new: | comparison | fields compared | differing fields | |---|---|---| | old vs new, first save | 4,002 | 4 (trident and spectral arrow UUIDs) in the second new run; 13 in the first | | old vs a second run of old | 4,002 | 4 (same UUIDs) | | old vs new, save after reload | 4,002 | 7 in the second new run (the UUIDs plus one zombie Fire and HurtTime and one minecart rider Fire), 10 in the first | | old vs a second run of old | 4,002 | 14 (UUIDs, boat passenger Rotation, sunburnt zombie, skeleton and horse rider Fire, Health, HurtTime) | The extra fields in the old-vs-new rows are the sunburn and rider-rotation fields that also differ between two runs of the old build. Horizon-saved world loaded back into vanilla and saved (166 vs 166 entities matched, old vs new): 46 differing fields in the first save and 61 after the reload, all of the kind that depends on how many ticks vanilla ran (zombie and skeleton Fire, Health, HurtTime, TNT fuse, trident life, orb and cloud Age). I did not run the old build twice here, so there is no noise row for this pair. Vanilla vs Horizon (not changed by this PR): Horizon saves 168 of vanilla's 169 entities (a firework rocket and an ominous item spawner are missing from the matched set), and 91 fields differ; old and new show the same differences. Cause of each not investigated. Not run: `sbs.py` (side by side), which compares live scenes; there is no scene for loading a saved entity, and the field comparison above covers it. Raw dumps and diffs are kept locally. ## Harnesses Run locally in the build fence with `DISPLAY=:0 HORIZON_E2E_HEADLESS=1`, after merging main. CI runs the full `--changed` set. ``` PASS world_reopen 17s PASS server_entities 90s PASS save_roundtrip 104s ``` `pr_ready --quick`: rustfmt, clippy and horizon-client tests (693) pass. Proved by script against the real 26.3 server; no human played this change. ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on Valhalla, against origin/main at f696adc89, 4 min 4 s) | Check | Result | | --- | --- | | Scope | ⚠️ 2 files, +576 −289; 865 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 614 passed (28 s) | | rustfmt | ✅ (7 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 36 s) | | tests: horizon-client | ✅ 695 passed (1 min 34 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (12 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 225 affected, to run in CI (--quick): anvil_turtle_egg, armor_stand_turtle_egg, arrow, arrow_wind_charge, block_removal, boat_authority, boat_paddle_reset, command_exec, composter, crafter, cursor_death, dedicated_server and 213 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>
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#7619
No description provided.