Merge pull request #1753 from ludovic111/feat/structure-blocks-harness
🤖 Agent: structures stack brought up to date with main (merge commits), verify and parity passed on this head.
This commit is contained in:
@@ -814,7 +814,6 @@ pub fn carry(
|
||||
if kind == "structure" {
|
||||
let path = rel.trim_start_matches("worldgen/structure/");
|
||||
let structure = format!("{ns}:{}", path.trim_end_matches(".json"));
|
||||
changed |= crate::legacy_structure_mods::yung::disables(&structure, &mut v);
|
||||
changed |=
|
||||
crate::worldgen::add_piece_counts(&structure, &mut v, &piece_counts);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
//! conversion.
|
||||
pub(crate) mod ctov;
|
||||
pub(crate) mod lithostitched;
|
||||
pub(crate) mod yung;
|
||||
|
||||
#[cfg(test)]
|
||||
fn data() -> crate::processors::ProcessorData {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,3 +20,4 @@ pub mod pipeline;
|
||||
pub mod processors;
|
||||
pub mod report;
|
||||
pub mod worldgen;
|
||||
mod yung;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
//! What is not here is taken out of its list later and counted
|
||||
//! (`worldgen::upgrade`). The entity NBT is written in 26.3's shape (an
|
||||
//! `equipment` map, not 1.21.1's `HandItems` and `ArmorItems`).
|
||||
use crate::legacy_structure_mods::{ctov, lithostitched, yung};
|
||||
use crate::legacy_structure_mods::{ctov, lithostitched};
|
||||
use serde_json::{Value, json};
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
@@ -177,12 +177,12 @@ fn carry_at(
|
||||
let mut out = Vec::with_capacity(expanded.len());
|
||||
for p in expanded {
|
||||
let kind = p["processor_type"].as_str().unwrap_or_default().to_owned();
|
||||
// Lithostitched's and YUNG's processors are carried apart from this
|
||||
// code (`legacy_structure_mods`).
|
||||
// Lithostitched's processors are carried apart from this code
|
||||
// (`legacy_structure_mods`).
|
||||
let replacement = lithostitched::processor(&kind, &p, data, carried).or_else(|| {
|
||||
match pillar_type(&kind).or_else(|| yung::pillar_type(&kind)) {
|
||||
match pillar_type(&kind) {
|
||||
Some(to) => Some(vec![pillar(&p, to, data, carried, depth)]),
|
||||
None => as_data(&kind, &p, data).or_else(|| yung::processor(&kind, &p)),
|
||||
None => as_data(&kind, &p, data),
|
||||
}
|
||||
});
|
||||
match replacement {
|
||||
@@ -860,8 +860,10 @@ mod tests {
|
||||
"horizon:bottom_pillar",
|
||||
"horizon:close_off_fluid_sources",
|
||||
"horizon:close_off_air_sources",
|
||||
"horizon:yung_pillar",
|
||||
"horizon:stair_pillar"
|
||||
// YUNG's processors stay Java (dropped later) until the
|
||||
// specification covers them.
|
||||
"betterfortresses:pillar_processor",
|
||||
"betterfortresses:stair_pillar_processor"
|
||||
]
|
||||
);
|
||||
// The named list is written in once; its own pillar loses its list.
|
||||
@@ -878,8 +880,7 @@ mod tests {
|
||||
p[4]["weighted_list_of_replacement_blocks"],
|
||||
json!([{"block": "minecraft:prismarine", "weight": 1}])
|
||||
);
|
||||
assert_eq!(p[6]["pillar"], "minecraft:red_nether_bricks");
|
||||
assert_eq!(carried["repurposed_structures:pillar_processor"], 2);
|
||||
assert_eq!(carried["betterfortresses:stair_pillar_processor"], 1);
|
||||
assert!(!carried.contains_key("betterfortresses:stair_pillar_processor"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,11 @@
|
||||
//! as it is is listed, so the coverage report can say what generates and how
|
||||
//! closely.
|
||||
//!
|
||||
//! YUNG's, Lithostitched's and CTOV's worldgen files are converted by
|
||||
//! YUNG's API's files are carried as written ([`crate::yung`]).
|
||||
//! Lithostitched's and CTOV's worldgen files are converted by
|
||||
//! `legacy_structure_mods`, called from [`upgrade`], [`crate::carry`] and the
|
||||
//! processors.
|
||||
use crate::legacy_structure_mods::{lithostitched, yung};
|
||||
use crate::{legacy_structure_mods::lithostitched, yung};
|
||||
use serde_json::Value;
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
@@ -262,7 +263,7 @@ fn upgrade_types(
|
||||
let lost = &mut report.rules_lost;
|
||||
// YUNG's and Lithostitched's types are converted apart from this code.
|
||||
if let Some(changed) =
|
||||
yung::upgrade(kind, v, set_tags, lost).or_else(|| lithostitched::upgrade(kind, v, lost))
|
||||
yung::upgrade(kind, v, lost).or_else(|| lithostitched::upgrade(kind, v, lost))
|
||||
{
|
||||
report.mapped += usize::from(changed);
|
||||
return changed;
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
//! YUNG's API's worldgen, carried as the mods write it (clean room:
|
||||
//! `cleanroom/structures/spec-yungsapi.md`).
|
||||
//!
|
||||
//! The game reads `yungsapi:yung_jigsaw` structures and
|
||||
//! `yungsapi:yung_single_element` pool elements as they ship
|
||||
//! (`horizon_world::worldgen::structure::jigsaw::Draws::Yung`), so their files
|
||||
//! pass through unchanged. What the game does not run yet is counted by name
|
||||
//! in the carry report: the fields whose behaviour the specification leaves
|
||||
//! open. YUNG's other structure, placement and processor types are left to the
|
||||
//! general code, which lists them as unsupported or drops them.
|
||||
use serde_json::Value;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
const JIGSAW: &str = "yungsapi:yung_jigsaw";
|
||||
const ELEMENT: &str = "yungsapi:yung_single_element";
|
||||
/// A terrain adaptation that adapts nothing.
|
||||
const NO_ADAPTATION: &str = "yungsapi:none";
|
||||
|
||||
fn count(lost: &mut BTreeMap<String, usize>, rule: String) {
|
||||
*lost.entry(rule).or_default() += 1;
|
||||
}
|
||||
|
||||
/// Whether a field changes generation in a way the game does not run yet:
|
||||
/// present, and not the value that changes nothing.
|
||||
fn active(v: &Value, field: &str) -> bool {
|
||||
match &v[field] {
|
||||
Value::Null | Value::Bool(false) => false,
|
||||
Value::Object(o) => o.get("type").and_then(Value::as_str) != Some(NO_ADAPTATION),
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// A `yung_jigsaw` structure: `Some(false)` (carried as it is), else `None`.
|
||||
pub(crate) fn upgrade(kind: &str, v: &Value, lost: &mut BTreeMap<String, usize>) -> Option<bool> {
|
||||
if kind != "structure" || v["type"] != JIGSAW {
|
||||
return None;
|
||||
}
|
||||
// spec-yungsapi §2: OPEN-Y1, OPEN-Y2 and §5.
|
||||
for field in [
|
||||
"adapt_noise",
|
||||
"max_y",
|
||||
"min_y",
|
||||
"enhanced_terrain_adaptation",
|
||||
] {
|
||||
if active(v, field) {
|
||||
count(lost, format!("{JIGSAW} {field}"));
|
||||
}
|
||||
}
|
||||
Some(false)
|
||||
}
|
||||
|
||||
/// A `yung_single_element` pool element, carried as it is; whether it was one.
|
||||
pub(crate) fn upgrade_pool_element(element: &Value, lost: &mut BTreeMap<String, usize>) -> bool {
|
||||
if element["element_type"] != ELEMENT {
|
||||
return false;
|
||||
}
|
||||
// spec-yungsapi §4 and §5. `name`, `max_count`, `is_priority`,
|
||||
// `min_required_depth` and `ignore_bounds` are run (§3, §3.2).
|
||||
for field in ["condition", "enhanced_terrain_adaptation", "modifiers"] {
|
||||
if active(element, field) {
|
||||
count(lost, format!("{ELEMENT} {field}"));
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn jigsaws_and_elements_are_carried_as_written() {
|
||||
let mut lost = BTreeMap::new();
|
||||
let dungeon =
|
||||
json!({"type": JIGSAW, "start_pool": "a:b", "size": 10, "adapt_noise": false});
|
||||
assert_eq!(upgrade("structure", &dungeon, &mut lost), Some(false));
|
||||
assert!(lost.is_empty());
|
||||
let stronghold = json!({"type": JIGSAW, "max_y": 0,
|
||||
"enhanced_terrain_adaptation": {"type": "yungsapi:carved"}});
|
||||
assert_eq!(upgrade("structure", &stronghold, &mut lost), Some(false));
|
||||
assert_eq!(lost[&format!("{JIGSAW} max_y")], 1);
|
||||
assert_eq!(lost[&format!("{JIGSAW} enhanced_terrain_adaptation")], 1);
|
||||
assert_eq!(
|
||||
upgrade("structure", &json!({"type": "minecraft:jigsaw"}), &mut lost),
|
||||
None
|
||||
);
|
||||
assert_eq!(upgrade("structure_set", &dungeon, &mut lost), None);
|
||||
|
||||
let mut lost = BTreeMap::new();
|
||||
let pile = json!({"element_type": ELEMENT, "name": "loot_pile_0", "max_count": 1,
|
||||
"enhanced_terrain_adaptation": {"type": NO_ADAPTATION}, "is_priority": true,
|
||||
"min_required_depth": 2, "ignore_bounds": true});
|
||||
assert!(upgrade_pool_element(&pile, &mut lost));
|
||||
assert!(lost.is_empty());
|
||||
let gated = json!({"element_type": ELEMENT, "condition": {"type": "yungsapi:not"}});
|
||||
assert!(upgrade_pool_element(&gated, &mut lost));
|
||||
assert_eq!(lost[&format!("{ELEMENT} condition")], 1);
|
||||
let single = json!({"element_type": "minecraft:single_pool_element"});
|
||||
assert!(!upgrade_pool_element(&single, &mut lost));
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@ pub mod start_checks;
|
||||
pub mod stronghold;
|
||||
pub mod template;
|
||||
pub mod temple;
|
||||
pub mod yung;
|
||||
|
||||
use crate::{
|
||||
nbt::{self, Limits},
|
||||
|
||||
@@ -306,7 +306,6 @@ mod tests {
|
||||
legacy: false,
|
||||
projection,
|
||||
waterlogging: None,
|
||||
yung: None,
|
||||
enhanced_terrain: own.map(Arc::new),
|
||||
ground_level: 1,
|
||||
})
|
||||
|
||||
@@ -39,9 +39,6 @@ pub enum PoolElement {
|
||||
legacy: bool,
|
||||
projection: Projection,
|
||||
waterlogging: Option<bool>,
|
||||
/// YUNG's API's rules on the piece (`"horizon:yungsapi"`), read only
|
||||
/// by its assembler ([`super::yung`]).
|
||||
yung: Option<Box<super::yung::Rules>>,
|
||||
/// The piece's own terrain kernel in a structure that has one
|
||||
/// (`"horizon:enhanced_terrain_adaptation"`).
|
||||
enhanced_terrain: Option<Arc<super::enhanced_terrain::Adaptation>>,
|
||||
@@ -123,7 +120,7 @@ impl PoolElement {
|
||||
Ok(match kind {
|
||||
"minecraft:empty_pool_element" => Self::Empty,
|
||||
// YUNG's API's element places what a single element places; its
|
||||
// `name` and `max_count` are the pool entry's (`Pool::limits`).
|
||||
// own fields are the pool entry's rules (`Pool::rules`).
|
||||
"minecraft:single_pool_element"
|
||||
| "minecraft:legacy_single_pool_element"
|
||||
| "yungsapi:yung_single_element" => {
|
||||
@@ -149,10 +146,6 @@ impl PoolElement {
|
||||
Some("ignore_waterlogging") => Some(false),
|
||||
_ => None,
|
||||
},
|
||||
yung: value
|
||||
.get("horizon:yungsapi")
|
||||
.map(|rules| super::yung::Rules::decode(rules, resources).map(Box::new))
|
||||
.transpose()?,
|
||||
enhanced_terrain: value
|
||||
.get("horizon:enhanced_terrain_adaptation")
|
||||
.map(|a| super::enhanced_terrain::Adaptation::decode(a).map(Arc::new))
|
||||
@@ -248,13 +241,10 @@ impl PoolElement {
|
||||
.first()
|
||||
.map(|e| e.shuffled_jigsaws(resources, position, rotation, random))
|
||||
.unwrap_or_default(),
|
||||
Self::Single { template, yung, .. } => {
|
||||
Self::Single { template, .. } => {
|
||||
let mut jigsaws = template_jigsaws(resources, template, position, rotation);
|
||||
shuffle(&mut jigsaws, random);
|
||||
// YUNG's elements keep the shuffled order.
|
||||
if yung.is_none() {
|
||||
jigsaws.sort_by_key(|j| std::cmp::Reverse(j.selection_priority));
|
||||
}
|
||||
jigsaws.sort_by_key(|j| std::cmp::Reverse(j.selection_priority));
|
||||
jigsaws
|
||||
}
|
||||
}
|
||||
@@ -265,13 +255,6 @@ impl PoolElement {
|
||||
_ => 1,
|
||||
}
|
||||
}
|
||||
/// YUNG's API's rules, on a piece of one of its structures.
|
||||
pub fn yung(&self) -> Option<&super::yung::Rules> {
|
||||
match self {
|
||||
Self::Single { yung, .. } => yung.as_deref(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
/// The piece's own terrain kernel, in place of its structure's.
|
||||
pub fn enhanced_terrain(&self) -> Option<&super::enhanced_terrain::Adaptation> {
|
||||
match self {
|
||||
@@ -340,9 +323,8 @@ pub struct Pool {
|
||||
pub(super) templates: Vec<Arc<PoolElement>>,
|
||||
/// The elements with their weights, in file order (`rawTemplates`).
|
||||
pub(super) raw: Vec<(Arc<PoolElement>, i32)>,
|
||||
/// Per entry of `raw`: a YUNG element's `name` and `max_count`, the most
|
||||
/// pieces of that name in one start.
|
||||
limits: Vec<Option<(Arc<str>, i32)>>,
|
||||
/// Per entry of `raw`: a YUNG element's rules.
|
||||
rules: Vec<Rules>,
|
||||
pub(super) fallback: String,
|
||||
max_size: OnceLock<i32>,
|
||||
}
|
||||
@@ -382,6 +364,37 @@ impl Pool {
|
||||
})
|
||||
}
|
||||
}
|
||||
/// A `yungsapi:yung_single_element`'s own fields (spec-yungsapi §3, §3.2).
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct Rules {
|
||||
/// `name` and `max_count`: the most pieces of that name in one start,
|
||||
/// the start not counted.
|
||||
limit: Option<(Arc<str>, i32)>,
|
||||
/// `is_priority`: tried before the pool's other entries, in the
|
||||
/// shuffled order and without a weighted draw.
|
||||
priority: bool,
|
||||
/// `min_required_depth`: the least depth of the parent piece (the start
|
||||
/// is depth 0).
|
||||
min_depth: i32,
|
||||
/// `ignore_bounds`: placed without the free-space test.
|
||||
ignore_bounds: bool,
|
||||
}
|
||||
impl Rules {
|
||||
fn of(element: &Value) -> Self {
|
||||
if element["element_type"] != "yungsapi:yung_single_element" {
|
||||
return Self::default();
|
||||
}
|
||||
Self {
|
||||
limit: element["name"]
|
||||
.as_str()
|
||||
.zip(element["max_count"].as_i64())
|
||||
.map(|(name, max)| (name.into(), max as i32)),
|
||||
priority: element["is_priority"].as_bool().unwrap_or(false),
|
||||
min_depth: element["min_required_depth"].as_i64().unwrap_or(0) as i32,
|
||||
ignore_bounds: element["ignore_bounds"].as_bool().unwrap_or(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Lazily decoded template pools.
|
||||
pub struct Pools {
|
||||
raw: BTreeMap<String, String>,
|
||||
@@ -410,7 +423,7 @@ impl Pools {
|
||||
}
|
||||
let pool = self.raw.get(name).and_then(|json| {
|
||||
let value: Value = serde_json::from_str(json).ok()?;
|
||||
let (mut templates, mut raw, mut limits) = (Vec::new(), Vec::new(), Vec::new());
|
||||
let (mut templates, mut raw, mut rules) = (Vec::new(), Vec::new(), Vec::new());
|
||||
for entry in value["elements"].as_array()? {
|
||||
let element =
|
||||
match PoolElement::decode(&entry["element"], resources, bindings, None) {
|
||||
@@ -427,22 +440,12 @@ impl Pools {
|
||||
templates.push(element.clone());
|
||||
}
|
||||
raw.push((element, weight as i32));
|
||||
let fields = &entry["element"];
|
||||
limits.push(
|
||||
match (fields["name"].as_str(), fields["max_count"].as_i64()) {
|
||||
(Some(name), Some(max))
|
||||
if fields["element_type"] == "yungsapi:yung_single_element" =>
|
||||
{
|
||||
Some((name.into(), max as i32))
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
);
|
||||
rules.push(Rules::of(&entry["element"]));
|
||||
}
|
||||
Some(Arc::new(Pool {
|
||||
templates,
|
||||
raw,
|
||||
limits,
|
||||
rules,
|
||||
fallback: value["fallback"]
|
||||
.as_str()
|
||||
.unwrap_or("minecraft:empty")
|
||||
@@ -621,9 +624,10 @@ pub trait JigsawContext {
|
||||
pub enum Draws {
|
||||
/// JigsawPlacement's.
|
||||
Vanilla,
|
||||
/// YUNG's API's `yungsapi:yung_jigsaw` (spec-yungsapi §2.1, §3.1): pools
|
||||
/// are drawn by weight from their file entries, without replacement, and
|
||||
/// an element at its `max_count` is skipped.
|
||||
/// YUNG's API's `yungsapi:yung_jigsaw` (spec-yungsapi §2.1, §3.1, §3.2):
|
||||
/// pools are drawn by weight from their file entries, without
|
||||
/// replacement, priority entries first, and an element at its
|
||||
/// `max_count` or too shallow is skipped.
|
||||
Yung,
|
||||
}
|
||||
|
||||
@@ -632,14 +636,28 @@ enum Candidates {
|
||||
/// Vanilla: the target pool's weight-expanded elements, then the
|
||||
/// fallback's, each shuffled up front.
|
||||
Listed(std::vec::IntoIter<Arc<PoolElement>>),
|
||||
/// YUNG's: weighted picks from each pool in turn (the fallback's only
|
||||
/// once the target's are spent), each pool's entries shuffled when it
|
||||
/// is reached.
|
||||
/// YUNG's: picks from each pool in turn (the fallback's only once the
|
||||
/// target's are spent), each pool's entries shuffled when it is
|
||||
/// reached: its priority entries in that order, then weighted picks
|
||||
/// from the others.
|
||||
Weighted {
|
||||
pools: Vec<Arc<Pool>>,
|
||||
current: Option<(Arc<Pool>, Vec<usize>)>,
|
||||
current: Option<Drawing>,
|
||||
},
|
||||
}
|
||||
/// A YUNG pool being drawn: entries (indices into `raw`) not tried yet.
|
||||
struct Drawing {
|
||||
pool: Arc<Pool>,
|
||||
priority: VecDeque<usize>,
|
||||
others: Vec<usize>,
|
||||
}
|
||||
/// An element to try.
|
||||
struct Pick {
|
||||
element: Arc<PoolElement>,
|
||||
/// Its YUNG name, counted toward `max_count` when it is placed.
|
||||
name: Option<Arc<str>>,
|
||||
ignore_bounds: bool,
|
||||
}
|
||||
impl Candidates {
|
||||
fn new(
|
||||
draws: Draws,
|
||||
@@ -667,37 +685,62 @@ impl Candidates {
|
||||
},
|
||||
}
|
||||
}
|
||||
/// The next element to try, with its YUNG name and limit.
|
||||
/// The next element to try for a jigsaw of a piece at `depth`.
|
||||
fn next(
|
||||
&mut self,
|
||||
counts: &HashMap<Arc<str>, i32>,
|
||||
depth: i32,
|
||||
random: &mut impl RandomSource,
|
||||
) -> Option<(Arc<PoolElement>, Option<Arc<str>>)> {
|
||||
) -> Option<Pick> {
|
||||
match self {
|
||||
Self::Listed(elements) => elements.next().map(|e| (e, None)),
|
||||
Self::Listed(elements) => elements.next().map(|element| Pick {
|
||||
element,
|
||||
name: None,
|
||||
ignore_bounds: false,
|
||||
}),
|
||||
Self::Weighted { pools, current } => loop {
|
||||
let (pool, order) = match current {
|
||||
Some((pool, order)) if !order.is_empty() => (pool, order),
|
||||
let drawing = match current {
|
||||
Some(d) if !d.priority.is_empty() || !d.others.is_empty() => d,
|
||||
_ => {
|
||||
let pool = pools.pop()?;
|
||||
let mut order: Vec<usize> = (0..pool.raw.len()).collect();
|
||||
shuffle(&mut order, random);
|
||||
*current = Some((pool, order));
|
||||
let (priority, others): (Vec<usize>, _) =
|
||||
order.into_iter().partition(|&i| pool.rules[i].priority);
|
||||
*current = Some(Drawing {
|
||||
pool,
|
||||
priority: priority.into(),
|
||||
others,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let Some(at) = pool.weighted(order, random) else {
|
||||
order.clear();
|
||||
continue;
|
||||
let entry = match drawing.priority.pop_front() {
|
||||
Some(entry) => entry,
|
||||
None => {
|
||||
let Some(at) = drawing.pool.weighted(&drawing.others, random) else {
|
||||
drawing.others.clear();
|
||||
continue;
|
||||
};
|
||||
drawing.others.remove(at)
|
||||
}
|
||||
};
|
||||
let entry = order.remove(at);
|
||||
let limit = pool.limits[entry].clone();
|
||||
if let Some((name, max)) = &limit
|
||||
// spec-yungsapi §3.1 item 8: an empty element ends the
|
||||
// jigsaw (the caller's), then `max_count`, then the depth.
|
||||
let rules = &drawing.pool.rules[entry];
|
||||
if let Some((name, max)) = &rules.limit
|
||||
&& counts.get(name).copied().unwrap_or(0) >= *max
|
||||
{
|
||||
continue;
|
||||
}
|
||||
return Some((pool.raw[entry].0.clone(), limit.map(|(name, _)| name)));
|
||||
if depth < rules.min_depth {
|
||||
continue;
|
||||
}
|
||||
return Some(Pick {
|
||||
element: drawing.pool.raw[entry].0.clone(),
|
||||
name: rules.limit.as_ref().map(|(name, _)| name.clone()),
|
||||
ignore_bounds: rules.ignore_bounds,
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -777,10 +820,10 @@ pub fn assemble_drawing(
|
||||
.unwrap_or_else(|| name.to_owned())
|
||||
};
|
||||
let center_pool = pools.get(&alias(config.start_pool), resources, bindings)?;
|
||||
let (rotation, element, limit) = match draws {
|
||||
let (rotation, element) = match draws {
|
||||
Draws::Vanilla => {
|
||||
let rotation = Rotation::random(random);
|
||||
(rotation, center_pool.random_template(random), None)
|
||||
(rotation, center_pool.random_template(random))
|
||||
}
|
||||
// The entries shuffled, then the rotation, then a weighted pick in
|
||||
// the shuffled order.
|
||||
@@ -789,9 +832,7 @@ pub fn assemble_drawing(
|
||||
shuffle(&mut order, random);
|
||||
let rotation = Rotation::random(random);
|
||||
let entry = order[center_pool.weighted(&order, random)?];
|
||||
let (element, _) = ¢er_pool.raw[entry];
|
||||
let limit = center_pool.limits[entry].clone().map(|(name, _)| name);
|
||||
(rotation, element.clone(), limit)
|
||||
(rotation, center_pool.raw[entry].0.clone())
|
||||
}
|
||||
};
|
||||
if matches!(element.as_ref(), PoolElement::Empty) {
|
||||
@@ -846,10 +887,10 @@ pub fn assemble_drawing(
|
||||
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 container = BoundingBox::new([cx - h, low_y, cz - h], [cx + h, high_y - 1, cz + h]);
|
||||
let counts = limit.into_iter().map(|name| (name, 1)).collect();
|
||||
// The start does not count toward `max_count` (spec-yungsapi §3).
|
||||
add_children_drawing(
|
||||
draws,
|
||||
counts,
|
||||
HashMap::new(),
|
||||
config,
|
||||
context,
|
||||
pools,
|
||||
@@ -1012,7 +1053,12 @@ impl Placer<'_, '_> {
|
||||
depth != self.config.max_depth,
|
||||
random,
|
||||
);
|
||||
while let Some((target, name)) = candidates.next(&self.counts, random) {
|
||||
while let Some(Pick {
|
||||
element: target,
|
||||
name,
|
||||
ignore_bounds,
|
||||
}) = candidates.next(&self.counts, depth, random)
|
||||
{
|
||||
if matches!(target.as_ref(), PoolElement::Empty) {
|
||||
break;
|
||||
}
|
||||
@@ -1074,7 +1120,7 @@ impl Placer<'_, '_> {
|
||||
let size = (expand_to + 1).max(target_box.max[1] - target_box.min[1]);
|
||||
target_box.max[1] = target_box.max[1].max(target_box.min[1] + size);
|
||||
}
|
||||
if !children_free.borrow().fits(&target_box) {
|
||||
if !ignore_bounds && !children_free.borrow().fits(&target_box) {
|
||||
continue;
|
||||
}
|
||||
children_free.borrow_mut().removed.push(target_box);
|
||||
|
||||
@@ -1025,7 +1025,6 @@ mod tests {
|
||||
legacy: false,
|
||||
projection: Projection::Rigid,
|
||||
waterlogging: None,
|
||||
yung: None,
|
||||
enhanced_terrain: None,
|
||||
ground_level: 1,
|
||||
});
|
||||
|
||||
@@ -59,8 +59,6 @@ pub struct JigsawDef {
|
||||
waterlogging: bool,
|
||||
/// A carried mod's start rules (`"horizon:start_checks"`).
|
||||
checks: super::start_checks::StartChecks,
|
||||
/// Laid out by YUNG's API's assembler (`"horizon:yungsapi"`).
|
||||
yung: Option<super::yung::Config>,
|
||||
/// Vanilla's draws, or YUNG's API's for `yungsapi:yung_jigsaw`.
|
||||
draws: super::jigsaw::Draws,
|
||||
/// Laid out by Repurposed Structures' and Moog's piece-limited
|
||||
@@ -111,9 +109,6 @@ pub struct StructureDef {
|
||||
/// A structure library's terrain kernel
|
||||
/// (`"horizon:enhanced_terrain_adaptation"`).
|
||||
pub enhanced_terrain: Option<super::enhanced_terrain::StructureAdaptation>,
|
||||
/// Another loaded structure turns this one's type off
|
||||
/// (`"horizon:disables"`): it never starts.
|
||||
pub disabled: bool,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum Reduction {
|
||||
@@ -311,19 +306,8 @@ impl StructureRegistry {
|
||||
biome_set: &dyn Fn(&Value) -> Result<BTreeSet<BiomeId>, DecodeError>,
|
||||
) -> Result<Self, DecodeError> {
|
||||
let mut defs = Vec::new();
|
||||
let (mut types, mut disables) = (Vec::new(), BTreeSet::new());
|
||||
for (name, json) in structures {
|
||||
let v: Value = serde_json::from_str(json)?;
|
||||
types.push(v["type"].as_str().unwrap_or_default().to_owned());
|
||||
// YUNG's mods turn their vanilla counterparts off (the
|
||||
// DisableVanilla*Mixin on ChunkGenerator.tryGenerateStructure).
|
||||
disables.extend(
|
||||
v["horizon:disables"]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|t| Some(t.as_str()?.to_owned())),
|
||||
);
|
||||
let draws = match v["type"].as_str() {
|
||||
Some("yungsapi:yung_jigsaw") => super::jigsaw::Draws::Yung,
|
||||
_ => super::jigsaw::Draws::Vanilla,
|
||||
@@ -347,7 +331,6 @@ impl StructureRegistry {
|
||||
padding: pair(v.get("dimension_padding"), "bottom", "top", 0),
|
||||
waterlogging: v["liquid_settings"].as_str() != Some("ignore_waterlogging"),
|
||||
checks: super::start_checks::StartChecks::decode(v.get("horizon:start_checks")),
|
||||
yung: v.get("horizon:yungsapi").map(super::yung::Config::decode),
|
||||
piece_limited: v
|
||||
.get("horizon:piece_limited")
|
||||
.map(super::piece_limited::Config::decode),
|
||||
@@ -408,12 +391,8 @@ impl StructureRegistry {
|
||||
.get("horizon:enhanced_terrain_adaptation")
|
||||
.map(super::enhanced_terrain::StructureAdaptation::decode)
|
||||
.transpose()?,
|
||||
disabled: false,
|
||||
});
|
||||
}
|
||||
for (def, kind) in defs.iter_mut().zip(&types) {
|
||||
def.disabled = disables.contains(kind);
|
||||
}
|
||||
let index = |name: &str| defs.iter().position(|d| d.name == name);
|
||||
let mut out = Vec::new();
|
||||
for (name, json) in sets {
|
||||
@@ -891,9 +870,6 @@ fn try_generate(
|
||||
chunk: ChunkPos,
|
||||
) -> Option<StructureStart> {
|
||||
let def = ®istry.structures[structure];
|
||||
if def.disabled {
|
||||
return None;
|
||||
}
|
||||
context.set_valid_biomes(&def.biomes);
|
||||
let seed = context.seed();
|
||||
let mut random = WorldgenRandom::new(LegacyRandom::new(0));
|
||||
@@ -923,8 +899,8 @@ fn try_generate(
|
||||
padding: jigsaw.padding,
|
||||
waterlogging: jigsaw.waterlogging,
|
||||
};
|
||||
let (position, mut pieces) = match (&jigsaw.yung, &jigsaw.piece_limited) {
|
||||
(_, Some(limits)) => super::piece_limited::assemble(
|
||||
let (position, mut pieces) = match &jigsaw.piece_limited {
|
||||
Some(limits) => super::piece_limited::assemble(
|
||||
&config,
|
||||
limits,
|
||||
context,
|
||||
@@ -934,17 +910,7 @@ fn try_generate(
|
||||
chunk,
|
||||
start,
|
||||
)?,
|
||||
(Some(yung), None) => super::yung::assemble(
|
||||
&config,
|
||||
yung,
|
||||
context,
|
||||
®istry.pools,
|
||||
resources,
|
||||
bindings,
|
||||
&mut random,
|
||||
start,
|
||||
)?,
|
||||
(None, None) => assemble_drawing(
|
||||
None => assemble_drawing(
|
||||
jigsaw.draws,
|
||||
&config,
|
||||
context,
|
||||
@@ -1449,37 +1415,6 @@ mod tests {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_structure_turns_its_vanilla_counterpart_off() {
|
||||
let r = registry(
|
||||
&[
|
||||
(
|
||||
"minecraft:pyramid",
|
||||
json!({"type": "minecraft:desert_pyramid"}),
|
||||
),
|
||||
("minecraft:igloo", json!({"type": "minecraft:igloo"})),
|
||||
(
|
||||
"yung:temple",
|
||||
json!({"type": "minecraft:swamp_hut", "horizon:disables": ["minecraft:desert_pyramid"]}),
|
||||
),
|
||||
],
|
||||
&[],
|
||||
);
|
||||
let disabled: Vec<_> = r
|
||||
.structures
|
||||
.iter()
|
||||
.map(|d| (d.name.as_str(), d.disabled))
|
||||
.collect();
|
||||
assert_eq!(
|
||||
disabled,
|
||||
[
|
||||
("minecraft:igloo", false),
|
||||
("minecraft:pyramid", true),
|
||||
("yung:temple", false)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exclusion_zones_may_skip_the_other_sets_own() {
|
||||
let set = |avoid: Value| {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -372,14 +372,14 @@ A pool addition holds `"elements"` as a pool does. This is what lithostitched's
|
||||
NeoForge and Fabric, and `horizon-port-pack carry` writes them from those.
|
||||
|
||||
A structure (and any of its pool elements, in place of the structure's) may
|
||||
hold `horizon:enhanced_terrain_adaptation`: YUNG's API's and
|
||||
MoogsStructureLib's terrain kernel, which carves or buries terrain around the
|
||||
hold `horizon:enhanced_terrain_adaptation`: MoogsStructureLib's terrain
|
||||
kernel, which carves or buries terrain around the
|
||||
pieces on top of vanilla's `terrain_adaptation`. `kernel_size` and
|
||||
`kernel_distance` shape the kernel; `top` and `bottom` (`carve`, `bury` or
|
||||
`none`) act above and below a piece's floor; `bottom_offset`, `padding`
|
||||
(`x`, `top`, `bottom`, `z`) and MoogsStructureLib's `band` (`bottom`, `top`,
|
||||
`piece_heights`) move the box it measures from. On a structure,
|
||||
`rigid_junctions` (YUNG's API) adds rigid pieces' junctions as well and
|
||||
`rigid_junctions` adds rigid pieces' junctions as well and
|
||||
`inflate` grows the start's box by the kernel radius. `kernel_size` 0 is
|
||||
none.
|
||||
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare the blocks Horizon's structure mods place with the blocks a real server saved.
|
||||
|
||||
Expected side: the clean-room structure oracle (see test_structure_layout_parity.py), which kept, for every
|
||||
start of a mod world, its blocks (`blocks`, the start's box) and every position of the box grown by
|
||||
`diff_margin` where the mod world differs from the no-mod world of the same seed (`changed_vs_vanilla`).
|
||||
|
||||
Horizon side: the chunk_dump probe generates the chunks around each start in full (terrain, structures,
|
||||
features) twice: from the 26.3 resources (the no-mod world) and from those resources with the mods carried
|
||||
by `horizon-port-pack carry` (the mod world), as test_structure_layout_parity.py builds them.
|
||||
|
||||
The oracle's game is 1.21.1 and Horizon's 26.3, so the worlds also differ where the versions do. A position
|
||||
is compared only where the two no-mod worlds agree (the oracle's no-mod block is known inside the start's
|
||||
box and at the changed positions); elsewhere in the grown box, where the oracle saw no change, Horizon's mod
|
||||
world must equal its no-mod world. Overlapping structures need no special case: both worlds have them.
|
||||
|
||||
A mismatch is counted by the oracle's no-mod block, the expected block and Horizon's, so a processor's
|
||||
missing rule reads as one line. KNOWN names the mismatch classes the implementation does not cover yet, with
|
||||
the reason; they are reported, not failed.
|
||||
|
||||
usage: test_structure_blocks_parity.py [--profile betterdungeons] [--filter REGEX] [--limit N]
|
||||
"""
|
||||
import argparse
|
||||
import gzip
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from collections import Counter, defaultdict
|
||||
|
||||
try:
|
||||
from . import lab, test_structure_layout_parity as layout
|
||||
except ImportError:
|
||||
import lab
|
||||
import test_structure_layout_parity as layout
|
||||
|
||||
# profile -> {structure id regex: what the implementation does not cover yet}
|
||||
KNOWN = {
|
||||
'betterdungeons': {
|
||||
r'^betterdungeons:(small|skeleton|zombie)_dungeon$':
|
||||
"Better Dungeons' placeholder processors and its biome modifier that removes vanilla's "
|
||||
'monster rooms (spec-betterdungeons §1.2, §3.2) are not implemented yet',
|
||||
r'^betterdungeons:(spider|small_nether)_dungeon$':
|
||||
"Better Dungeons' own structure types (spec-betterdungeons §5, §6; OPEN-B14, B15) are not "
|
||||
'implemented yet',
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def state(text):
|
||||
"""`name[k=v,...]` with sorted properties, the same for both games' spellings."""
|
||||
name, _, rest = text.partition('[')
|
||||
return name + ('[' + ','.join(sorted(rest.rstrip(']').split(','))) + ']' if rest else '')
|
||||
|
||||
|
||||
def state_names(resources):
|
||||
facts = json.loads((resources / 'facts.json').read_text())
|
||||
return [state(s[3].removeprefix('Block{').replace('}', '', 1)) for s in facts['states']]
|
||||
|
||||
|
||||
def chunk_rect(box):
|
||||
x0, _, z0, x1, _, z1 = box
|
||||
return f'{x0 >> 4},{z0 >> 4},{x1 >> 4},{z1 >> 4}'
|
||||
|
||||
|
||||
def generate(binary, resources, seed, dimension, boxes, names):
|
||||
"""Block states by position inside `boxes`, from chunk_dump's full generation of their chunks."""
|
||||
result = subprocess.run([str(binary), 'chunk_dump', str(resources), str(seed), dimension,
|
||||
*(chunk_rect(b) for b in boxes)], capture_output=True, text=True, cwd=lab.ROOT)
|
||||
if result.returncode:
|
||||
raise SystemExit('chunk_dump failed: ' + result.stderr[-2000:])
|
||||
rows = {} # chunk -> the heights the boxes over it need
|
||||
for x0, y0, z0, x1, y1, z1 in boxes:
|
||||
for cx in range(x0 >> 4, (x1 >> 4) + 1):
|
||||
for cz in range(z0 >> 4, (z1 >> 4) + 1):
|
||||
low, high = rows.get((cx, cz), (y0, y1))
|
||||
rows[(cx, cz)] = (min(low, y0), max(high, y1))
|
||||
blocks, chunk, low, high = {}, None, 0, -1
|
||||
for line in result.stdout.splitlines():
|
||||
if line.startswith('chunk '):
|
||||
_, x, z = line.split()
|
||||
low, high = rows.get((int(x), int(z)), (0, -1))
|
||||
chunk = (int(x) * 16, int(z) * 16)
|
||||
elif line.startswith('y '):
|
||||
_, y, row = line.split(' ', 2)
|
||||
y = int(y)
|
||||
if low <= y <= high:
|
||||
for i, state_id in enumerate(row.split(' ')):
|
||||
blocks[(chunk[0] + i % 16, y, chunk[1] + i // 16)] = names[int(state_id)]
|
||||
return blocks
|
||||
|
||||
|
||||
def oracle_blocks(start):
|
||||
"""(mod world, no-mod world) block by position: the box in full, the changed positions around it."""
|
||||
x0, y0, z0, x1, y1, z1 = start['bounding_box']
|
||||
palette = [state(p) for p in start['blocks']['palette']]
|
||||
runs = iter(index for index, count in start['blocks']['rle'] for _ in range(count))
|
||||
mod = {(x, y, z): palette[next(runs)] for y in range(y0, y1 + 1) for z in range(z0, z1 + 1)
|
||||
for x in range(x0, x1 + 1)}
|
||||
base = dict(mod)
|
||||
for x, y, z, mod_state, base_state in start['changed_vs_vanilla']:
|
||||
mod[(x, y, z)], base[(x, y, z)] = state(mod_state), state(base_state)
|
||||
return mod, base
|
||||
|
||||
|
||||
def inside(box, p):
|
||||
return all(box[i] <= p[i] <= box[i + 3] for i in range(3))
|
||||
|
||||
|
||||
def compare(start, vanilla, modded):
|
||||
"""Compared positions and the mismatches, as (no-mod, expected, Horizon) -> count."""
|
||||
mod, base = oracle_blocks(start)
|
||||
compared, mismatches = 0, Counter()
|
||||
x0, y0, z0, x1, y1, z1 = start['diff_box']
|
||||
for y in range(y0, y1 + 1):
|
||||
for z in range(z0, z1 + 1):
|
||||
for x in range(x0, x1 + 1):
|
||||
p = (x, y, z)
|
||||
if p not in vanilla or p not in modded:
|
||||
continue
|
||||
if p in base:
|
||||
if vanilla[p] != base[p]:
|
||||
continue # the versions differ here
|
||||
expected = mod[p]
|
||||
else:
|
||||
expected = vanilla[p] # the oracle saw no change
|
||||
compared += 1
|
||||
if modded[p] != expected:
|
||||
mismatches[(base.get(p, vanilla[p]), expected, modded[p])] += 1
|
||||
return compared, mismatches
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
parser.add_argument('--profile', default='betterdungeons', choices=[p for p, v in layout.PROFILES.items() if v['carry']])
|
||||
parser.add_argument('--filter', default='', help='only structure ids matching this regex')
|
||||
parser.add_argument('--limit', type=int, default=8, help='mismatch classes shown per structure')
|
||||
args = parser.parse_args()
|
||||
profile = layout.PROFILES[args.profile]
|
||||
results = sorted((layout.ORACLE / args.profile).glob('seed-*.json.gz'))
|
||||
missing = [jar for jar in profile['mods'].values() if not (layout.JARS / jar).exists()]
|
||||
if not results or missing:
|
||||
print(f'SKIP: oracle results or mod jars missing under {layout.ORACLE} (see test_structure_layout_parity.py)')
|
||||
return 0
|
||||
resources = layout.overlay(args.profile, layout.carry(args.profile, profile['mods'], profile['carry']))
|
||||
binary = layout.probe_binary()
|
||||
names = state_names(lab.RESOURCES)
|
||||
totals = defaultdict(lambda: [0, 0, Counter()]) # structure -> [starts, compared, mismatches]
|
||||
for path in results:
|
||||
oracle = json.load(gzip.open(path))
|
||||
seed = oracle['seed']
|
||||
starts = [s for s in oracle['structures'] if s['complete'] and re.search(args.filter, s['id'])]
|
||||
for dimension in sorted({s['dimension'] for s in starts}):
|
||||
here = [s for s in starts if s['dimension'] == dimension]
|
||||
boxes = [s['diff_box'] for s in here]
|
||||
dim = dimension.removeprefix('minecraft:')
|
||||
vanilla = generate(binary, lab.RESOURCES, seed, dim, boxes, names)
|
||||
modded = generate(binary, resources, seed, dim, boxes, names)
|
||||
for start in here:
|
||||
compared, mismatches = compare(start, vanilla, modded)
|
||||
total = totals[start['id']]
|
||||
total[0] += 1
|
||||
total[1] += compared
|
||||
total[2].update(mismatches)
|
||||
failed = False
|
||||
for structure, (starts, compared, mismatches) in sorted(totals.items()):
|
||||
wrong = sum(mismatches.values())
|
||||
reason = next((r for pattern, r in KNOWN.get(args.profile, {}).items() if re.search(pattern, structure)), None)
|
||||
verdict = 'ok ' if not wrong else 'known' if reason else 'FAIL '
|
||||
failed |= verdict == 'FAIL '
|
||||
print(f'{verdict} {structure}: {starts} starts, {compared - wrong} of {compared} positions match'
|
||||
+ (f' ({reason})' if wrong and reason else ''))
|
||||
for (base, expected, got), n in mismatches.most_common(args.limit):
|
||||
print(f' {n:6} no-mod {base} expected {expected} Horizon {got}')
|
||||
return 1 if failed else 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
@@ -17,15 +17,22 @@ The oracle's game is 1.21.1 and Horizon's 26.3. KNOWN lists the starts where 26.
|
||||
1.21.1, each checked against 26.3 vanilla (VanillaChunkGenerationOracle's `scan`, HORIZON_PIECES=1), whose
|
||||
pieces equal Horizon's there; they are reported, not failed.
|
||||
|
||||
Mod profiles compare the mod world's `pieces` instead. Horizon then reads the mod's own data from its jar
|
||||
(`.local/structure-oracle/jars/`, or HORIZON_STRUCTURE_JARS): an overlay of the 26.3 resources adds the
|
||||
jar's structures, sets, pools, processor lists, biome tags and templates, as they are written. The mod's
|
||||
own processors are left out of the overlay's lists: they change blocks, never which pieces are placed.
|
||||
Block states are upgraded to 26.3's JSON shape, as the port does.
|
||||
The jars are the player's; nothing of them enters the repository.
|
||||
Mod profiles compare the mod world's `pieces` instead, through the path players' packs take: the mod jars
|
||||
(`.local/structure-oracle/jars/`, or HORIZON_STRUCTURE_JARS) are carried by `horizon-port-pack carry` into
|
||||
a fresh work folder, and an overlay of the 26.3 resources adds the carried structures, sets, pools,
|
||||
processor lists, biome tags and templates. The jars are the player's; nothing of them enters the
|
||||
repository.
|
||||
|
||||
usage: test_structure_layout_parity.py [--profile lithostitched|betterdungeons] [--filter REGEX] [--verbose]
|
||||
The `yung-probe` profiles check YUNG's API's draws with a data pack of the spec team's own (spec-yungsapi
|
||||
§3, probe experiments e1-e9: fallback, max_count, empty elements, min_required_depth, ignore_bounds,
|
||||
max_y, is_priority). The pack is carried as one more mod, built at run time from the oracle's profile file
|
||||
(`.local/structure-oracle/profiles/<profile>.json`), and its starts are read from the oracle's census of
|
||||
every start (`all_starts`).
|
||||
|
||||
usage: test_structure_layout_parity.py [--profile lithostitched|betterdungeons|yung-probe|yung-probe2]
|
||||
[--filter REGEX] [--verbose]
|
||||
"""
|
||||
import base64
|
||||
import argparse
|
||||
import gzip
|
||||
import json
|
||||
@@ -44,12 +51,16 @@ except ImportError:
|
||||
|
||||
ORACLE = Path(os.environ.get('HORIZON_STRUCTURE_ORACLE', lab.LOCAL / 'structure-oracle'))
|
||||
JARS = Path(os.environ.get('HORIZON_STRUCTURE_JARS', ORACLE / 'jars'))
|
||||
# Per profile: which saved pieces are expected, the mod jars whose data Horizon reads, and the structures
|
||||
# compared (a regex; None: every start that has the pieces).
|
||||
# Per profile: which saved pieces are expected, the mods in the pack (id: jar), those carried, and the
|
||||
# structures compared (a regex; None: every start that has the pieces).
|
||||
PROFILES = {
|
||||
'lithostitched': {'side': 'base_pieces', 'jars': [], 'structures': None},
|
||||
'betterdungeons': {'side': 'pieces', 'jars': ['YungsApi-1.21.1-NeoForge-5.1.9.jar', 'YungsBetterDungeons-1.21.1-NeoForge-5.1.4.jar'],
|
||||
'structures': r'^betterdungeons:(small|skeleton|zombie)_dungeon$'},
|
||||
'lithostitched': {'side': 'base_pieces', 'mods': {}, 'carry': [], 'structures': None},
|
||||
'betterdungeons': {'side': 'pieces', 'mods': {'yungsapi': 'YungsApi-1.21.1-NeoForge-5.1.9.jar',
|
||||
'betterdungeons': 'YungsBetterDungeons-1.21.1-NeoForge-5.1.4.jar'},
|
||||
'carry': ['betterdungeons'], 'structures': r'^betterdungeons:(small|skeleton|zombie)_dungeon$'},
|
||||
**{name: {'side': 'all_starts', 'mods': {'yungsapi': 'YungsApi-1.21.1-NeoForge-5.1.9.jar'},
|
||||
'packs': {'probe': name}, 'carry': ['probe'], 'structures': r'^probe:'}
|
||||
for name in ['yung-probe', 'yung-probe2']},
|
||||
}
|
||||
BUNDLES = {'structure': 'structures', 'structure_set': 'structure_sets', 'template_pool': 'template_pools',
|
||||
'processor_list': 'processor_lists'}
|
||||
@@ -61,7 +72,7 @@ KNOWN = {
|
||||
('lithostitched', 1234, 'minecraft:village_plains', -24, 47): 'no start in 26.3 vanilla (nor in Horizon)',
|
||||
('lithostitched', 1234, 'minecraft:ruined_portal', -16, 51): RUINED_PORTAL,
|
||||
('lithostitched', 42, 'minecraft:ruined_portal', -19, -38): RUINED_PORTAL,
|
||||
('betterdungeons', 1234, 'betterdungeons:small_dungeon', 162, 10): SULFUR_CAVES,
|
||||
('betterdungeons', 1234, 'betterdungeons:small_dungeon', 162, 10): SULFUR_CAVES,
|
||||
('betterdungeons', 42, 'betterdungeons:small_dungeon', -29, -28): SULFUR_CAVES,
|
||||
**{('lithostitched', seed, 'minecraft:trial_chambers', x, z): TRIAL_CHAMBERS
|
||||
for seed, x, z in [(1234, 13, 21), (2, -28, 13), (2, 11, 16), (2, 146, 44), (42, 17, 7), (42, 38, -25)]},
|
||||
@@ -91,20 +102,49 @@ def expected_piece(saved):
|
||||
return piece
|
||||
|
||||
|
||||
def upgrade_states(value):
|
||||
"""1.21.1's block states (`{"Name", "Properties"}`) in 26.3's shape (`{"id", "properties"}`)."""
|
||||
if isinstance(value, list):
|
||||
return [upgrade_states(v) for v in value]
|
||||
if not isinstance(value, dict):
|
||||
return value
|
||||
if 'Name' in value and set(value) <= {'Name', 'Properties'}:
|
||||
return {'id': value['Name'], **({'properties': value['Properties']} if 'Properties' in value else {})}
|
||||
return {k: upgrade_states(v) for k, v in value.items()}
|
||||
# horizon-port-pack's jar census (inventory.json); the carry does not read it.
|
||||
CENSUS = ['blockstates', 'item_models', 'recipes', 'loot_tables', 'tags', 'worldgen', 'structures', 'languages',
|
||||
'textures', 'sounds', 'classes', 'mixin_configs']
|
||||
|
||||
|
||||
def overlay(profile, jars):
|
||||
"""The 26.3 resources plus the jars' structure data, in a folder the probe reads as its resources."""
|
||||
root = lab.LOCAL / 'structure-layout' / profile
|
||||
def pack_jar(work, mod, profile):
|
||||
"""The data pack an oracle profile added to its world, as a jar of mod `mod`."""
|
||||
spec = json.loads((ORACLE / 'profiles' / f'{profile}.json').read_text())
|
||||
files = {**spec['config_files'], **{path: base64.b64decode(data) for path, data in spec.get('binary_files', {}).items()}}
|
||||
jar = work / f'{mod}.jar'
|
||||
with zipfile.ZipFile(jar, 'w') as z:
|
||||
for path, content in files.items():
|
||||
parts = Path(path).parts
|
||||
if parts[:2] == ('world', 'datapacks') and len(parts) > 3:
|
||||
z.writestr(str(Path(*parts[3:])), content)
|
||||
return jar
|
||||
|
||||
|
||||
def carry(profile, mods, carried, packs=None):
|
||||
"""`horizon-port-pack carry` of the profile's mods and packs; the carried mods' data folders."""
|
||||
work = lab.LOCAL / 'structure-layout' / profile / 'work'
|
||||
shutil.rmtree(work, ignore_errors=True)
|
||||
work.mkdir(parents=True)
|
||||
mods = {key: str(JARS / jar) for key, jar in mods.items()}
|
||||
mods.update({key: str(pack_jar(work, key, name)) for key, name in (packs or {}).items()})
|
||||
records = [{'key': key, 'name': key, 'version': '', 'path': jar, 'tier': 'data', 'confidence': 'known',
|
||||
'class': 'content' if key in carried else 'library', 'source': 'file', 'license': '',
|
||||
'client': '', 'server': '', 'depends': [], 'layer': 0, 'jar': jar,
|
||||
'info': {'mod_id': key, 'name': key, 'version': '', 'license': '', 'depends': [],
|
||||
'census': dict.fromkeys(CENSUS, 0)}}
|
||||
for key, jar in mods.items()]
|
||||
(work / 'inventory.json').write_text(json.dumps(records))
|
||||
subprocess.run(['cargo', 'run', '--release', '-q', '-p', 'horizon-port-pack', '--', 'carry', str(work),
|
||||
'--resources', str(lab.RESOURCES), *carried], check=True, cwd=lab.ROOT, stdout=subprocess.DEVNULL)
|
||||
data = [work / 'mods' / key / 'carry' / 'data' for key in carried]
|
||||
if not all(d.is_dir() for d in data):
|
||||
raise SystemExit(f'horizon-port-pack carried nothing into {work / "mods"}')
|
||||
return data
|
||||
|
||||
|
||||
def overlay(profile, data_dirs):
|
||||
"""The 26.3 resources plus the carried structure data, in a folder the probe reads as its resources."""
|
||||
root = lab.LOCAL / 'structure-layout' / profile / 'resources'
|
||||
shutil.rmtree(root, ignore_errors=True)
|
||||
worldgen = root / 'worldgen'
|
||||
(worldgen / 'structure').mkdir(parents=True)
|
||||
@@ -116,28 +156,24 @@ def overlay(profile, jars):
|
||||
(worldgen / entry.name).symlink_to(entry)
|
||||
for namespace in (source / 'structure').iterdir():
|
||||
(worldgen / 'structure' / namespace.name).symlink_to(namespace)
|
||||
for jar in jars:
|
||||
with zipfile.ZipFile(JARS / jar) as archive:
|
||||
for name in archive.namelist():
|
||||
parts = name.split('/')
|
||||
if parts[0] != 'data' or len(parts) < 4 or name.endswith('/'):
|
||||
continue
|
||||
namespace, kind = parts[1], parts[2]
|
||||
if kind == 'structure' and name.endswith('.nbt'):
|
||||
target = worldgen / 'structure' / namespace / '/'.join(parts[3:])
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(archive.read(name))
|
||||
elif name.endswith('.json') and kind == 'worldgen' and parts[3] in BUNDLES:
|
||||
value = upgrade_states(json.loads(archive.read(name)))
|
||||
if parts[3] == 'processor_list':
|
||||
value['processors'] = [p for p in value['processors'] if p['processor_type'].startswith('minecraft:')]
|
||||
merged[BUNDLES[parts[3]]][f'{namespace}:' + '/'.join(parts[4:])[:-5]] = json.dumps(value)
|
||||
elif name.endswith('.json') and parts[2:5] == ['tags', 'worldgen', 'biome']:
|
||||
tag = f'{namespace}:' + '/'.join(parts[5:])[:-5]
|
||||
value = json.loads(archive.read(name))
|
||||
if tag in merged['biome_tags'] and not value.get('replace'):
|
||||
value['values'] = json.loads(merged['biome_tags'][tag])['values'] + value['values']
|
||||
merged['biome_tags'][tag] = json.dumps(value)
|
||||
for data in data_dirs:
|
||||
for path in sorted(p for p in data.rglob('*') if p.is_file()):
|
||||
parts = path.relative_to(data).parts
|
||||
if len(parts) < 3:
|
||||
continue
|
||||
namespace, kind = parts[0], parts[1]
|
||||
if kind == 'structure' and path.suffix == '.nbt':
|
||||
target = worldgen / 'structure' / namespace / Path(*parts[2:])
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.symlink_to(path)
|
||||
elif path.suffix == '.json' and kind == 'worldgen' and parts[2] in BUNDLES:
|
||||
merged[BUNDLES[parts[2]]][f'{namespace}:' + '/'.join(parts[3:])[:-5]] = path.read_text()
|
||||
elif path.suffix == '.json' and parts[1:4] == ('tags', 'worldgen', 'biome'):
|
||||
tag = f'{namespace}:' + '/'.join(parts[4:])[:-5]
|
||||
value = json.loads(path.read_text())
|
||||
if tag in merged['biome_tags'] and not value.get('replace'):
|
||||
value['values'] = json.loads(merged['biome_tags'][tag])['values'] + value['values']
|
||||
merged['biome_tags'][tag] = json.dumps(value)
|
||||
for name, bundle in merged.items():
|
||||
(worldgen / f'{name}.json').write_text(json.dumps(bundle))
|
||||
return root
|
||||
@@ -179,6 +215,15 @@ def compare(expected, actual):
|
||||
return None
|
||||
|
||||
|
||||
def census_starts(oracle):
|
||||
"""The oracle's census of every start (`all_starts`), as `structures` entries with their `all_starts`."""
|
||||
for chunk in oracle['all_starts']:
|
||||
for start in chunk['starts']:
|
||||
if 'children' in start:
|
||||
yield {'id': start['id'], 'dimension': chunk['dimension'], 'start_chunk': chunk['chunk'],
|
||||
'all_starts': start['children']}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
parser.add_argument('--profile', default='lithostitched', choices=sorted(PROFILES))
|
||||
@@ -190,18 +235,23 @@ def main():
|
||||
print(f'SKIP: no oracle results in {ORACLE / args.profile} (see this file\'s docstring)')
|
||||
return 0
|
||||
profile = PROFILES[args.profile]
|
||||
missing = [jar for jar in profile['jars'] if not (JARS / jar).exists()]
|
||||
missing = [str(JARS / jar) for jar in profile['mods'].values() if not (JARS / jar).exists()]
|
||||
missing += [str(ORACLE / 'profiles' / f'{name}.json') for name in profile.get('packs', {}).values()
|
||||
if not (ORACLE / 'profiles' / f'{name}.json').exists()]
|
||||
if missing:
|
||||
print(f'SKIP: mod jars not in {JARS}: {", ".join(missing)}')
|
||||
print(f'SKIP: not found: {", ".join(missing)}')
|
||||
return 0
|
||||
resources = overlay(args.profile, profile['jars']) if profile['jars'] else lab.RESOURCES
|
||||
resources = lab.RESOURCES
|
||||
if profile['carry']:
|
||||
data = carry(args.profile, profile['mods'], profile['carry'], profile.get('packs'))
|
||||
resources = overlay(args.profile, data)
|
||||
binary = probe_binary()
|
||||
matched, known, failed = 0, 0, []
|
||||
for path in results:
|
||||
oracle = json.load(gzip.open(path))
|
||||
seed = oracle['seed']
|
||||
by_dimension = {}
|
||||
for start in oracle['structures']:
|
||||
for start in oracle['structures'] if profile['side'] != 'all_starts' else census_starts(oracle):
|
||||
if start.get(profile['side']) is None or not re.search(args.filter, start['id']) \
|
||||
or not re.search(profile['structures'] or '', start['id']):
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user