[PR #2437] [MERGED] Worldgen: finalize structure mobs at placement, as vanilla #4315

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

📋 Pull Request Information

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

Base: main ← Head: fix/structure-mob-finalize


📝 Commits (1)

  • 266c7a2 Worldgen: finalize structure mobs at placement, as vanilla

📊 Changes

11 files changed (+698 additions, -20 deletions)

View changed files

📝 crates/horizon-client/src/entity_nbt.rs (+148 -6)
📝 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/vanillagen.rs (+15 -1)
➕ crates/horizon-client/src/vanillagen/structure_mobs.rs (+446 -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

Vanilla finalizes a structure's mobs while it places them. StructureTemplate.placeEntities and the pieces' data markers call finalizeSpawn(level, difficulty, STRUCTURE, null) inside the WorldGenRegion, which draws from the region random. So a structure's mobs come out the same for every run of a seed. Two vanilla runs agree on every piglin's weapon, armour, handedness, follow range bonus and baby state.

Horizon tagged these entities horizon:finalize and finalized them when their chunk's entities were first loaded, through the reduced spawning::finalize:

  • no spawn reason, so a bastion's crossbow piglin was given a new weapon,
  • no Mob.finalizeSpawn step, so no follow range bonus and no left-handed mobs,
  • no hoglin babies,
  • no piglin hunted_recently and no brute home memories,
  • no drowned jockeys: vanilla's ocean ruins put a trident drowned on a zombie nautilus, or a baby drowned on a chicken,
  • drawn from each mob's own random, so not the same for a seed.

The save path also wrote over the template's raw compound. It dropped Invulnerable when false, wrote no LeftHanded, gave hoglins no AgeLocked, and kept legacy template keys vanilla never writes (HandItems, ArmorItems, Dimension, HurtByTimestamp, CannotHunt).

What changes:

  • horizon-world gets a StructureMobs hook that the game installs in each generator worker. Decoration's add_entity calls it for every entity placed with horizon:finalize, with:
    • the region random in placement order,
    • the biome at the mob's block,
    • the structures with a piece there.
  • vanillagen/structure_mobs.rs runs the existing vanilla-accurate mobs::finalize with Reason::Structure. Difficulty is the level's, with 0 inhabited time. A jockey's vehicle becomes the saved entity, with the rider in Passengers.
  • If the hook cannot finalize (missing mob data, an unknown random), the tag stays and the game finalizes the mob when it loads, as before. This also covers worlds saved before this change.
  • entity_nbt writes what vanilla's save chain writes for these mobs:
    • Invulnerable and LeftHanded,
    • IsBaby for the zombie family, piglin and zoglin,
    • hoglin Age, AgeLocked and ForcedAge,
    • the finalized attributes,
    • piglin and brute memories.
      It drops the legacy template keys.

Vanilla reference

  • StructureTemplate.placeEntities, OceanRuinPieces.OceanRuinPiece.handleDataMarker
  • WorldGenRegion.getRandom / getCurrentDifficultyAt
  • Mob.finalizeSpawn, Piglin.finalizeSpawn, PiglinBrute.finalizeSpawn, Hoglin.finalizeSpawn, Zombie.finalizeSpawn, Drowned.finalizeSpawn
  • Entity.saveWithoutId, LivingEntity / Mob / AgeableMob / AbstractPiglin / Piglin / Zombie / Hoglin.addAdditionalSaveData

Tests

  • New tests in vanillagen/structure_mobs.rs, run with the prepared data:
    • bastion_crossbow_piglin_finalizes_as_structure: the template's crossbow piglin keeps its crossbow and saves vanilla's key set.
    • bastion_chunk_mobs_match_vanilla (seed 12345, Nether, chunk (-23, 8)): all 9 mobs match two vanilla runs in weapons, golden armour, follow range bonus, handedness and baby state.
    • ocean_ruin_drowned_match_vanilla (seed 12345, Overworld, chunk (3, 26)): 4 drowned, and a zombie nautilus carrying the trident drowned, as in vanilla.
  • Negative control: with the hook and the save changes reverted, all three fail.
  • tools/test_decorated_region_parity.py could not take entities: its probe lives in horizon-world and cannot run the game-side hook.
  • Not vanilla-exact yet:
    • The attributes vanilla saves beyond the ones finalize sets (movement_speed and others) are not written.
    • Natural spawns, spawners and raids still use spawning::finalize.

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on 1d1e54d38d4c, against upstream/main at 68db8847e, 5 min 7 s)

Check Result
Scope ⚠️ 11 files, +698 −20; 718 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (7 s)
clippy ✅ (25 s)
tests: horizon-client, horizon-world ✅ 1580 passed (4 min 29 s)
doc tests ✅ 0 passed (3 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 333 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 321 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/2437 **Author:** [@FusselTV](https://github.com/FusselTV) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/27/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/structure-mob-finalize` --- ### 📝 Commits (1) - [`266c7a2`](https://github.com/horizon-rust/horizon/commit/266c7a2cd92116965fd379884591ddab373b3f46) Worldgen: finalize structure mobs at placement, as vanilla ### 📊 Changes **11 files changed** (+698 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/entity_nbt.rs` (+148 -6) 📝 `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/vanillagen.rs` (+15 -1) ➕ `crates/horizon-client/src/vanillagen/structure_mobs.rs` (+446 -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 Vanilla finalizes a structure's mobs while it places them. `StructureTemplate.placeEntities` and the pieces' data markers call `finalizeSpawn(level, difficulty, STRUCTURE, null)` inside the `WorldGenRegion`, which draws from the region random. So a structure's mobs come out the same for every run of a seed. Two vanilla runs agree on every piglin's weapon, armour, handedness, follow range bonus and baby state. Horizon tagged these entities `horizon:finalize` and finalized them when their chunk's entities were first loaded, through the reduced `spawning::finalize`: - no spawn reason, so a bastion's crossbow piglin was given a new weapon, - no `Mob.finalizeSpawn` step, so no follow range bonus and no left-handed mobs, - no hoglin babies, - no piglin `hunted_recently` and no brute `home` memories, - no drowned jockeys: vanilla's ocean ruins put a trident drowned on a zombie nautilus, or a baby drowned on a chicken, - drawn from each mob's own random, so not the same for a seed. The save path also wrote over the template's raw compound. It dropped `Invulnerable` when false, wrote no `LeftHanded`, gave hoglins no `AgeLocked`, and kept legacy template keys vanilla never writes (`HandItems`, `ArmorItems`, `Dimension`, `HurtByTimestamp`, `CannotHunt`). What changes: - `horizon-world` gets a `StructureMobs` hook that the game installs in each generator worker. Decoration's `add_entity` calls it for every entity placed with `horizon:finalize`, with: - the region random in placement order, - the biome at the mob's block, - the structures with a piece there. - `vanillagen/structure_mobs.rs` runs the existing vanilla-accurate `mobs::finalize` with `Reason::Structure`. Difficulty is the level's, with 0 inhabited time. A jockey's vehicle becomes the saved entity, with the rider in `Passengers`. - If the hook cannot finalize (missing mob data, an unknown random), the tag stays and the game finalizes the mob when it loads, as before. This also covers worlds saved before this change. - `entity_nbt` writes what vanilla's save chain writes for these mobs: - `Invulnerable` and `LeftHanded`, - `IsBaby` for the zombie family, piglin and zoglin, - hoglin `Age`, `AgeLocked` and `ForcedAge`, - the finalized attributes, - piglin and brute memories. It drops the legacy template keys. ## Vanilla reference - `StructureTemplate.placeEntities`, `OceanRuinPieces.OceanRuinPiece.handleDataMarker` - `WorldGenRegion.getRandom` / `getCurrentDifficultyAt` - `Mob.finalizeSpawn`, `Piglin.finalizeSpawn`, `PiglinBrute.finalizeSpawn`, `Hoglin.finalizeSpawn`, `Zombie.finalizeSpawn`, `Drowned.finalizeSpawn` - `Entity.saveWithoutId`, `LivingEntity` / `Mob` / `AgeableMob` / `AbstractPiglin` / `Piglin` / `Zombie` / `Hoglin.addAdditionalSaveData` ## Tests - New tests in `vanillagen/structure_mobs.rs`, run with the prepared data: - `bastion_crossbow_piglin_finalizes_as_structure`: the template's crossbow piglin keeps its crossbow and saves vanilla's key set. - `bastion_chunk_mobs_match_vanilla` (seed 12345, Nether, chunk (-23, 8)): all 9 mobs match two vanilla runs in weapons, golden armour, follow range bonus, handedness and baby state. - `ocean_ruin_drowned_match_vanilla` (seed 12345, Overworld, chunk (3, 26)): 4 drowned, and a zombie nautilus carrying the trident drowned, as in vanilla. - Negative control: with the hook and the save changes reverted, all three fail. - `tools/test_decorated_region_parity.py` could not take entities: its probe lives in `horizon-world` and cannot run the game-side hook. - Not vanilla-exact yet: - The attributes vanilla saves beyond the ones finalize sets (`movement_speed` and others) are not written. - Natural spawns, spawners and raids still use `spawning::finalize`. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on 1d1e54d38d4c, against upstream/main at 68db8847e, 5 min 7 s) | Check | Result | | --- | --- | | Scope | ⚠️ 11 files, +698 −20; 718 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (7 s) | | clippy | ✅ (25 s) | | tests: horizon-client, horizon-world | ✅ 1580 passed (4 min 29 s) | | doc tests | ✅ 0 passed (3 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 333 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 321 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: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#4315
No description provided.