[PR #962] [MERGED] Keep restored chunk entities out of /summon's result after a level switch #2944

Closed
opened 2026-11-02 16:00:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/level-switch-entities


📝 Commits (1)

  • c0f0c17 Keep restored chunk entities out of /summon's result after a level switch

📊 Changes

5 files changed (+76 additions, -3 deletions)

View changed files

📝 crates/horizon-client/src/game/command_harness.rs (+20 -1)
📝 crates/horizon-client/src/game/commands/data.rs (+8 -1)
📝 crates/horizon-client/src/game/nether_portal.rs (+6 -0)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaCommandExecOracle.java (+18 -0)
📝 tools/command_exec_corpus.py (+24 -1)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Fixes #947. Found while checking LookImEcho-Rick's #800 (/execute in <dimension> run tp, #592); with this merged, #800 passes command_exec 780/780.

What was wrong

Game::switch_level saves the departing level's entities with its chunks, and coming back the chunk loader puts them in World::loaded_entities, spawned on the next tick (spawn_loaded_entities, vanilla's PersistentEntitySectionManager.processPendingLoads in the level tick). Entity ids are never reused (next_entity only grows): there is no id collision. Two things went wrong:

  • /summon (spawn_entity_from_nbt) pushed its compound onto that queue and drained all of it, then took before + 1 as its root. With the Overworld's saved entities still waiting, the first of them (the pig) got that id: "Summoned new Pig" for an armor stand. Summon now spawns only its own stack and leaves the waiting entities to the tick. This also happened in the game whenever a summon ran while freshly loaded chunks' entities were waiting.
  • The command harness's settle only waited for the terrain, without a tick, so the commands after it ran before those entities spawned (/swing @e[type=minecraft:pig]: "No entity was found"). The vanilla oracle's settle waits for the entities too (areEntitiesActuallyLoadedAndTicking); Horizon's now spawns the waiting entities of the loaded chunks before it returns.

Portal round trip

Portal travel uses the same switch_level path. The harness gets a portal op: the player goes through the nether portal it stands in, as Entity.handlePortal does once its portal process has finished (vanilla: NetherPortalBlock.getPortalDestination + Entity.teleportToPortalDestination; Horizon: player_through_nether_portal, the tail of tick_nether_portal moved into a function). The corpus's new levels group builds a portal, goes to the Nether and back through it, then checks the dimension, the arrival Pos/Rotation, the pig from entities, and a summon's feedback.

How tested

  • levels without the fix (corpus and op only): 2 mismatches, /execute if entity @e[type=minecraft:pig] (vanilla "Test passed. Count: 1", Horizon "Test failed") and /summon minecraft:armor_stand … CustomName:"Back" (vanilla "Summoned new Back", Horizon "Summoned new Dirt").
  • With the fix: command_exec 764/764, 3 runs in a row (tools/parity.py --repeat 3 command_exec).
  • #800 + main + this fix: command_exec 780/780 (#800 + main alone: 771/774, the two #947 mismatches plus a /random reset * count of 10 against 11 that didn't show up again in the four runs after it).
  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings: clean. cargo test -p horizon-client: 993 passed.
  • tools/parity.py --changed origin/main: 20 passed, 0 failed (arrow, block_removal, composter, crafter, dedicated_server, dispenser, locator_bar, mace, online_mode, sculk, section_mesh, secure_chat, server_dimension_players, server_entities, server_ops_feedback, server_player_targets, server_world_gen, use_item_on, user_cache, world_spawn), plus command_exec above.

Needs Ludovic: nothing.

🤖 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/962 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/level-switch-entities` --- ### 📝 Commits (1) - [`c0f0c17`](https://github.com/horizon-rust/horizon/commit/c0f0c17ed4b05dd72d9ecda26ae6a925e0018f0c) Keep restored chunk entities out of /summon's result after a level switch ### 📊 Changes **5 files changed** (+76 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/command_harness.rs` (+20 -1) 📝 `crates/horizon-client/src/game/commands/data.rs` (+8 -1) 📝 `crates/horizon-client/src/game/nether_portal.rs` (+6 -0) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaCommandExecOracle.java` (+18 -0) 📝 `tools/command_exec_corpus.py` (+24 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes #947. Found while checking LookImEcho-Rick's #800 (`/execute in <dimension> run tp`, #592); with this merged, #800 passes `command_exec` 780/780. ## What was wrong `Game::switch_level` saves the departing level's entities with its chunks, and coming back the chunk loader puts them in `World::loaded_entities`, spawned on the next tick (`spawn_loaded_entities`, vanilla's `PersistentEntitySectionManager.processPendingLoads` in the level tick). Entity ids are never reused (`next_entity` only grows): there is no id collision. Two things went wrong: - `/summon` (`spawn_entity_from_nbt`) pushed its compound onto that queue and drained all of it, then took `before + 1` as its root. With the Overworld's saved entities still waiting, the first of them (the pig) got that id: "Summoned new Pig" for an armor stand. Summon now spawns only its own stack and leaves the waiting entities to the tick. This also happened in the game whenever a summon ran while freshly loaded chunks' entities were waiting. - The command harness's `settle` only waited for the terrain, without a tick, so the commands after it ran before those entities spawned (`/swing @e[type=minecraft:pig]`: "No entity was found"). The vanilla oracle's settle waits for the entities too (`areEntitiesActuallyLoadedAndTicking`); Horizon's now spawns the waiting entities of the loaded chunks before it returns. ## Portal round trip Portal travel uses the same `switch_level` path. The harness gets a `portal` op: the player goes through the nether portal it stands in, as `Entity.handlePortal` does once its portal process has finished (vanilla: `NetherPortalBlock.getPortalDestination` + `Entity.teleportToPortalDestination`; Horizon: `player_through_nether_portal`, the tail of `tick_nether_portal` moved into a function). The corpus's new `levels` group builds a portal, goes to the Nether and back through it, then checks the dimension, the arrival `Pos`/`Rotation`, the pig from `entities`, and a summon's feedback. ## How tested - `levels` without the fix (corpus and op only): 2 mismatches, `/execute if entity @e[type=minecraft:pig]` (vanilla "Test passed. Count: 1", Horizon "Test failed") and `/summon minecraft:armor_stand … CustomName:"Back"` (vanilla "Summoned new Back", Horizon "Summoned new Dirt"). - With the fix: `command_exec` 764/764, 3 runs in a row (`tools/parity.py --repeat 3 command_exec`). - #800 + main + this fix: `command_exec` 780/780 (#800 + main alone: 771/774, the two #947 mismatches plus a `/random reset *` count of 10 against 11 that didn't show up again in the four runs after it). - `cargo fmt --all -- --check`, `cargo clippy --workspace --all-targets -- -D warnings`: clean. `cargo test -p horizon-client`: 993 passed. - `tools/parity.py --changed origin/main`: 20 passed, 0 failed (arrow, block_removal, composter, crafter, dedicated_server, dispenser, locator_bar, mace, online_mode, sculk, section_mesh, secure_chat, server_dimension_players, server_entities, server_ops_feedback, server_player_targets, server_world_gen, use_item_on, user_cache, world_spawn), plus command_exec above. Needs Ludovic: nothing. 🤖 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-02 16:00:18 +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#2944
No description provided.