[PR #2544] [MERGED] Worldgen: structure mobs save the fields vanilla's chunk keeps #4414

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

📋 Pull Request Information

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

Base: main ← Head: fix/structure-entity-fields


📝 Commits (2)

  • 266c7a2 Worldgen: finalize structure mobs at placement, as vanilla
  • 1a80673 Worldgen: structure mobs save the fields vanilla's chunk keeps

📊 Changes

14 files changed (+815 additions, -43 deletions)

View changed files

📝 crates/horizon-client/examples/probe/finalize_spawn_fixture.rs (+1 -0)
📝 crates/horizon-client/src/entity_nbt.rs (+242 -16)
📝 crates/horizon-client/src/game.rs (+3 -0)
📝 crates/horizon-client/src/game/creatures.rs (+6 -0)
📝 crates/horizon-client/src/game/levels.rs (+1 -0)
📝 crates/horizon-client/src/game/persist.rs (+10 -2)
📝 crates/horizon-client/src/game/raids.rs (+1 -1)
📝 crates/horizon-client/src/mobs/finalize.rs (+5 -0)
📝 crates/horizon-client/src/mobs/nautilus.rs (+0 -13)
📝 crates/horizon-client/src/vanillagen.rs (+15 -1)
➕ crates/horizon-client/src/vanillagen/structure_mobs.rs (+463 -0)
📝 crates/horizon-world/src/worldgen/generator.rs (+20 -0)
📝 crates/horizon-world/src/worldgen/generator_decoration.rs (+42 -9)
📝 crates/horizon-world/src/worldgen/structure/legacy.rs (+6 -1)

📄 Description

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

What and why

Builds on #2437 (structure mobs finalized at placement); its commit is included here, so please review the last commit.

Vanilla's proto chunk saves a structure's entity as soon as it is placed (ProtoChunk.addEntity serialises it), and the chunk loads it again when it becomes full (ChunkStatusTasks.postLoadProtoChunk). So a generated world holds each entity exactly as its own save writes it. Horizon kept the template's NBT with its model written on top, and the model missed some fields. Compared with vanilla over seeds 12345, 1 and 8675309 (1,024 × 1,024 blocks):

  • villagers lacked VillagerDataFinalized and AgeLocked, and kept the template's food_level and lastRestock;
  • cats kept the template's CatType and an empty OwnerUUID;
  • iron golems lacked anger_end_time;
  • drowned lacked the movement_speed attribute and, with a nautilus shell, drop_chances;
  • zombie nautiluses had Age, ForcedAge and AgeLocked, which vanilla does not write for them;
  • the drowned riding a new chicken jockey had its full equipment and attributes, where vanilla's chunk holds it as it was when the chicken was added.

What changes:

  • Keys in vanilla's templates that no entity reads (food_level, lastRestock, CatType, OwnerUUID, Riches, Willing) are dropped from structure mobs.
  • Age, ForcedAge and AgeLocked are written and read for every AgeableMob that canBeABaby, not only the creature category. Villagers and hoglins keep their age across a reload; frogs, parrots and zombie nautiluses no longer get one. Tadpoles keep their own Age and AgeLocked.
  • Villagers save VillagerDataFinalized.
  • The neutral mobs other than the bee save anger_end_time (-1 unless the save had one).
  • Zombies and piglins save the movement_speed attribute their setBaby creates on load.
  • drop_chances is saved from the model when set, and read back.
  • A chicken jockey's rider made during generation is saved as it was when the chicken was added.

Vanilla reference

  • ProtoChunk.addEntity, ChunkStatusTasks.postLoadProtoChunk.
  • AgeableMob.addAdditionalSaveData (canBeABaby), Villager.addAdditionalSaveData, NeutralMob.addPersistentAngerSaveData.
  • Zombie.setBaby / Piglin.setBaby → getAttribute(MOVEMENT_SPEED); AttributeMap.pack.
  • Mob.addAdditionalSaveData / DropChances.CODEC.
  • Zombie.finalizeSpawn: level.addFreshEntity(chicken) before populateDefaultEquipmentSlots and handleAttributes.

Tests

  • New unit test entity_nbt::sheep_nbt_tests::a_baby_villager_keeps_its_age.
  • End to end over the same three seeds: the structure mobs (villagers, cats, iron golems, drowned, zombie nautiluses and their riders, chicken jockeys) now match vanilla field for field. What still differs is drawn from each entity's own random (random_spawn_bonus, spawn_reinforcements, EggLayTime), which differs between two vanilla runs too.

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on cf76e8b5595a, against upstream/main at cb43e3278, 8 min 27 s)

Check Result
Scope ⚠️ 14 files, +815 −43; 858 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 320 passed (30 s)
rustfmt ✅ (8 s)
clippy ✅ (1 min 15 s)
tests: horizon-client, horizon-world ✅ 1582 passed (5 min 53 s)
doc tests ✅ 0 passed (39 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 334 affected, to run in CI (--quick): arrow, attribute_map_queries, attribute_updates, auto_jump, bamboo, biome_source_codec, biome_temperature, biome_weather, biome_zoom, block_blob, block_collision_scan, block_column and 322 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/2544 **Author:** [@FusselTV](https://github.com/FusselTV) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/structure-entity-fields` --- ### 📝 Commits (2) - [`266c7a2`](https://github.com/horizon-rust/horizon/commit/266c7a2cd92116965fd379884591ddab373b3f46) Worldgen: finalize structure mobs at placement, as vanilla - [`1a80673`](https://github.com/horizon-rust/horizon/commit/1a80673d50561657398e977cdd4618b1011a5c07) Worldgen: structure mobs save the fields vanilla's chunk keeps ### 📊 Changes **14 files changed** (+815 additions, -43 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/probe/finalize_spawn_fixture.rs` (+1 -0) 📝 `crates/horizon-client/src/entity_nbt.rs` (+242 -16) 📝 `crates/horizon-client/src/game.rs` (+3 -0) 📝 `crates/horizon-client/src/game/creatures.rs` (+6 -0) 📝 `crates/horizon-client/src/game/levels.rs` (+1 -0) 📝 `crates/horizon-client/src/game/persist.rs` (+10 -2) 📝 `crates/horizon-client/src/game/raids.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs/finalize.rs` (+5 -0) 📝 `crates/horizon-client/src/mobs/nautilus.rs` (+0 -13) 📝 `crates/horizon-client/src/vanillagen.rs` (+15 -1) ➕ `crates/horizon-client/src/vanillagen/structure_mobs.rs` (+463 -0) 📝 `crates/horizon-world/src/worldgen/generator.rs` (+20 -0) 📝 `crates/horizon-world/src/worldgen/generator_decoration.rs` (+42 -9) 📝 `crates/horizon-world/src/worldgen/structure/legacy.rs` (+6 -1) </details> ### 📄 Description > 🤖 Opened by FusselTV's AI agent (Claude Code, Opus 5.5), not by FusselTV personally. ## What and why Builds on #2437 (structure mobs finalized at placement); its commit is included here, so please review the last commit. Vanilla's proto chunk saves a structure's entity as soon as it is placed (`ProtoChunk.addEntity` serialises it), and the chunk loads it again when it becomes full (`ChunkStatusTasks.postLoadProtoChunk`). So a generated world holds each entity exactly as its own save writes it. Horizon kept the template's NBT with its model written on top, and the model missed some fields. Compared with vanilla over seeds 12345, 1 and 8675309 (1,024 × 1,024 blocks): - villagers lacked `VillagerDataFinalized` and `AgeLocked`, and kept the template's `food_level` and `lastRestock`; - cats kept the template's `CatType` and an empty `OwnerUUID`; - iron golems lacked `anger_end_time`; - drowned lacked the `movement_speed` attribute and, with a nautilus shell, `drop_chances`; - zombie nautiluses had `Age`, `ForcedAge` and `AgeLocked`, which vanilla does not write for them; - the drowned riding a new chicken jockey had its full equipment and attributes, where vanilla's chunk holds it as it was when the chicken was added. What changes: - Keys in vanilla's templates that no entity reads (`food_level`, `lastRestock`, `CatType`, `OwnerUUID`, `Riches`, `Willing`) are dropped from structure mobs. - `Age`, `ForcedAge` and `AgeLocked` are written and read for every `AgeableMob` that `canBeABaby`, not only the creature category. Villagers and hoglins keep their age across a reload; frogs, parrots and zombie nautiluses no longer get one. Tadpoles keep their own `Age` and `AgeLocked`. - Villagers save `VillagerDataFinalized`. - The neutral mobs other than the bee save `anger_end_time` (-1 unless the save had one). - Zombies and piglins save the `movement_speed` attribute their `setBaby` creates on load. - `drop_chances` is saved from the model when set, and read back. - A chicken jockey's rider made during generation is saved as it was when the chicken was added. ## Vanilla reference - `ProtoChunk.addEntity`, `ChunkStatusTasks.postLoadProtoChunk`. - `AgeableMob.addAdditionalSaveData` (`canBeABaby`), `Villager.addAdditionalSaveData`, `NeutralMob.addPersistentAngerSaveData`. - `Zombie.setBaby` / `Piglin.setBaby` → `getAttribute(MOVEMENT_SPEED)`; `AttributeMap.pack`. - `Mob.addAdditionalSaveData` / `DropChances.CODEC`. - `Zombie.finalizeSpawn`: `level.addFreshEntity(chicken)` before `populateDefaultEquipmentSlots` and `handleAttributes`. ## Tests - New unit test `entity_nbt::sheep_nbt_tests::a_baby_villager_keeps_its_age`. - End to end over the same three seeds: the structure mobs (villagers, cats, iron golems, drowned, zombie nautiluses and their riders, chicken jockeys) now match vanilla field for field. What still differs is drawn from each entity's own random (`random_spawn_bonus`, `spawn_reinforcements`, `EggLayTime`), which differs between two vanilla runs too. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on cf76e8b5595a, against upstream/main at cb43e3278, 8 min 27 s) | Check | Result | | --- | --- | | Scope | ⚠️ 14 files, +815 −43; 858 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 320 passed (30 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (1 min 15 s) | | tests: horizon-client, horizon-world | ✅ 1582 passed (5 min 53 s) | | doc tests | ✅ 0 passed (39 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 334 affected, to run in CI (--quick): arrow, attribute_map_queries, attribute_updates, auto_jump, bamboo, biome_source_codec, biome_temperature, biome_weather, biome_zoom, block_blob, block_collision_scan, block_column and 322 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:16:58 +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#4414
No description provided.