Merge pull request #1177 from ludovic111/feat/formations-fountain
🤖 Agent: merged after integration wave 2 on the desktop (integ/w2 @ 38307d15 = main c16b41ab + this wave): fmt, clippy -D warnings, workspace + launcher + telemetry-server tests, release build and every affected parity harness pass; the 3 harness failures and the panel test passed on rerun (known flakes).
This commit is contained in:
@@ -557,6 +557,22 @@ fn upgrade_types(
|
||||
v["type"] = "horizon:formations".into();
|
||||
true
|
||||
}
|
||||
// Its PiecedStructure: the same start, then vanilla's jigsaw
|
||||
// (`horizon:pieced`).
|
||||
Some("formations:pieced") => {
|
||||
let Some(o) = v.as_object_mut() else {
|
||||
return false;
|
||||
};
|
||||
let pool = o.remove("start_pool").unwrap_or_default();
|
||||
let mut pieced = serde_json::Map::new();
|
||||
for k in ["max_depth", "max_distance_from_center"] {
|
||||
pieced.insert(k.into(), o.remove(k).unwrap_or_default());
|
||||
}
|
||||
o.insert("template".into(), pool);
|
||||
o.insert("horizon:pieced".into(), pieced.into());
|
||||
o.insert("type".into(), "horizon:formations".into());
|
||||
true
|
||||
}
|
||||
Some(t) if !t.starts_with("minecraft:") => {
|
||||
unsupported(t);
|
||||
false
|
||||
@@ -1299,6 +1315,21 @@ mod tests {
|
||||
|
||||
const NO_TAGS: BTreeMap<String, Vec<String>> = BTreeMap::new();
|
||||
|
||||
#[test]
|
||||
fn formations_pieced_structure_keeps_its_jigsaw() {
|
||||
let mut v = json!({"type": "formations:pieced", "start_pool": "fo:fountain/fountains",
|
||||
"max_depth": 2, "max_distance_from_center": 116, "placement": "surface"});
|
||||
let mut report = Upgrade::default();
|
||||
assert!(upgrade("structure", &mut v, &mut report, &BTreeMap::new()));
|
||||
assert_eq!(
|
||||
v,
|
||||
json!({"type": "horizon:formations", "template": "fo:fountain/fountains",
|
||||
"placement": "surface",
|
||||
"horizon:pieced": {"max_depth": 2, "max_distance_from_center": 116}})
|
||||
);
|
||||
assert!(report.unsupported.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formations_become_the_games() {
|
||||
let mut report = Upgrade::default();
|
||||
@@ -1324,12 +1355,7 @@ mod tests {
|
||||
(json!(6), json!(1))
|
||||
);
|
||||
assert!(e(0).get("ground_level").is_none());
|
||||
// The pieced structure stays out.
|
||||
let mut pieced = json!({"type": "formations:pieced", "start_pool": "f:p", "max_depth": 2,
|
||||
"max_distance_from_center": 40, "placement": "surface", "biomes": "#f:x"});
|
||||
assert!(!upgrade("structure", &mut pieced, &mut report, &NO_TAGS));
|
||||
assert_eq!(report.unsupported.get("formations:pieced"), Some(&1));
|
||||
assert_eq!(report.unsupported.len(), 1);
|
||||
assert!(report.unsupported.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -3,9 +3,14 @@
|
||||
//! one pool element at a random spot of the chunk, at a height its
|
||||
//! placement finds in the noise columns under the element's corners and
|
||||
//! centre ([`StartContext::noise_column`]).
|
||||
//!
|
||||
//! Its PiecedStructure (the fountain) starts the same way, then lays out
|
||||
//! the element's jigsaw children with vanilla's jigsaw
|
||||
//! ([`super::jigsaw::add_children`]): `horizon:pieced` on the structure
|
||||
//! holds its `max_depth` and `max_distance_from_center`.
|
||||
use super::{
|
||||
BoundingBox, Rotation, StructureResources,
|
||||
jigsaw::{PoolElement, PoolPiece, Pools},
|
||||
jigsaw::{JigsawConfig, PoolElement, PoolPiece, Pools, add_children},
|
||||
start::{NoiseBlock, NoiseColumn, StartContext},
|
||||
};
|
||||
use crate::{
|
||||
@@ -51,6 +56,8 @@ impl Placement {
|
||||
pub struct Def {
|
||||
pub pool: String,
|
||||
pub placement: Placement,
|
||||
/// PiecedStructure's jigsaw: (max depth, max distance from the centre).
|
||||
pub pieced: Option<(i32, i32)>,
|
||||
}
|
||||
impl Def {
|
||||
pub fn decode(v: &Value) -> Result<Self, DecodeError> {
|
||||
@@ -61,11 +68,21 @@ impl Def {
|
||||
.ok_or(DecodeError::Field("formations template"))?
|
||||
.to_owned(),
|
||||
placement: Placement::decode(v["placement"].as_str().unwrap_or_default())?,
|
||||
pieced: match v.get("horizon:pieced") {
|
||||
None => None,
|
||||
Some(p) => {
|
||||
let int = |k: &'static str| {
|
||||
p[k].as_i64().map(|n| n as i32).ok_or(DecodeError::Field(k))
|
||||
};
|
||||
Some((int("max_depth")?, int("max_distance_from_center")?))
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// SimpleStructure.findGenerationPoint: the start's position and piece.
|
||||
/// SimpleStructure.findGenerationPoint, or PiecedStructure's: the start's
|
||||
/// position and pieces.
|
||||
pub fn generate(
|
||||
def: &Def,
|
||||
context: &mut impl StartContext,
|
||||
@@ -74,7 +91,7 @@ pub fn generate(
|
||||
bindings: &FeatureBlockBindings<'_>,
|
||||
random: &mut impl RandomSource,
|
||||
chunk: ChunkPos,
|
||||
) -> Option<([i32; 3], PoolPiece)> {
|
||||
) -> Option<([i32; 3], Vec<PoolPiece>)> {
|
||||
let element = pools
|
||||
.get(&def.pool, resources, bindings)?
|
||||
.random_template(random);
|
||||
@@ -88,7 +105,7 @@ pub fn generate(
|
||||
let height = find_height(def.placement, context, b, random)?;
|
||||
let ground = element.ground_level_delta();
|
||||
let y = height - ground + 1;
|
||||
if y < context.min_y() {
|
||||
if def.pieced.is_none() && y < context.min_y() {
|
||||
return None;
|
||||
}
|
||||
let piece = PoolPiece {
|
||||
@@ -101,7 +118,46 @@ pub fn generate(
|
||||
// LiquidSettings.APPLY_WATERLOGGING.
|
||||
waterlogging: true,
|
||||
};
|
||||
Some(([x, y, z], piece))
|
||||
let Some((max_depth, distance)) = def.pieced else {
|
||||
return Some(([x, y, z], vec![piece]));
|
||||
};
|
||||
// PiecedStructure.addPieces: the start sits at the element's centre, one
|
||||
// above the height found, and its children may fill the box of
|
||||
// `distance` around it (not clamped to the world's height) less its own.
|
||||
let (cx, cy, cz) = (
|
||||
(b.max[0] + b.min[0]) / 2,
|
||||
height + 1,
|
||||
(b.max[2] + b.min[2]) / 2,
|
||||
);
|
||||
let mut pieces = vec![piece];
|
||||
if max_depth > 0 {
|
||||
let config = JigsawConfig {
|
||||
start_pool: &def.pool,
|
||||
start_jigsaw: None,
|
||||
max_depth,
|
||||
use_expansion_hack: false,
|
||||
project_to: None,
|
||||
max_distance: [distance, distance],
|
||||
aliases: &Default::default(),
|
||||
padding: [0, 0],
|
||||
waterlogging: true,
|
||||
};
|
||||
let container = BoundingBox::new(
|
||||
[cx - distance, cy - distance, cz - distance],
|
||||
[cx + distance, cy + distance, cz + distance],
|
||||
);
|
||||
add_children(
|
||||
&config,
|
||||
context,
|
||||
pools,
|
||||
resources,
|
||||
bindings,
|
||||
random,
|
||||
&mut pieces,
|
||||
container,
|
||||
);
|
||||
}
|
||||
Some(([cx, cy, cz], pieces))
|
||||
}
|
||||
|
||||
/// The four corners (min x min z, min x max z, max x max z, max x min z)
|
||||
@@ -335,6 +391,15 @@ mod tests {
|
||||
);
|
||||
assert!(Placement::decode("floating").is_err());
|
||||
let def = Def::decode(&serde_json::json!({"template": "a:b", "placement": "surface"}));
|
||||
assert_eq!(def.unwrap().placement, Placement::Surface);
|
||||
let def = def.unwrap();
|
||||
assert_eq!((def.placement, def.pieced), (Placement::Surface, None));
|
||||
let pieced = Def::decode(
|
||||
&serde_json::json!({"template": "a:b", "placement": "surface",
|
||||
"horizon:pieced": {"max_depth": 2, "max_distance_from_center": 116}}),
|
||||
);
|
||||
assert_eq!(pieced.unwrap().pieced, Some((2, 116)));
|
||||
let broken = serde_json::json!({"template": "a:b", "placement": "surface",
|
||||
"horizon:pieced": {"max_depth": 2}});
|
||||
assert!(Def::decode(&broken).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -690,25 +690,53 @@ pub fn assemble(
|
||||
let [h, v] = config.max_distance;
|
||||
let low_y = (cy - v).max(context.min_y() + config.padding[0]);
|
||||
let high_y = (cy + v + 1).min(context.max_y() + 1 - config.padding[1]);
|
||||
let free = Rc::new(RefCell::new(Free {
|
||||
container: BoundingBox::new([cx - h, low_y, cz - h], [cx + h, high_y - 1, cz + h]),
|
||||
removed: vec![pieces[0].bounding_box],
|
||||
}));
|
||||
let mut placer = Placer {
|
||||
let container = BoundingBox::new([cx - h, low_y, cz - h], [cx + h, high_y - 1, cz + h]);
|
||||
add_children(
|
||||
config,
|
||||
context,
|
||||
pools,
|
||||
resources,
|
||||
bindings,
|
||||
pieces: &mut pieces,
|
||||
queue: BTreeMap::new(),
|
||||
};
|
||||
placer.children(0, free, 0, context, random);
|
||||
while let Some(state) = placer.next() {
|
||||
placer.children(state.piece, state.free, state.depth, context, random);
|
||||
}
|
||||
random,
|
||||
&mut pieces,
|
||||
container,
|
||||
);
|
||||
}
|
||||
Some(([cx, cy, cz], pieces))
|
||||
}
|
||||
|
||||
/// The inner JigsawPlacement.addPieces: lays out the children of
|
||||
/// `pieces[0]`, a start piece already placed, to `config.max_depth`,
|
||||
/// within `container` (inclusive) less the start's box. A structure with
|
||||
/// its own start (Formations' pieced one) reaches the jigsaw layout here.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(super) fn add_children(
|
||||
config: &JigsawConfig<'_>,
|
||||
context: &mut impl JigsawContext,
|
||||
pools: &Pools,
|
||||
resources: &StructureResources,
|
||||
bindings: &FeatureBlockBindings<'_>,
|
||||
random: &mut impl RandomSource,
|
||||
pieces: &mut Vec<PoolPiece>,
|
||||
container: BoundingBox,
|
||||
) {
|
||||
let free = Rc::new(RefCell::new(Free {
|
||||
container,
|
||||
removed: vec![pieces[0].bounding_box],
|
||||
}));
|
||||
let mut placer = Placer {
|
||||
config,
|
||||
pools,
|
||||
resources,
|
||||
bindings,
|
||||
pieces,
|
||||
queue: BTreeMap::new(),
|
||||
};
|
||||
placer.children(0, free, 0, context, random);
|
||||
while let Some(state) = placer.next() {
|
||||
placer.children(state.piece, state.free, state.depth, context, random);
|
||||
}
|
||||
}
|
||||
struct Placer<'a, 'p> {
|
||||
config: &'a JigsawConfig<'a>,
|
||||
pools: &'a Pools,
|
||||
|
||||
@@ -1173,7 +1173,7 @@ fn try_generate(
|
||||
(position, legacy(vec![piece]))
|
||||
}
|
||||
StructureKind::Formations(formations) => {
|
||||
let (position, piece) = super::formations::generate(
|
||||
let (position, pieces) = super::formations::generate(
|
||||
formations,
|
||||
context,
|
||||
®istry.pools,
|
||||
@@ -1182,7 +1182,7 @@ fn try_generate(
|
||||
&mut random,
|
||||
chunk,
|
||||
)?;
|
||||
(position, vec![Piece::Pool(piece)])
|
||||
(position, pieces.into_iter().map(Piece::Pool).collect())
|
||||
}
|
||||
StructureKind::Unsupported(_) => return None,
|
||||
};
|
||||
|
||||
+7
-1
@@ -643,7 +643,6 @@ Two cases the oracle fills in:
|
||||
- When Dungeons Arise, Structory and Towns and Towers use vanilla's types already (T&T's
|
||||
namespaces are carried since the namespaces rule above).
|
||||
- Still lost, written in Java:
|
||||
- Formations' pieced structure (1, its one jigsaw-like type);
|
||||
- Repurposed's mineshafts, mansions and monuments, Better Mineshafts and two Better
|
||||
Dungeons types: Java structure types;
|
||||
- the block processors written in Java
|
||||
@@ -658,6 +657,13 @@ Two cases the oracle fills in:
|
||||
39 Overworld and 672 Nether starts at seed 1234 (51 and 643 at seed 2), and leaves every
|
||||
other start as it was. Its processors (biome replacements, aged blocks, bed colours,
|
||||
plants) are still dropped, so its structures keep their templates' blocks.
|
||||
Its one PiecedStructure, the fountain, starts the same way and then lays out the element's
|
||||
jigsaw children with vanilla's jigsaw: carry writes it as `horizon:formations` with
|
||||
`horizon:pieced` (`max_depth`, `max_distance_from_center`), and the game's assembler takes
|
||||
the placed start piece (`jigsaw::add_children`), the children kept within that distance of
|
||||
the start's centre, one block above the height found. It shares Formations' "uncommon"
|
||||
structure set, so where the set now picks it, it takes the place of a statue or a house:
|
||||
1 fountain at seed 1234 and 3 at seed 2 in chunks -64..63, one with a child piece.
|
||||
|
||||
With every structure PR above, the same square (seed 1234, chunks -64..63) holds 362
|
||||
overworld starts with 22,026 pieces. CTOV has 7, Better Dungeons 72 and Better Ocean
|
||||
|
||||
Reference in New Issue
Block a user