[PR #203] [MERGED] Loaded spawners keep their mob; chunk block entities in vanilla's order #2403

Closed
opened 2026-11-02 15:55:45 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/dedicated-server-spawners


📝 Commits (1)

  • d93b347 Loaded spawners keep their mob; chunk block entities in vanilla's order

📊 Changes

2 files changed (+51 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/lan/chunks.rs (+16 -0)
📝 crates/horizon-client/src/save.rs (+35 -1)

📄 Description

What was wrong

The new parity CI job failed dedicated_server on #186, an unrelated PR, so the failure is on main. Reproduced on main (94aeab9a): 10 differing lines.

  • Spawners. Generated spawners reached the client with a null update tag. Vanilla sends {Delay:20s,…,SpawnData:{entity:{id:"minecraft:zombie"}},SpawnRange:4s}. Affected: dungeon zombie and spider spawners and a mineshaft cave-spider spawner, plus the chunk hashes of those chunks.
    • Cause: the harness serves a world that vanilla generated, so Horizon loads the spawners from the region files. In those files a spawner's block entity id is minecraft:mob_spawner, not its block's name. save::decode_block_entity called BlockEntity::for_block("minecraft:mob_spawner"), which knows only minecraft:spawner. So every spawner loaded from a save was dropped, and the chunk packet carried no update tag for it.
    • This also hit Horizon's own worlds: since #146 added the spawner block entity, a reloaded world lost its spawners' mobs. Worldgen (MonsterRoomFeature and the structures' setEntityId) was already right; the bug was only in loading.
    • Fix: minecraft:mob_spawner maps to the spawner block.
  • Block entity order. In chunk 7,-5 two sculk sensors were listed in the wrong order. This one depends on the world, so not every run shows it.
    • What vanilla does: SerializableChunkData puts the saved block_entities list, in order, into ChunkAccess.pendingBlockEntities (a HashMap). LevelChunk then promotes them into blockEntities (an Object2ObjectOpenHashMap), and the packet iterates that map. Positions that share a bucket keep their insertion order.
    • Cause: Horizon reproduced the hashing (java_hash_order) but fed it the section-scan order, and the two sensors share a bucket in both maps.
    • Fix: the save's list order is now kept on the chunk (ChunkExtras::block_entity_order) and used as the insertion order. Block entities not in the save follow in scan order.

How it was tested

On the Mac mini:

  • tools/test_dedicated_server_parity.py: 542 transcript lines identical (was 10 differing).
  • tools/test_spawner_parity.py: 6,000/6,000.
  • cargo test -p horizon-client: all pass, including a new spawner_block_entity_round_trips test (a vanilla-saved dungeon spawner decodes with its mob and survives a save and reload).
  • cargo clippy --workspace --all-targets -D warnings and cargo fmt --check: clean.

The full parity --changed set (78 harnesses) runs in this PR's CI job.

Follows up #146. Fixes no issue.

🤖 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/203 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/dedicated-server-spawners` --- ### 📝 Commits (1) - [`d93b347`](https://github.com/horizon-rust/horizon/commit/d93b347b417036c52fe1e6a361bc61a2ca5f16a0) Loaded spawners keep their mob; chunk block entities in vanilla's order ### 📊 Changes **2 files changed** (+51 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/lan/chunks.rs` (+16 -0) 📝 `crates/horizon-client/src/save.rs` (+35 -1) </details> ### 📄 Description ## What was wrong The new `parity` CI job failed `dedicated_server` on #186, an unrelated PR, so the failure is on `main`. Reproduced on main (94aeab9a): 10 differing lines. - **Spawners.** Generated spawners reached the client with a `null` update tag. Vanilla sends `{Delay:20s,…,SpawnData:{entity:{id:"minecraft:zombie"}},SpawnRange:4s}`. Affected: dungeon zombie and spider spawners and a mineshaft cave-spider spawner, plus the chunk hashes of those chunks. - **Cause:** the harness serves a world that vanilla generated, so Horizon loads the spawners from the region files. In those files a spawner's block entity id is `minecraft:mob_spawner`, not its block's name. `save::decode_block_entity` called `BlockEntity::for_block("minecraft:mob_spawner")`, which knows only `minecraft:spawner`. So every spawner loaded from a save was dropped, and the chunk packet carried no update tag for it. - This also hit Horizon's own worlds: since #146 added the spawner block entity, a reloaded world lost its spawners' mobs. Worldgen (`MonsterRoomFeature` and the structures' `setEntityId`) was already right; the bug was only in loading. - **Fix:** `minecraft:mob_spawner` maps to the spawner block. - **Block entity order.** In chunk 7,-5 two sculk sensors were listed in the wrong order. This one depends on the world, so not every run shows it. - **What vanilla does:** `SerializableChunkData` puts the saved `block_entities` list, in order, into `ChunkAccess.pendingBlockEntities` (a `HashMap`). `LevelChunk` then promotes them into `blockEntities` (an `Object2ObjectOpenHashMap`), and the packet iterates that map. Positions that share a bucket keep their insertion order. - **Cause:** Horizon reproduced the hashing (`java_hash_order`) but fed it the section-scan order, and the two sensors share a bucket in both maps. - **Fix:** the save's list order is now kept on the chunk (`ChunkExtras::block_entity_order`) and used as the insertion order. Block entities not in the save follow in scan order. ## How it was tested On the Mac mini: - `tools/test_dedicated_server_parity.py`: **542 transcript lines identical** (was 10 differing). - `tools/test_spawner_parity.py`: 6,000/6,000. - `cargo test -p horizon-client`: all pass, including a new `spawner_block_entity_round_trips` test (a vanilla-saved dungeon spawner decodes with its mob and survives a save and reload). - `cargo clippy --workspace --all-targets -D warnings` and `cargo fmt --check`: clean. The full `parity --changed` set (78 harnesses) runs in this PR's CI job. Follows up #146. Fixes no issue. 🤖 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 15:55:45 +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#2403
No description provided.