[PR #116] [MERGED] Find a new world's spawn as vanilla does (NoiseSpawnFinder, setInitialSpawn, PlayerSpawnFinder) #2332

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

📋 Pull Request Information

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

Base: main ← Head: fix/world-spawn-seed


📝 Commits (1)

  • 7ace13c Find a new world's spawn as vanilla does

📊 Changes

13 files changed (+1022 additions, -61 deletions)

View changed files

📝 crates/horizon-client/src/collisions.rs (+15 -1)
📝 crates/horizon-client/src/flatgen.rs (+4 -0)
📝 crates/horizon-client/src/game.rs (+47 -59)
➕ crates/horizon-client/src/game/initial_spawn.rs (+217 -0)
📝 crates/horizon-client/src/lib.rs (+1 -0)
📝 crates/horizon-client/src/vanillagen.rs (+4 -0)
➕ crates/horizon-client/src/world_spawn.rs (+269 -0)
➕ crates/horizon-world/examples/spawn_origin.rs (+54 -0)
📝 crates/horizon-world/src/worldgen.rs (+1 -0)
📝 crates/horizon-world/src/worldgen/generator.rs (+52 -1)
➕ crates/horizon-world/src/worldgen/spawn_finder.rs (+128 -0)
➕ mods/horizon/src/test/java/dev/horizonlab/parity/VanillaWorldSpawnOracle.java (+61 -0)
➕ tools/test_world_spawn_parity.py (+169 -0)

📄 Description

What was wrong

A new world's spawn did not follow vanilla at all: Game::spawn_player searched its own square spiral of 48-block steps from 0 0 (spawn_candidate) for a dry, non-leaf top block. On seed 1891623539983467248 Horizon put the player at -48 -48; vanilla's world spawn is 144 71 144 (the player then lands within the 10-block respawn radius: 152 145 in the report).

What vanilla does

MinecraftServer.setInitialSpawn:

  1. Origin: NoiseBasedChunkGenerator.getOrigin runs NoiseSpawnFinder.findSpawnPosition over the noise settings' spawn_target points: each SpawnTargetPoint.sampleFitness sums squared Climate.Parameter.distances of the quantized density samples at the column's quart corner; fitness × 2048² + distance² to 0 0; a radial search out to 2048 in 512 steps, then out to 512 in 32 steps around the best. The chunk of the best column is the origin (ChunkGenerator.getOrigin is 0 0 without a target).
  2. World spawn: an 11 by 11 chunk spiral (Mth.square(11) steps) around the origin chunk; the first chunk where PlayerSpawnFinder.getSpawnPosInChunk finds a column (getLevelRespawnPos: MOTION_BLOCKING / WORLD_SURFACE / OCEAN_FLOOR heights, stop at liquid, a block whose collision shape has a full top face) gives the spawn; otherwise the origin chunk's centre at getSpawnHeight.
  3. First player: PlayerSpawnFinder.findSpawn (via PrepareSpawnTask): the respawn-radius square, clamped to the world border, visited in a random coprime-stride order (getCoprime); the first column with a respawn position and a free player box (noCollision(null, box, true), liquids colliding); else the spawn with fixupSpawnHeight. Adventure mode takes the spawn as is.

The change

  • horizon-world: worldgen::spawn_finder (NoiseSpawnFinder, SpawnTargetPoint) and OverworldGenerator::origin / spawn_position (the spawn_target decoded from the noise settings, samplers from the generator's own compiled densities, result cached).
  • horizon-client: world_spawn (setInitialSpawn's spiral, getLevelRespawnPos, getSpawnPosInChunk, PlayerSpawnFinder's candidate order, with unit tests) and game/initial_spawn.rs binding them to the loaded world; spawn_player uses them for a new world (single player and the dedicated server). Chunks are tested once lit (decorated with their neighbours), as vanilla tests FULL chunks. Flat worlds use FlatLevelSource's origin (0 0) and spawn height. collisions::no_collision_or_liquid is noCollision(null, box, true).
  • Saved positions and existing world spawns load as before.

How tested

tools/test_world_spawn_parity.py (new; Python driver + VanillaWorldSpawnOracle + spawn_origin example), run on the Mac mini:

  • Origins: vanilla's NoiseSpawnFinder.findSpawnPosition / getOrigin vs Horizon's for 60 seeds (the report's, the 9 seeds of the chunk generation harness, 50 random): 60/60 identical (column and chunk).
  • World spawns: worlds created by the pinned vanilla dedicated server and by horizon-client --dedicated --nogui with the same server.properties, spawn of both level.dat: 60/60. The report seed: vanilla 144 71 144 / Horizon 144 71 144.
  • Vanilla is not deterministic on some chunk corners: trees of neighbouring chunks overlap there and which is placed last follows its worldgen threads. On a mismatch the harness recreates the vanilla world up to 3 more times and passes only if vanilla also produces Horizon's spawn. 3 of 60 seeds varied in vanilla itself, e.g. 5882138163895760678: vanilla gave 0 70 0, 0 76 0 and 0 73 0 in successive runs (jungle leaves over oak leaves on the spawn column); Horizon gave 0 73 0. Same x z in every case.
  • cargo clippy --workspace --all-targets -D warnings clean; cargo test -p horizon-world --lib 84 passed, -p horizon-client --lib 397 passed; tools/check_public_tree.py passed.

🤖 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/116 **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/world-spawn-seed` --- ### 📝 Commits (1) - [`7ace13c`](https://github.com/horizon-rust/horizon/commit/7ace13cc821b621951e6747745fe05b437e7852d) Find a new world's spawn as vanilla does ### 📊 Changes **13 files changed** (+1022 additions, -61 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/collisions.rs` (+15 -1) 📝 `crates/horizon-client/src/flatgen.rs` (+4 -0) 📝 `crates/horizon-client/src/game.rs` (+47 -59) ➕ `crates/horizon-client/src/game/initial_spawn.rs` (+217 -0) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) 📝 `crates/horizon-client/src/vanillagen.rs` (+4 -0) ➕ `crates/horizon-client/src/world_spawn.rs` (+269 -0) ➕ `crates/horizon-world/examples/spawn_origin.rs` (+54 -0) 📝 `crates/horizon-world/src/worldgen.rs` (+1 -0) 📝 `crates/horizon-world/src/worldgen/generator.rs` (+52 -1) ➕ `crates/horizon-world/src/worldgen/spawn_finder.rs` (+128 -0) ➕ `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaWorldSpawnOracle.java` (+61 -0) ➕ `tools/test_world_spawn_parity.py` (+169 -0) </details> ### 📄 Description ## What was wrong A new world's spawn did not follow vanilla at all: `Game::spawn_player` searched its own square spiral of 48-block steps from 0 0 (`spawn_candidate`) for a dry, non-leaf top block. On seed **1891623539983467248** Horizon put the player at **-48 -48**; vanilla's world spawn is **144 71 144** (the player then lands within the 10-block respawn radius: 152 145 in the report). ## What vanilla does `MinecraftServer.setInitialSpawn`: 1. **Origin**: `NoiseBasedChunkGenerator.getOrigin` runs `NoiseSpawnFinder.findSpawnPosition` over the noise settings' `spawn_target` points: each `SpawnTargetPoint.sampleFitness` sums squared `Climate.Parameter.distance`s of the quantized density samples at the column's quart corner; fitness × 2048² + distance² to 0 0; a radial search out to 2048 in 512 steps, then out to 512 in 32 steps around the best. The chunk of the best column is the origin (`ChunkGenerator.getOrigin` is 0 0 without a target). 2. **World spawn**: an 11 by 11 chunk spiral (`Mth.square(11)` steps) around the origin chunk; the first chunk where `PlayerSpawnFinder.getSpawnPosInChunk` finds a column (`getLevelRespawnPos`: MOTION_BLOCKING / WORLD_SURFACE / OCEAN_FLOOR heights, stop at liquid, a block whose collision shape has a full top face) gives the spawn; otherwise the origin chunk's centre at `getSpawnHeight`. 3. **First player**: `PlayerSpawnFinder.findSpawn` (via `PrepareSpawnTask`): the respawn-radius square, clamped to the world border, visited in a random coprime-stride order (`getCoprime`); the first column with a respawn position and a free player box (`noCollision(null, box, true)`, liquids colliding); else the spawn with `fixupSpawnHeight`. Adventure mode takes the spawn as is. ## The change - `horizon-world`: `worldgen::spawn_finder` (NoiseSpawnFinder, SpawnTargetPoint) and `OverworldGenerator::origin` / `spawn_position` (the `spawn_target` decoded from the noise settings, samplers from the generator's own compiled densities, result cached). - `horizon-client`: `world_spawn` (setInitialSpawn's spiral, `getLevelRespawnPos`, `getSpawnPosInChunk`, PlayerSpawnFinder's candidate order, with unit tests) and `game/initial_spawn.rs` binding them to the loaded world; `spawn_player` uses them for a new world (single player and the dedicated server). Chunks are tested once lit (decorated with their neighbours), as vanilla tests FULL chunks. Flat worlds use FlatLevelSource's origin (0 0) and spawn height. `collisions::no_collision_or_liquid` is `noCollision(null, box, true)`. - Saved positions and existing world spawns load as before. ## How tested `tools/test_world_spawn_parity.py` (new; Python driver + `VanillaWorldSpawnOracle` + `spawn_origin` example), run on the Mac mini: - **Origins**: vanilla's `NoiseSpawnFinder.findSpawnPosition` / `getOrigin` vs Horizon's for 60 seeds (the report's, the 9 seeds of the chunk generation harness, 50 random): **60/60** identical (column and chunk). - **World spawns**: worlds created by the pinned vanilla dedicated server and by `horizon-client --dedicated --nogui` with the same server.properties, `spawn` of both level.dat: **60/60**. The report seed: vanilla 144 71 144 / Horizon 144 71 144. - Vanilla is not deterministic on some chunk corners: trees of neighbouring chunks overlap there and which is placed last follows its worldgen threads. On a mismatch the harness recreates the vanilla world up to 3 more times and passes only if vanilla also produces Horizon's spawn. 3 of 60 seeds varied in vanilla itself, e.g. 5882138163895760678: vanilla gave 0 70 0, 0 76 0 and 0 73 0 in successive runs (jungle leaves over oak leaves on the spawn column); Horizon gave 0 73 0. Same x z in every case. - `cargo clippy --workspace --all-targets -D warnings` clean; `cargo test -p horizon-world --lib` 84 passed, `-p horizon-client --lib` 397 passed; `tools/check_public_tree.py` passed. 🤖 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:02 +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#2332
No description provided.