7ace13cc82
Horizon searched its own spiral of 48-block steps from 0 0 for a dry, non-leaf top block, so seed 1891623539983467248 spawned at -48 -48 where vanilla puts the world spawn at 144 71 144 (the player then lands within the respawn radius, 152 145 in the report). Vanilla (MinecraftServer.setInitialSpawn): NoiseBasedChunkGenerator. getOrigin runs NoiseSpawnFinder over the noise settings' spawn_target points (SpawnTargetPoint.sampleFitness, a 2048/512 then 512/32 radial search biased towards 0 0); an 11 by 11 chunk spiral around that chunk takes the first column PlayerSpawnFinder.getSpawnPosInChunk accepts (getLevelRespawnPos: MOTION_BLOCKING, WORLD_SURFACE and OCEAN_FLOOR heights, no liquid, a full-topped collision shape); without one, the origin chunk's centre at the spawn height. The first player is then placed by PlayerSpawnFinder.findSpawn: the respawn-radius square in a random coprime order, a free player box with liquids colliding, else the spawn with fixupSpawnHeight; adventure mode uses the spawn as is. horizon-world gains worldgen::spawn_finder and OverworldGenerator::origin; the client's world_spawn module and game/initial_spawn.rs follow setInitialSpawn and PlayerSpawnFinder, for single player and the dedicated server alike. Flat worlds use FlatLevelSource's origin and spawn height. tools/test_world_spawn_parity.py compares, for the report's seed, the chunk harness's seeds and 50 random ones, the origins (VanillaWorldSpawnOracle against the spawn_origin example) and the level.dat spawn of worlds created by the vanilla dedicated server and by Horizon's. Vanilla is not deterministic on chunk corners where trees of neighbouring chunks overlap (decoration order follows its worker threads), so a mismatching seed reruns vanilla up to three times. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
2.0 KiB
Rust
55 lines
2.0 KiB
Rust
//! NoiseSpawnFinder for tools/test_world_spawn_parity.py: for each seed, the
|
|
//! column the overworld's spawn search starts from and its chunk
|
|
//! (NoiseBasedChunkGenerator.getOrigin), as `seed x z chunk_x chunk_z` lines.
|
|
//!
|
|
//! usage: spawn_origin <client resource directory> <seed>...
|
|
use horizon_world::{
|
|
DATA_VERSION,
|
|
nbt::Tag,
|
|
registry::BlockRegistry,
|
|
worldgen::generator::{GeneratorData, OverworldGenerator},
|
|
};
|
|
use serde_json::Value;
|
|
use std::{fs, path::Path};
|
|
|
|
type Error = Box<dyn std::error::Error + Send + Sync>;
|
|
|
|
fn tag(v: &Value) -> Tag {
|
|
match v {
|
|
Value::String(s) => Tag::String(s.as_str().into()),
|
|
Value::Number(n) => Tag::Int(n.as_i64().unwrap() as i32),
|
|
Value::Array(a) => Tag::List(a.iter().map(tag).collect()),
|
|
Value::Object(o) => {
|
|
Tag::Compound(o.iter().map(|(k, v)| (k.as_str().into(), tag(v))).collect())
|
|
}
|
|
_ => panic!("invalid registry metadata"),
|
|
}
|
|
}
|
|
fn registry(resources: &Path) -> Result<&'static BlockRegistry, Error> {
|
|
let facts: Value = serde_json::from_str(&fs::read_to_string(resources.join("facts.json"))?)?;
|
|
let states = facts["states"].as_array().ok_or("facts states")?;
|
|
let registry = BlockRegistry::from_nbt(&Tag::compound([
|
|
("DataVersion", Tag::Int(DATA_VERSION)),
|
|
(
|
|
"states",
|
|
Tag::List(states.iter().map(|v| tag(&v[4])).collect()),
|
|
),
|
|
("defaults", tag(&facts["defaults"])),
|
|
]))?;
|
|
Ok(Box::leak(Box::new(registry)))
|
|
}
|
|
|
|
fn main() -> Result<(), Error> {
|
|
let mut args = std::env::args().skip(1);
|
|
let resources = std::path::PathBuf::from(args.next().ok_or("client resource directory")?);
|
|
let data = GeneratorData::load(&resources.join("worldgen"), registry(&resources)?)?;
|
|
for seed in args {
|
|
let seed: i64 = seed.parse()?;
|
|
let generator = OverworldGenerator::new(data.clone(), seed)?;
|
|
let [x, z] = generator.spawn_position()?;
|
|
let origin = generator.origin()?;
|
|
println!("{seed} {x} {z} {} {}", origin.x, origin.z);
|
|
}
|
|
Ok(())
|
|
}
|