Merge remote-tracking branch 'origin/wip/horizon-structures-templates' into t3code/rewrite-minecraft-rust

This commit is contained in:
Ludovic Marie
2026-10-08 11:46:40 +02:00
8 changed files with 27 additions and 24 deletions
@@ -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<GeneratorData>,
@@ -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<Arc<StructureTemplate>> {
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
}
@@ -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(
@@ -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<bool, PlacementQueryError>,
place_feature: &mut PlaceFeature<'_, W, R>,
) -> Result<bool, PlacementQueryError> {
place_element(
&self.element,
@@ -441,12 +436,7 @@ fn place_element<W: FeatureWorld + PlacementContext, R: RandomSource>(
reference: [i32; 3],
rotation: Rotation,
waterlogging: bool,
place_feature: &mut dyn FnMut(
&mut W,
&mut R,
&str,
[i32; 3],
) -> Result<bool, PlacementQueryError>,
place_feature: &mut PlaceFeature<'_, W, R>,
) -> Result<bool, PlacementQueryError> {
match element {
PoolElement::Empty => Ok(true),
@@ -520,6 +510,10 @@ fn place_element<W: FeatureWorld + PlacementContext, R: RandomSource>(
}
}
/// 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<bool, PlacementQueryError> + 'a;
/// The world queries jigsaw assembly needs from the chunk generator.
pub trait JigsawContext {
fn min_y(&self) -> i32;
@@ -23,6 +23,8 @@ use horizon_core::{
use std::sync::{Arc, Mutex};
pub type Result<T> = std::result::Result<T, PlacementQueryError>;
/// 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<i32>;
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<W: FeatureWorld + PlacementContext> 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<Option<Vec<(String, [i32; 3])>>> {
) -> Result<Option<Markers>> {
let ignore = Processor::BlockIgnore(self.ignore.iter().cloned().collect());
let mut settings = self.settings();
settings.bounding_box = Some(c.chunk_box);
@@ -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
}
@@ -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<W: FeatureWorld + PlacementContext, R: RandomSource + 'sta
resources: &StructureResources,
random: &mut R,
chunk_box: BoundingBox,
place_feature: &mut dyn FnMut(
&mut W,
&mut R,
&str,
[i32; 3],
) -> Result<bool, PlacementQueryError>,
place_feature: &mut PlaceFeature<'_, W, R>,
) -> Result<(), PlacementQueryError> {
let Some(first) = start.pieces.first() else {
return Ok(());
@@ -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.