[PR #2285] [MERGED] Load the loot tables before a world's first chunks are read #4173

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

📋 Pull Request Information

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

Base: main ← Head: fix/loot-tables-before-chunks


📝 Commits (5)

📊 Changes

2 files changed (+121 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/game/world_loading.rs (+4 -0)
➕ tools/test_spawn_loot_parity.py (+117 -0)

📄 Description

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

Follows #2073 (FusselTV's "unopened containers keep their loot table", landed through #2288).

What and why

#2073 rolls a loaded container that has a loot table and no items as its chunk is decoded (save::roll_loaded_loot), so that a container nobody opens still saves the way vanilla wrote it. It reads the loot tables that structure_blocks::loot_data has already loaded. But those tables were loaded lazily, on the first level tick. The spawn chunks are decoded while the world opens, before that tick, so a loot chest near spawn came out empty and lost its loot table on the next save. Found while gating #2073: seeded chests matched vanilla 48/48 at x/z 3000 but stayed empty near spawn.

WorldRequest::prepare now loads the tables first. Every world opens through it: in-frame, on the server thread, and on a dedicated server (load_world and the background WorldLoader).

Testing

New spawn_loot harness. The vanilla 26.3 server writes a flat world with a seeded simple_dungeon chest beside the world spawn, then rolls the chest itself in a copy of the world. Horizon opens the untouched world in a fresh process and must hold the same stacks in the same slots.

server thread in-frame
without the fix 0 stacks (FAIL) 0 stacks (FAIL)
with the fix 18 stacks, same as vanilla 18 stacks, same as vanilla

My first placement was in a Horizon world (setblock ... chest{LootTable:...}). That doesn't work as a test: Horizon's setblock drops the LootTable from the block entity NBT (data get block shows Items: []), so the harness builds its world with vanilla instead.

Self-check

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 5f1c25c22, 9 min 28 s)

Check Result
Scope ✅ 2 files, +121 (after #2288)
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ⚠️ 310 run, 2 errors, both macOS-only and on main too (test_parity_runner without a java mock, test_rust_parity with /private/var vs /var)
rustfmt ✅
clippy ✅
tests: horizon-client ✅ 1331 passed
Parity spawn_loot, world_reopen, save_roundtrip ✅ here; the rest runs in CI

🤖 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/2285 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/loot-tables-before-chunks` --- ### 📝 Commits (5) - [`4471e59`](https://github.com/horizon-rust/horizon/commit/4471e59132dd8af6248d8685d066aa86ae6c15a6) Load the loot tables before a world's first chunks are read - [`9aba251`](https://github.com/horizon-rust/horizon/commit/9aba251de58a27a97e9c4aa4ee075d5b845f5f7f) Merge #2288 (#2073 with main merged) - [`94e8b18`](https://github.com/horizon-rust/horizon/commit/94e8b184bcd7b249bf5ba992eaf96be2bc9f8e89) Merge main - [`eee7253`](https://github.com/horizon-rust/horizon/commit/eee7253b1b00b0b1a85150d5dde652ee88ee6715) Merge main - [`e57faff`](https://github.com/horizon-rust/horizon/commit/e57faff4a3e37140dccf6c22e4df6f109cfe887d) Merge main ### 📊 Changes **2 files changed** (+121 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/world_loading.rs` (+4 -0) ➕ `tools/test_spawn_loot_parity.py` (+117 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Follows #2073 (FusselTV's "unopened containers keep their loot table", landed through #2288). ## What and why #2073 rolls a loaded container that has a loot table and no items as its chunk is decoded (`save::roll_loaded_loot`), so that a container nobody opens still saves the way vanilla wrote it. It reads the loot tables that `structure_blocks::loot_data` has already loaded. But those tables were loaded lazily, on the first level tick. The spawn chunks are decoded while the world opens, before that tick, so a loot chest near spawn came out empty and lost its loot table on the next save. Found while gating #2073: seeded chests matched vanilla 48/48 at x/z 3000 but stayed empty near spawn. `WorldRequest::prepare` now loads the tables first. Every world opens through it: in-frame, on the server thread, and on a dedicated server (`load_world` and the background `WorldLoader`). ## Testing New `spawn_loot` harness. The vanilla 26.3 server writes a flat world with a seeded `simple_dungeon` chest beside the world spawn, then rolls the chest itself in a copy of the world. Horizon opens the untouched world in a fresh process and must hold the same stacks in the same slots. | | server thread | in-frame | |---|---|---| | without the fix | 0 stacks (FAIL) | 0 stacks (FAIL) | | with the fix | 18 stacks, same as vanilla | 18 stacks, same as vanilla | My first placement was in a Horizon world (`setblock ... chest{LootTable:...}`). That doesn't work as a test: Horizon's `setblock` drops the `LootTable` from the block entity NBT (`data get block` shows `Items: []`), so the harness builds its world with vanilla instead. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 5f1c25c22, 9 min 28 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +121 (after #2288) | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ⚠️ 310 run, 2 errors, both macOS-only and on main too (`test_parity_runner` without a `java` mock, `test_rust_parity` with `/private/var` vs `/var`) | | rustfmt | ✅ | | clippy | ✅ | | tests: horizon-client | ✅ 1331 passed | | Parity | `spawn_loot`, `world_reopen`, `save_roundtrip` ✅ here; the rest runs in CI | 🤖 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 04:15: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#4173
No description provided.