From 6a543b8887b931d08181ab8805d12a23f2978700 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 8 Oct 2026 11:20:01 +0200 Subject: [PATCH] WIP snapshot: structure templates and jigsaw follow-ups Uncommitted work from a finished agent worktree on ludothinkpad (/home/ludovic/.t3/scratch/2026-10-03-i-want-you-to-retro-e5fa4461/.claude/worktrees/agent-a2bb16cfb9ff4be19), saved before the worktree was removed. Not built or verified. Co-Authored-By: Claude Opus 5.5 --- .../src/worldgen/generator_decoration.rs | 1 + crates/horizon-world/src/worldgen/structure.rs | 4 +++- .../src/worldgen/structure/features.rs | 4 ++-- .../src/worldgen/structure/jigsaw.rs | 18 ++++++------------ .../src/worldgen/structure/legacy.rs | 6 +++++- .../src/worldgen/structure/processor.rs | 2 +- .../src/worldgen/structure/start.rs | 9 ++------- .../src/worldgen/structure/template.rs | 7 +++++++ 8 files changed, 27 insertions(+), 24 deletions(-) diff --git a/crates/horizon-world/src/worldgen/generator_decoration.rs b/crates/horizon-world/src/worldgen/generator_decoration.rs index b2da351c2..498850250 100644 --- a/crates/horizon-world/src/worldgen/generator_decoration.rs +++ b/crates/horizon-world/src/worldgen/generator_decoration.rs @@ -246,6 +246,7 @@ impl Decoration { .filter_map(|(name, feature)| feature.as_ref().err().map(|e| (name.clone(), e.clone()))) .collect() } + #[allow(clippy::too_many_arguments)] pub(super) fn decorate( &self, data: &Arc, diff --git a/crates/horizon-world/src/worldgen/structure.rs b/crates/horizon-world/src/worldgen/structure.rs index c5146d62a..608337cd1 100644 --- a/crates/horizon-world/src/worldgen/structure.rs +++ b/crates/horizon-world/src/worldgen/structure.rs @@ -294,7 +294,7 @@ impl StructureResources { .collect(), } } - /// StructureTemplateManager.getOrCreate; missing templates are None. + /// StructureTemplateManager.getOrCreate; missing templates are empty. pub fn template(&self, id: &str) -> Option> { let id = if id.contains(':') { id.to_owned() @@ -322,6 +322,8 @@ impl StructureResources { &self.transforms, ))) }); + // StructureTemplateManager.getOrCreate: missing templates are empty. + let loaded = loaded.or_else(|| Some(Arc::new(StructureTemplate::empty()))); self.templates.write().unwrap().insert(id, loaded.clone()); loaded } diff --git a/crates/horizon-world/src/worldgen/structure/features.rs b/crates/horizon-world/src/worldgen/structure/features.rs index 63e9a494a..73eecc808 100644 --- a/crates/horizon-world/src/worldgen/structure/features.rs +++ b/crates/horizon-world/src/worldgen/structure/features.rs @@ -94,7 +94,7 @@ impl TemplateFeature { pos[i] += step[i] * length; } } - let mut settings = PlaceSettings::new(rotation).add(&self.processors); + let mut settings = PlaceSettings::new(rotation).with_processors(&self.processors); settings.random = Some(random); place_in_world( world, @@ -212,7 +212,7 @@ impl FossilFeature { (base, &self.fossil_processors), (overlay, &self.overlay_processors), ] { - let mut settings = PlaceSettings::new(rotation).add(processors); + let mut settings = PlaceSettings::new(rotation).with_processors(processors); settings.bounding_box = Some(bounds); settings.random = Some(&mut *random); place_in_world( diff --git a/crates/horizon-world/src/worldgen/structure/jigsaw.rs b/crates/horizon-world/src/worldgen/structure/jigsaw.rs index 005fab6d0..d78c12f57 100644 --- a/crates/horizon-world/src/worldgen/structure/jigsaw.rs +++ b/crates/horizon-world/src/worldgen/structure/jigsaw.rs @@ -406,12 +406,7 @@ impl PoolPiece { random: &mut R, chunk_box: BoundingBox, reference: [i32; 3], - place_feature: &mut dyn FnMut( - &mut W, - &mut R, - &str, - [i32; 3], - ) -> Result, + place_feature: &mut PlaceFeature<'_, W, R>, ) -> Result { place_element( &self.element, @@ -441,12 +436,7 @@ fn place_element( reference: [i32; 3], rotation: Rotation, waterlogging: bool, - place_feature: &mut dyn FnMut( - &mut W, - &mut R, - &str, - [i32; 3], - ) -> Result, + place_feature: &mut PlaceFeature<'_, W, R>, ) -> Result { match element { PoolElement::Empty => Ok(true), @@ -520,6 +510,10 @@ fn place_element( } } +/// Places a named placed feature (feature pool elements) with the piece random. +pub type PlaceFeature<'a, W, R> = + dyn FnMut(&mut W, &mut R, &str, [i32; 3]) -> Result + 'a; + /// The world queries jigsaw assembly needs from the chunk generator. pub trait JigsawContext { fn min_y(&self) -> i32; diff --git a/crates/horizon-world/src/worldgen/structure/legacy.rs b/crates/horizon-world/src/worldgen/structure/legacy.rs index d78b89b68..8843310ac 100644 --- a/crates/horizon-world/src/worldgen/structure/legacy.rs +++ b/crates/horizon-world/src/worldgen/structure/legacy.rs @@ -23,6 +23,8 @@ use horizon_core::{ use std::sync::{Arc, Mutex}; pub type Result = std::result::Result; +/// Data markers of a placed template: (metadata, absolute position). +pub type Markers = Vec<(String, [i32; 3])>; /// The random draws legacy pieces make. pub trait PieceRandom: ProcessorRandom { @@ -48,6 +50,7 @@ pub trait PieceWorld { fn max_y(&mut self) -> Result; fn block_entity(&mut self, pos: [i32; 3], nbt: Compound) -> Result<()>; fn post_process(&mut self, pos: [i32; 3]) -> Result<()>; + #[allow(clippy::too_many_arguments)] fn place_template( &mut self, resources: &StructureResources, @@ -85,6 +88,7 @@ impl PieceWorld for W { fn post_process(&mut self, pos: [i32; 3]) -> Result<()> { self.mark_postprocessing(pos) } + #[allow(clippy::too_many_arguments)] fn place_template( &mut self, resources: &StructureResources, @@ -721,7 +725,7 @@ impl TemplatePiece { c: &mut PieceContext<'_>, position: [i32; 3], extra: &[Processor], - ) -> Result>> { + ) -> Result> { let ignore = Processor::BlockIgnore(self.ignore.iter().cloned().collect()); let mut settings = self.settings(); settings.bounding_box = Some(c.chunk_box); diff --git a/crates/horizon-world/src/worldgen/structure/processor.rs b/crates/horizon-world/src/worldgen/structure/processor.rs index 4e50654d6..d2bebe662 100644 --- a/crates/horizon-world/src/worldgen/structure/processor.rs +++ b/crates/horizon-world/src/worldgen/structure/processor.rs @@ -325,7 +325,7 @@ impl<'a> PlaceSettings<'a> { random: None, } } - pub fn add(mut self, list: &'a ProcessorList) -> Self { + pub fn with_processors(mut self, list: &'a ProcessorList) -> Self { self.processors.extend(list.0.iter()); self } diff --git a/crates/horizon-world/src/worldgen/structure/start.rs b/crates/horizon-world/src/worldgen/structure/start.rs index 32c838a54..598893419 100644 --- a/crates/horizon-world/src/worldgen/structure/start.rs +++ b/crates/horizon-world/src/worldgen/structure/start.rs @@ -2,7 +2,7 @@ //! references, terrain adaptation and per-chunk piece placement. use super::{ BoundingBox, StructureResources, - jigsaw::{JigsawConfig, JigsawContext, PoolPiece, Pools, Projection, assemble}, + jigsaw::{JigsawConfig, JigsawContext, PlaceFeature, PoolPiece, Pools, Projection, assemble}, legacy::{LegacyPiece, PieceContext}, }; use crate::{ @@ -731,12 +731,7 @@ pub fn place_in_chunk Result, + place_feature: &mut PlaceFeature<'_, W, R>, ) -> Result<(), PlacementQueryError> { let Some(first) = start.pieces.first() else { return Ok(()); diff --git a/crates/horizon-world/src/worldgen/structure/template.rs b/crates/horizon-world/src/worldgen/structure/template.rs index a95a68f46..c4e9b4f9f 100644 --- a/crates/horizon-world/src/worldgen/structure/template.rs +++ b/crates/horizon-world/src/worldgen/structure/template.rs @@ -118,6 +118,13 @@ pub(super) fn parse_state_string(registry: &BlockRegistry, text: &str) -> Option } impl StructureTemplate { + /// A new, never-loaded template: zero size and no palettes. + pub fn empty() -> Self { + Self { + size: [0; 3], + palettes: Vec::new(), + } + } /// StructureTemplate.load. Blocks are ordered as vanilla orders them: /// full collision blocks, then other blocks, then block entities, each /// sorted by Y, X, Z.