[PR #2288] [MERGED] Saves: unopened containers keep their loot table (carries #2073) #4177

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

📋 Pull Request Information

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

Base: main ← Head: carry/2073-keep-loot-tables


📝 Commits (2)

  • fc0b739 x
  • bf39e5d Merge main (save.rs: keep both new tests; the loot test encodes with LevelShape::OVERWORLD after #2070)

📊 Changes

6 files changed (+280 additions, -72 deletions)

View changed files

📝 crates/horizon-client/src/game/fishing.rs (+1 -1)
📝 crates/horizon-client/src/game/minecarts.rs (+10 -0)
📝 crates/horizon-client/src/game/persist.rs (+26 -1)
📝 crates/horizon-client/src/save.rs (+151 -2)
📝 crates/horizon-client/src/structure_blocks.rs (+86 -63)
📝 crates/horizon-client/src/vanillagen.rs (+6 -5)

📄 Description

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

This carries @FusselTV's #2073 unchanged, plus one merge of main. After #2070 merged, #2073 conflicted in save.rs (both added a test at the same place), and its loot test had to call encode_with with LevelShape::OVERWORLD. GitHub doesn't let maintainers push to a fork owned by an organization (RoyalPixelsDE), so the merge lives on this branch. FusselTV's commit keeps its author, and the merger lands it with a merge commit.

The merge keeps both tests. save::tests passes 26/26, including unopened_rolled_containers_save_their_loot_table and nether_and_end_chunks_save_with_their_own_height.

Gate evidence from #2073: seeded chests roll the same items as vanilla 26.3, 48/48 on the server thread and in-frame. save_roundtrip, world_reopen, chunk_generation, structure_start_nbt, structure_blocks, structure_layout, trial_spawner and vault pass on an integration tree with the whole save series. A vanilla save of a generated world round-trips through Horizon back to vanilla.

Closes #2073 once merged.


FusselTV's original description:

(#2073) Opened by FusselTV's AI agent (Claude Code, Opus 5.5), not by FusselTV personally.

What and why

Horizon rolls a generated container's loot table when it makes the chunk, and the save wrote the rolled Items. Vanilla keeps LootTable and LootTableSeed until a player first opens the container (RandomizableContainer.unpackLootTable). A world pre-generated by Horizon and then opened in vanilla or Paper therefore had:

  • loot that vanilla never rolls for that seed and position,
  • no loot table to unpack, so the loot advancements cannot fire (War Pigs, and every "loot a chest in X" check that keys on the table),
  • plugins that react to loot generation never called.

The other direction was broken too. A vanilla-made world opened in Horizon has containers with a LootTable and no Items, and Horizon showed them empty.

What changes:

  • A generated container whose items are still exactly the roll is saved as its LootTable and seed again (RolledLoot::restore). Once its items change, the items are saved instead and the table is dropped, as unpackLootTable does.
  • A loaded container with a LootTable and no items is rolled on load the same way, and is saved as its table again while it is untouched.
  • A container that was loaded with a table, rolled and then changed loses the table. Without that, a chest emptied after a load would fill up again on the next load.
  • Chest minecarts (mineshafts) keep their table from generation and are rolled when the game loads them. This replaces unpack_entity_loot.
  • A zero LootTableSeed is not written, as trySaveLootTable leaves it out.
  • Rolled items keep what #1911 added: enchantments, potions and an ominous bottle's level (loot_item_with_components). LootTable.fill uses the container's own size instead of 27.

Vanilla reference

  • RandomizableContainer.tryLoadLootTable / trySaveLootTable / unpackLootTable
  • ContainerEntity.addChestVehicleSaveData / readChestVehicleSaveData / unpackChestVehicleLootTable
  • LootTable.fill

Tests

  • New unit test save::tests::unopened_rolled_containers_save_their_loot_table. An untouched rolled chest saves LootTable and seed with no Items, and a changed chest saves Items with no table. A chest loaded with a table, then emptied, saves no table. A negative control confirmed that last part: with the fix removed, the test fails with assertion failed: emptied.get("LootTable").is_none().
  • New unit test structure_blocks::tests::a_container_rolled_without_loot_data_saves_its_table.
  • tools/test_block_entity_storage_parity.py passed on this branch: 78,251 lines match on client and server.
  • End to end: All fixes of this series (the five save PRs and the four structure-start PRs) merged onto main and run as a dedicated server, which pre-generated seed 12345, 4,096 chunks per dimension (radius 500 blocks), and the result was compared chunk by chunk with the same area from the pinned vanilla 26.3 server (compare.py, our own world-diff tool). Then the world was opened in Paper 26.3. Paper's log shows no exception and no skipped block entity. Saved with LootTable: 577 containers and 52 chest minecarts in the Overworld, 36 containers in the Nether. Vanilla has 687 / 59 / 40 over its larger saved area (it also keeps 3,476 proto chunks). No container is saved with pre-rolled items. In Paper, the bastion chest at -380 73 137 holds minecraft:chests/bastion_other. Before rebasing onto current main, I also checked this in game on Paper with a real client: opening that chest rolls its loot (an enchanted axe) and grants War Pigs.

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on 79c2991ab58c, against upstream/main at 57c5f8129, 3 min 40 s)

Check Result
Scope ✅ 6 files, +274 −72
Cargo.lock ✅ unchanged
Public tree ✅ (1 s)
Python tests ➖ no Python change
rustfmt ✅ (5 s)
clippy ✅ (29 s)
tests: horizon-client ✅ 1297 passed (3 min 3 s)
doc tests ✅ 0 passed (2 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 324 affected, to run in CI (--quick): arrow, attribute_map_queries, auto_jump, biome_source_codec, biome_temperature, biome_weather, biome_zoom, block_blob, block_collision_scan, block_column, block_entity_anim, block_entity_render and 312 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 Generated with Claude Code

🤖 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/2288 **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:** `carry/2073-keep-loot-tables` --- ### 📝 Commits (2) - [`fc0b739`](https://github.com/horizon-rust/horizon/commit/fc0b73954f28fe022b0f9ac4ace3392118469108) x - [`bf39e5d`](https://github.com/horizon-rust/horizon/commit/bf39e5d49ea200f2c5e2b946f5f7bc3c71ea2219) Merge main (save.rs: keep both new tests; the loot test encodes with LevelShape::OVERWORLD after #2070) ### 📊 Changes **6 files changed** (+280 additions, -72 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/fishing.rs` (+1 -1) 📝 `crates/horizon-client/src/game/minecarts.rs` (+10 -0) 📝 `crates/horizon-client/src/game/persist.rs` (+26 -1) 📝 `crates/horizon-client/src/save.rs` (+151 -2) 📝 `crates/horizon-client/src/structure_blocks.rs` (+86 -63) 📝 `crates/horizon-client/src/vanillagen.rs` (+6 -5) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. **This carries @FusselTV's #2073 unchanged, plus one merge of main.** After #2070 merged, #2073 conflicted in `save.rs` (both added a test at the same place), and its loot test had to call `encode_with` with `LevelShape::OVERWORLD`. GitHub doesn't let maintainers push to a fork owned by an organization (RoyalPixelsDE), so the merge lives on this branch. FusselTV's commit keeps its author, and the merger lands it with a merge commit. The merge keeps both tests. `save::tests` passes 26/26, including `unopened_rolled_containers_save_their_loot_table` and `nether_and_end_chunks_save_with_their_own_height`. Gate evidence from #2073: seeded chests roll the same items as vanilla 26.3, 48/48 on the server thread and in-frame. `save_roundtrip`, `world_reopen`, `chunk_generation`, `structure_start_nbt`, `structure_blocks`, `structure_layout`, `trial_spawner` and `vault` pass on an integration tree with the whole save series. A vanilla save of a generated world round-trips through Horizon back to vanilla. Closes #2073 once merged. --- FusselTV's original description: > (#2073) Opened by FusselTV's AI agent (Claude Code, Opus 5.5), not by FusselTV personally. ## What and why Horizon rolls a generated container's loot table when it makes the chunk, and the save wrote the rolled `Items`. Vanilla keeps `LootTable` and `LootTableSeed` until a player first opens the container (`RandomizableContainer.unpackLootTable`). A world pre-generated by Horizon and then opened in vanilla or Paper therefore had: - loot that vanilla never rolls for that seed and position, - no loot table to unpack, so the loot advancements cannot fire (War Pigs, and every "loot a chest in X" check that keys on the table), - plugins that react to loot generation never called. The other direction was broken too. A vanilla-made world opened in Horizon has containers with a `LootTable` and no `Items`, and Horizon showed them empty. What changes: - A generated container whose items are still exactly the roll is saved as its `LootTable` and seed again (`RolledLoot::restore`). Once its items change, the items are saved instead and the table is dropped, as `unpackLootTable` does. - A loaded container with a `LootTable` and no items is rolled on load the same way, and is saved as its table again while it is untouched. - A container that was loaded with a table, rolled and then changed loses the table. Without that, a chest emptied after a load would fill up again on the next load. - Chest minecarts (mineshafts) keep their table from generation and are rolled when the game loads them. This replaces `unpack_entity_loot`. - A zero `LootTableSeed` is not written, as `trySaveLootTable` leaves it out. - Rolled items keep what #1911 added: enchantments, potions and an ominous bottle's level (`loot_item_with_components`). `LootTable.fill` uses the container's own size instead of 27. ## Vanilla reference - `RandomizableContainer.tryLoadLootTable` / `trySaveLootTable` / `unpackLootTable` - `ContainerEntity.addChestVehicleSaveData` / `readChestVehicleSaveData` / `unpackChestVehicleLootTable` - `LootTable.fill` ## Tests - New unit test `save::tests::unopened_rolled_containers_save_their_loot_table`. An untouched rolled chest saves `LootTable` and seed with no `Items`, and a changed chest saves `Items` with no table. A chest loaded with a table, then emptied, saves no table. A negative control confirmed that last part: with the fix removed, the test fails with `assertion failed: emptied.get("LootTable").is_none()`. - New unit test `structure_blocks::tests::a_container_rolled_without_loot_data_saves_its_table`. - `tools/test_block_entity_storage_parity.py` passed on this branch: 78,251 lines match on client and server. - End to end: All fixes of this series (the five save PRs and the four structure-start PRs) merged onto `main` and run as a dedicated server, which pre-generated seed 12345, 4,096 chunks per dimension (radius 500 blocks), and the result was compared chunk by chunk with the same area from the pinned vanilla 26.3 server (`compare.py`, our own world-diff tool). Then the world was opened in Paper 26.3. Paper's log shows no exception and no skipped block entity. Saved with `LootTable`: 577 containers and 52 chest minecarts in the Overworld, 36 containers in the Nether. Vanilla has 687 / 59 / 40 over its larger saved area (it also keeps 3,476 proto chunks). No container is saved with pre-rolled items. In Paper, the bastion chest at -380 73 137 holds `minecraft:chests/bastion_other`. Before rebasing onto current `main`, I also checked this in game on Paper with a real client: opening that chest rolls its loot (an enchanted axe) and grants War Pigs. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on 79c2991ab58c, against upstream/main at 57c5f8129, 3 min 40 s) | Check | Result | | --- | --- | | Scope | ✅ 6 files, +274 −72 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ (1 s) | | Python tests | ➖ no Python change | | rustfmt | ✅ (5 s) | | clippy | ✅ (29 s) | | tests: horizon-client | ✅ 1297 passed (3 min 3 s) | | doc tests | ✅ 0 passed (2 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 324 affected, to run in CI (--quick): arrow, attribute_map_queries, auto_jump, biome_source_codec, biome_temperature, biome_weather, biome_zoom, block_blob, block_collision_scan, block_column, block_entity_anim, block_entity_render and 312 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) 🤖 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:15 +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#4177
No description provided.