[PR #146] [MERGED] Monster spawners spawn, spin their mob and take spawn eggs #2351

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

📋 Pull Request Information

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

Base: main ← Head: fix/spawners-95


📝 Commits (1)

  • 79e04e2 Monster spawners spawn, spin their mob and take spawn eggs

📊 Changes

22 files changed (+1939 additions, -67 deletions)

View changed files

📝 crates/horizon-client/examples/natural_spawn_fixture.rs (+153 -8)
📝 crates/horizon-client/src/containers.rs (+9 -3)
📝 crates/horizon-client/src/game.rs (+26 -4)
📝 crates/horizon-client/src/game/creatures.rs (+18 -0)
📝 crates/horizon-client/src/game/dispense_fixture.rs (+36 -0)
📝 crates/horizon-client/src/game/lan.rs (+19 -0)
📝 crates/horizon-client/src/game/natural_spawning.rs (+53 -1)
📝 crates/horizon-client/src/game/persist.rs (+1 -1)
➕ crates/horizon-client/src/game/spawner.rs (+414 -0)
📝 crates/horizon-client/src/lan/chunks.rs (+1 -34)
📝 crates/horizon-client/src/lan/containers.rs (+22 -0)
📝 crates/horizon-client/src/mobs.rs (+1 -0)
📝 crates/horizon-client/src/mobs/render.rs (+33 -5)
📝 crates/horizon-client/src/mobs/spawn_selection.rs (+2 -2)
➕ crates/horizon-client/src/mobs/spawner.rs (+740 -0)
📝 crates/horizon-client/src/save.rs (+2 -0)
📝 crates/horizon-client/src/structure_blocks.rs (+4 -0)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaBlockUpdateOracle.java (+3 -0)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaDispenserOracle.java (+30 -0)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaNaturalSpawnOracle.java (+73 -2)

...and 2 more files

📄 Description

What was wrong

Monster spawners did nothing. Horizon kept a spawner's block entity only as the NBT it was loaded with and never ticked it, and a spawner in a freshly generated dungeon, mineshaft or fortress lost even that (BlockEntity::for_block had no spawner, so the generated SpawnData was dropped). No mob ever spawned, nothing turned inside the cage, and a spawn egg used on a spawner spawned a mob on top of it instead of setting the spawner's mob.

What vanilla does

  • SpawnerBlockEntity / BaseSpawner: load/save with SpawnData.CODEC (ids normalised by Identifier.CODEC, custom_spawn_rules as InclusiveRange.INT light limits, weighted SpawnPotentials; when the potentials are missing the next data is the one potential, so changing it changes the potential).
  • serverTick: hasNearbyAlivePlayer within RequiredPlayerRange (any distance when negative), isSpawnerBlockEnabled (spawner_blocks_work), the -1 delay, the countdown, getOrCreateNextSpawnData, then SpawnCount attempts: EntityType.by, Pos or a random point (nextDouble - nextDouble, nextInt(3)), noCollision(getSpawnAABB) (living shulkers are solid), custom light rules and peaceful or SpawnPlacements.checkSpawnRules(SPAWNER), the MaxNearbyEntities cap over the exact class, the yaw, Mob.checkSpawnRules and checkSpawnObstruction, finalizeSpawn when the data is an id alone, then levelEvent(2004), ENTITY_PLACE and spawnAnim (entity event 20); delay() draws the next delay and potential (WeightedList.getRandom) and sends block event 1.
  • clientTick: the client copy's own delay drives the spin and puffs smoke and flame; SpawnerRenderer draws the next mob at 0.53125 scale (divided by its largest dimension), turned by the spin and tilted 30°.
  • SpawnEggItem.useOn on a Spawner: EntityType.canSpawn (no monsters in peaceful), advMode.notEnabled.spawner when the rule is off, otherwise setEntityId/setEntityData, sendBlockUpdated, BLOCK_CHANGE, shrink (kept in creative) and the used statistic.
  • SpawnerBlock.spawnAfterBreak: 15 + nextInt(15) + nextInt(15) experience, silk touch or not.

The fix

  • mobs::spawner: the spawner's state, codecs, server tick (through a SpawnerLevel the game and the harness both implement, reusing spawn_selection's checkSpawnRules/obstruction code), client tick and render pose.
  • BlockEntity::Spawner, saved and loaded with the chunk, loaded from generated structures, ticked every tick; spawned mobs go through the game's spawn path (finalizeSpawn, gear, jockeys) or are loaded from configured spawn data.
  • Spawn eggs on spawners, the 2004 burst, the poof, the spinning mob (render_posed), spawner break experience, and the update tag / block event / entity event for LAN guests.

How it was tested

  • New tools/test_spawner_parity.py: vanilla's real SpawnerBlockEntity.serverTick on the natural-spawn oracle's stand-in level (new spawner mode) against mobs::spawner in natural_spawn_fixture on the same worlds — dungeons, caves, fields, flooded rooms, nether halls, light levels, players in and out of range, spectators, caps, every difficulty, the game rule, generated/loaded/weighted/custom-rule/Pos/configured/invalid spawn data, edge delays, counts and ranges. Every spawn's exact position and yaw bits, every event and the final level random are compared: 6,000 / 6,000 cases match (1,344 spawns, 5,563 delays, 3,941 block updates).
  • tools/test_use_item_on_parity.py now also uses spawn eggs (and other items) on spawners through the real ServerPlayerGameMode.useItemOn: 4,000 / 4,000 (≈600 spawner cases, with the game rule off and the system message).
  • tools/test_natural_spawn_parity.py still matches (15,500 / 15,500), tools/test_dispenser_parity.py 6,000 / 6,000.
  • cargo fmt --check, cargo clippy --workspace --all-targets -D warnings, cargo test --workspace (with new mobs::spawner unit tests), python -m unittest discover -s tests, tools/check_public_tree.py --history.

finalizeSpawn itself still goes through the game's existing finalize path (as natural spawning does); the oracle runs it with a fixed random and its outcomes are not compared.

Fixes #95

🤖 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/146 **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/spawners-95` --- ### 📝 Commits (1) - [`79e04e2`](https://github.com/horizon-rust/horizon/commit/79e04e22d6b5f52270740bab857335f37838d0f1) Monster spawners spawn, spin their mob and take spawn eggs ### 📊 Changes **22 files changed** (+1939 additions, -67 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/natural_spawn_fixture.rs` (+153 -8) 📝 `crates/horizon-client/src/containers.rs` (+9 -3) 📝 `crates/horizon-client/src/game.rs` (+26 -4) 📝 `crates/horizon-client/src/game/creatures.rs` (+18 -0) 📝 `crates/horizon-client/src/game/dispense_fixture.rs` (+36 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+19 -0) 📝 `crates/horizon-client/src/game/natural_spawning.rs` (+53 -1) 📝 `crates/horizon-client/src/game/persist.rs` (+1 -1) ➕ `crates/horizon-client/src/game/spawner.rs` (+414 -0) 📝 `crates/horizon-client/src/lan/chunks.rs` (+1 -34) 📝 `crates/horizon-client/src/lan/containers.rs` (+22 -0) 📝 `crates/horizon-client/src/mobs.rs` (+1 -0) 📝 `crates/horizon-client/src/mobs/render.rs` (+33 -5) 📝 `crates/horizon-client/src/mobs/spawn_selection.rs` (+2 -2) ➕ `crates/horizon-client/src/mobs/spawner.rs` (+740 -0) 📝 `crates/horizon-client/src/save.rs` (+2 -0) 📝 `crates/horizon-client/src/structure_blocks.rs` (+4 -0) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaBlockUpdateOracle.java` (+3 -0) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaDispenserOracle.java` (+30 -0) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaNaturalSpawnOracle.java` (+73 -2) _...and 2 more files_ </details> ### 📄 Description ## What was wrong Monster spawners did nothing. Horizon kept a spawner's block entity only as the NBT it was loaded with and never ticked it, and a spawner in a freshly generated dungeon, mineshaft or fortress lost even that (`BlockEntity::for_block` had no spawner, so the generated `SpawnData` was dropped). No mob ever spawned, nothing turned inside the cage, and a spawn egg used on a spawner spawned a mob on top of it instead of setting the spawner's mob. ## What vanilla does - `SpawnerBlockEntity` / `BaseSpawner`: `load`/`save` with `SpawnData.CODEC` (ids normalised by `Identifier.CODEC`, `custom_spawn_rules` as `InclusiveRange.INT` light limits, weighted `SpawnPotentials`; when the potentials are missing the next data *is* the one potential, so changing it changes the potential). - `serverTick`: `hasNearbyAlivePlayer` within `RequiredPlayerRange` (any distance when negative), `isSpawnerBlockEnabled` (`spawner_blocks_work`), the `-1` delay, the countdown, `getOrCreateNextSpawnData`, then `SpawnCount` attempts: `EntityType.by`, `Pos` or a random point (`nextDouble - nextDouble`, `nextInt(3)`), `noCollision(getSpawnAABB)` (living shulkers are solid), custom light rules and peaceful or `SpawnPlacements.checkSpawnRules(SPAWNER)`, the `MaxNearbyEntities` cap over the exact class, the yaw, `Mob.checkSpawnRules` and `checkSpawnObstruction`, `finalizeSpawn` when the data is an id alone, then `levelEvent(2004)`, `ENTITY_PLACE` and `spawnAnim` (entity event 20); `delay()` draws the next delay and potential (`WeightedList.getRandom`) and sends block event 1. - `clientTick`: the client copy's own delay drives the spin and puffs smoke and flame; `SpawnerRenderer` draws the next mob at 0.53125 scale (divided by its largest dimension), turned by the spin and tilted 30°. - `SpawnEggItem.useOn` on a `Spawner`: `EntityType.canSpawn` (no monsters in peaceful), `advMode.notEnabled.spawner` when the rule is off, otherwise `setEntityId`/`setEntityData`, `sendBlockUpdated`, `BLOCK_CHANGE`, shrink (kept in creative) and the used statistic. - `SpawnerBlock.spawnAfterBreak`: `15 + nextInt(15) + nextInt(15)` experience, silk touch or not. ## The fix - `mobs::spawner`: the spawner's state, codecs, server tick (through a `SpawnerLevel` the game and the harness both implement, reusing `spawn_selection`'s `checkSpawnRules`/obstruction code), client tick and render pose. - `BlockEntity::Spawner`, saved and loaded with the chunk, loaded from generated structures, ticked every tick; spawned mobs go through the game's spawn path (`finalizeSpawn`, gear, jockeys) or are loaded from configured spawn data. - Spawn eggs on spawners, the 2004 burst, the poof, the spinning mob (`render_posed`), spawner break experience, and the update tag / block event / entity event for LAN guests. ## How it was tested - New `tools/test_spawner_parity.py`: vanilla's real `SpawnerBlockEntity.serverTick` on the natural-spawn oracle's stand-in level (new `spawner` mode) against `mobs::spawner` in `natural_spawn_fixture` on the same worlds — dungeons, caves, fields, flooded rooms, nether halls, light levels, players in and out of range, spectators, caps, every difficulty, the game rule, generated/loaded/weighted/custom-rule/`Pos`/configured/invalid spawn data, edge delays, counts and ranges. Every spawn's exact position and yaw bits, every event and the final level random are compared: **6,000 / 6,000 cases match** (1,344 spawns, 5,563 delays, 3,941 block updates). - `tools/test_use_item_on_parity.py` now also uses spawn eggs (and other items) on spawners through the real `ServerPlayerGameMode.useItemOn`: **4,000 / 4,000** (≈600 spawner cases, with the game rule off and the system message). - `tools/test_natural_spawn_parity.py` still matches (15,500 / 15,500), `tools/test_dispenser_parity.py` 6,000 / 6,000. - `cargo fmt --check`, `cargo clippy --workspace --all-targets -D warnings`, `cargo test --workspace` (with new `mobs::spawner` unit tests), `python -m unittest discover -s tests`, `tools/check_public_tree.py --history`. `finalizeSpawn` itself still goes through the game's existing finalize path (as natural spawning does); the oracle runs it with a fixed random and its outcomes are not compared. Fixes #95 🤖 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: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#2351
No description provided.