From f94aa2a3d6818a40300e37f8869c4acdd311708f Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 12 Oct 2026 14:28:40 +0200 Subject: [PATCH] Assemble /place jigsaw pieces from the generation context's random JigsawPlacement.generateJigsaw builds the pieces with the GenerationContext's WorldgenRandom (large feature seed from the level seed and the position's chunk) and only places them with the level random. Horizon assembled them from the level random, so the village layout, and the plants /fill later broke around it, changed from run to run. Co-Authored-By: Claude Opus 5.5 --- .../horizon-client/src/game/commands/place.rs | 4 +--- crates/horizon-client/src/vanillagen.rs | 5 ++--- crates/horizon-world/src/level/growth.rs | 19 +++++++---------- .../horizon-world/src/worldgen/generator.rs | 21 +++++++++---------- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/crates/horizon-client/src/game/commands/place.rs b/crates/horizon-client/src/game/commands/place.rs index 2d9140782..502cb53f4 100644 --- a/crates/horizon-client/src/game/commands/place.rs +++ b/crates/horizon-client/src/game/commands/place.rs @@ -157,9 +157,7 @@ impl Game<'_> { position: pos, }; let placed = self.with_level(|b, level, ticks| { - b.place_jigsaw(level, ticks, pos, |random| { - terrain.jigsaw_pieces(&query, random) - }) + b.place_jigsaw(level, ticks, pos, || terrain.jigsaw_pieces(&query)) }); self.process_level_events() .map_err(|_| err("command.failed", &[]))?; diff --git a/crates/horizon-client/src/vanillagen.rs b/crates/horizon-client/src/vanillagen.rs index 6b4b7c769..14f432fa3 100644 --- a/crates/horizon-client/src/vanillagen.rs +++ b/crates/horizon-client/src/vanillagen.rs @@ -100,15 +100,14 @@ impl VanillaTerrain { let worker = worker.get_or_insert_with(|| self.generator.worker()); worker.find_closest_biome(search) } - /// `/place jigsaw`: `JigsawPlacement.addPieces` drawing from `random`. + /// `/place jigsaw`: `JigsawPlacement.addPieces`. pub fn jigsaw_pieces( &self, query: &horizon_world::worldgen::generator::JigsawQuery<'_>, - random: &mut horizon_core::random::LegacyRandom, ) -> Option { let mut worker = self.query.lock().unwrap_or_else(|e| e.into_inner()); let worker = worker.get_or_insert_with(|| self.generator.worker()); - worker.jigsaw_pieces(query, random) + worker.jigsaw_pieces(query) } /// Concentric ring positions of a structure set (strongholds), once known. pub fn ring_positions(&self, set: &str) -> Option> { diff --git a/crates/horizon-world/src/level/growth.rs b/crates/horizon-world/src/level/growth.rs index 32e8474b0..91d0a1a12 100644 --- a/crates/horizon-world/src/level/growth.rs +++ b/crates/horizon-world/src/level/growth.rs @@ -21,28 +21,25 @@ impl Behaviours { pub fn live_features(&self) -> Option<&Arc> { self.growth.features.get() } - /// `JigsawPlacement.generateJigsaw`: `assemble` builds the pieces from - /// the level random, then each piece is placed into the level with an - /// unbounded box and `reference` as the origin. Returns whether pieces - /// were assembled. + /// `JigsawPlacement.generateJigsaw`: `assemble` builds the pieces (from + /// the generation context's own random), then each piece is placed into + /// the level with the level random, an unbounded box and `reference` as + /// the origin. Returns whether pieces were assembled. pub fn place_jigsaw( &self, level: &mut L, ticks: &mut super::Ticks, reference: [i32; 3], - assemble: impl FnOnce( - &mut horizon_core::random::LegacyRandom, - ) -> Option, + assemble: impl FnOnce() -> Option, ) -> bool { let Some(features) = self.live_features() else { return false; }; - let mut sim = self.sim(level, ticks); - let mut random = sim.random().clone(); - let Some(jigsaw) = assemble(&mut random) else { - *sim.random() = random; + let Some(jigsaw) = assemble() else { return false; }; + let mut sim = self.sim(level, ticks); + let mut random = sim.random().clone(); { let mut world = LevelFeatureWorld { sim: &mut sim, diff --git a/crates/horizon-world/src/worldgen/generator.rs b/crates/horizon-world/src/worldgen/generator.rs index 81000b1d1..8885b7f50 100644 --- a/crates/horizon-world/src/worldgen/generator.rs +++ b/crates/horizon-world/src/worldgen/generator.rs @@ -1379,7 +1379,6 @@ trait SeededPipeline: Send + Sync { &self, worker: &mut WorkerState, query: &JigsawQuery<'_>, - random: &mut horizon_core::random::LegacyRandom, ) -> Option; } impl SeededPipeline for Pipeline @@ -1526,12 +1525,15 @@ where &self, worker: &mut WorkerState, query: &JigsawQuery<'_>, - random: &mut horizon_core::random::LegacyRandom, ) -> Option { // JigsawPlacement.generateJigsaw: addPieces with no heightmap // projection, MaxDistance(128), no aliases, no padding and - // waterlogging applied. + // waterlogging applied. The pieces draw from the GenerationContext's + // random, seeded from the level seed and the position's chunk, not + // from the level random. let structures = self.structures.as_ref()?; + let mut random = horizon_core::random::WorldgenRandom::new(LegacyRandom::new(0)); + random.set_large_feature_seed(self.seed, query.position[0] >> 4, query.position[2] >> 4); let aliases = BTreeMap::new(); let config = super::structure::jigsaw::JigsawConfig { start_pool: query.pool, @@ -1554,7 +1556,7 @@ where &structures.registry.pools, &structures.resources, &structures.bindings, - random, + &mut random, query.position, )?; Some(JigsawPieces { @@ -1791,13 +1793,10 @@ impl GeneratorWorker { pub fn find_closest_biome(&mut self, search: &BiomeSearch<'_>) -> Option<(String, [i32; 3])> { self.pipeline.find_closest_biome(&mut self.state, search) } - /// `JigsawPlacement.addPieces` for `/place jigsaw`, drawing from `random`. - pub fn jigsaw_pieces( - &mut self, - query: &JigsawQuery<'_>, - random: &mut horizon_core::random::LegacyRandom, - ) -> Option { - self.pipeline.jigsaw_pieces(&mut self.state, query, random) + /// `JigsawPlacement.addPieces` for `/place jigsaw`, drawing from the + /// generation context's random (level seed and the position's chunk). + pub fn jigsaw_pieces(&mut self, query: &JigsawQuery<'_>) -> Option { + self.pipeline.jigsaw_pieces(&mut self.state, query) } /// STRUCTURE_STARTS: the structure starts owned by a chunk (cached). pub fn structure_starts(