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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-12 14:28:40 +02:00
parent 42c2e96082
commit f94aa2a3d6
4 changed files with 21 additions and 28 deletions
@@ -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", &[]))?;
+2 -3
View File
@@ -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<horizon_world::worldgen::generator::JigsawPieces> {
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<Vec<ChunkPos>> {
+8 -11
View File
@@ -21,28 +21,25 @@ impl Behaviours {
pub fn live_features(&self) -> Option<&Arc<LiveFeatures>> {
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<L: LevelAccess + ?Sized>(
&self,
level: &mut L,
ticks: &mut super::Ticks,
reference: [i32; 3],
assemble: impl FnOnce(
&mut horizon_core::random::LegacyRandom,
) -> Option<crate::worldgen::generator::JigsawPieces>,
assemble: impl FnOnce() -> Option<crate::worldgen::generator::JigsawPieces>,
) -> 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,
+10 -11
View File
@@ -1379,7 +1379,6 @@ trait SeededPipeline: Send + Sync {
&self,
worker: &mut WorkerState,
query: &JigsawQuery<'_>,
random: &mut horizon_core::random::LegacyRandom,
) -> Option<JigsawPieces>;
}
impl<R: RandomSource + 'static> SeededPipeline for Pipeline<R>
@@ -1526,12 +1525,15 @@ where
&self,
worker: &mut WorkerState,
query: &JigsawQuery<'_>,
random: &mut horizon_core::random::LegacyRandom,
) -> Option<JigsawPieces> {
// 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<JigsawPieces> {
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<JigsawPieces> {
self.pipeline.jigsaw_pieces(&mut self.state, query)
}
/// STRUCTURE_STARTS: the structure starts owned by a chunk (cached).
pub fn structure_starts(