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(