Merge pull request #909 from ludovic111/feat/carry-spawner-processors
🤖 Agent: reviewed; verify passes. Parity: 298/298 harnesses on the integration commit 234bd101 (main + #907/#908/#910); vanilla structure-start oracle 35/35 with all five modpacks-7 changes. Merged in the required order #907 → #908 → #909 → #910 → #911.
This commit is contained in:
@@ -367,6 +367,7 @@ pub fn carry(
|
||||
let mut biome_conventions = BTreeSet::new();
|
||||
let set_tags = crate::worldgen::structure_set_tags(&mut zip);
|
||||
let piece_counts = crate::worldgen::piece_counts(&mut zip);
|
||||
let processor_data = crate::processors::ProcessorData::read(&mut zip);
|
||||
for i in 0..zip.len() {
|
||||
let mut entry = zip.by_index(i).map_err(|e| e.to_string())?;
|
||||
let name = entry.name().to_owned();
|
||||
@@ -426,12 +427,15 @@ pub fn carry(
|
||||
if kind == "structure" {
|
||||
crate::worldgen::convention_tags(&v["biomes"], &mut biome_conventions);
|
||||
}
|
||||
let mut changed = crate::worldgen::upgrade(
|
||||
let types = &mut report.worldgen_types;
|
||||
let carried = crate::processors::carry(
|
||||
kind,
|
||||
&mut v,
|
||||
&mut report.worldgen_types,
|
||||
&set_tags,
|
||||
&processor_data,
|
||||
&mut types.processors_carried,
|
||||
);
|
||||
let mut changed =
|
||||
crate::worldgen::upgrade(kind, &mut v, types, &set_tags) || carried;
|
||||
if kind == "structure" {
|
||||
let path = rel.trim_start_matches("worldgen/structure/");
|
||||
let structure = format!("{id}:{}", path.trim_end_matches(".json"));
|
||||
@@ -453,6 +457,12 @@ pub fn carry(
|
||||
if let Some((kind, mut added)) =
|
||||
modifier.and_then(|v| crate::worldgen::modifier(&v, loaded, types))
|
||||
{
|
||||
crate::processors::carry(
|
||||
kind,
|
||||
&mut added,
|
||||
&processor_data,
|
||||
&mut types.processors_carried,
|
||||
);
|
||||
crate::worldgen::upgrade(kind, &mut added, types, &set_tags);
|
||||
let to = format!(
|
||||
"data/{id}/worldgen/{kind}/{}/{path}",
|
||||
|
||||
@@ -14,5 +14,6 @@ pub mod jar;
|
||||
pub mod modrinth;
|
||||
pub mod oracle;
|
||||
pub mod pipeline;
|
||||
pub mod processors;
|
||||
pub mod report;
|
||||
pub mod worldgen;
|
||||
|
||||
@@ -0,0 +1,505 @@
|
||||
//! Structure processors the structure libraries write in Java, carried over
|
||||
//! as data the game runs: the ones that give spawners their mob.
|
||||
//!
|
||||
//! - Moog's Structure Lib's and Repurposed Structures' spawner randomizing
|
||||
//! processors pick a mob from a weighted list for each spawner. They become
|
||||
//! `horizon:spawner_mobs` (`horizon_world::worldgen::structure::processor`),
|
||||
//! with Repurposed's `rs_spawners` list written in.
|
||||
//! - YUNG's Better Dungeons and Better Desert Temples turn a spawner or a
|
||||
//! placeholder block into a spawner of a fixed mob. That is vanilla's `rule`
|
||||
//! processor with an `append_static` block entity.
|
||||
//! - Moog's vanilla loot swap only acts when its mod's "replace vanilla"
|
||||
//! preset is on; one that ships off is a no-op and is taken out.
|
||||
//!
|
||||
//! 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 serde_json::{Value, json};
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
io::{Read, Seek},
|
||||
};
|
||||
|
||||
/// What the processors read from the mod's own data files.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ProcessorData {
|
||||
/// Repurposed Structures' `rs_spawners/<path>.json` by id: each mob and
|
||||
/// its weight, without the weight-0 entries its loader removes.
|
||||
pub spawners: BTreeMap<String, Vec<(String, f64)>>,
|
||||
/// Moog's "replace vanilla" presets that are on by default:
|
||||
/// `(mod id, vanilla_key)`.
|
||||
pub replace_vanilla: BTreeSet<(String, String)>,
|
||||
}
|
||||
|
||||
impl ProcessorData {
|
||||
pub fn read<R: Read + Seek>(zip: &mut zip::ZipArchive<R>) -> Self {
|
||||
let mut out = Self::default();
|
||||
for i in 0..zip.len() {
|
||||
let Ok(mut entry) = zip.by_index(i) else {
|
||||
continue;
|
||||
};
|
||||
let name = entry.name().to_owned();
|
||||
let Some((ns, rest)) = name
|
||||
.strip_prefix("data/")
|
||||
.and_then(|r| r.strip_suffix(".json"))
|
||||
.and_then(|r| r.split_once('/'))
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let spawners = rest.strip_prefix("rs_spawners/");
|
||||
if spawners.is_none() && rest != "moogs_structures/replace_vanilla" {
|
||||
continue;
|
||||
}
|
||||
let mut text = String::new();
|
||||
let Ok(v) = entry
|
||||
.read_to_string(&mut text)
|
||||
.map_err(|_| ())
|
||||
.and_then(|_| serde_json::from_str::<Value>(&text).map_err(|_| ()))
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
if let Some(path) = spawners {
|
||||
let mobs = v["mobs"]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|m| Some((m["name"].as_str()?.to_owned(), m["weight"].as_f64()?)))
|
||||
.filter(|(_, w)| *w != 0.)
|
||||
.collect();
|
||||
out.spawners.insert(format!("{ns}:{path}"), mobs);
|
||||
continue;
|
||||
}
|
||||
for preset in v["presets"].as_array().into_iter().flatten() {
|
||||
if preset["default_enabled"].as_bool() != Some(true) {
|
||||
continue;
|
||||
}
|
||||
for r in preset["replacements"].as_array().into_iter().flatten() {
|
||||
if let Some(key) = r["vanilla_key"].as_str() {
|
||||
out.replace_vanilla.insert((ns.to_owned(), key.to_owned()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
/// Calls `f` on each processor list in a worldgen file: a `processor_list`
|
||||
/// file, and the inline lists of a template pool's elements (list elements
|
||||
/// included). Whether any call changed something.
|
||||
pub fn each_list(kind: &str, v: &mut Value, f: &mut dyn FnMut(&mut Value) -> bool) -> bool {
|
||||
match kind {
|
||||
"processor_list" => f(v),
|
||||
"template_pool" => {
|
||||
let mut changed = false;
|
||||
for e in v["elements"].as_array_mut().into_iter().flatten() {
|
||||
let element = &mut e["element"];
|
||||
if let Some(list) = element.get_mut("elements").and_then(Value::as_array_mut) {
|
||||
for inner in list {
|
||||
if let Some(p) = inner.get_mut("processors") {
|
||||
changed |= f(p);
|
||||
}
|
||||
}
|
||||
} else if let Some(p) = element.get_mut("processors") {
|
||||
changed |= f(p);
|
||||
}
|
||||
}
|
||||
changed
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The processors of a list: `{"processors": [...]}` or a bare list (an id
|
||||
/// names another file and is left alone).
|
||||
pub fn processors(list: &mut Value) -> Option<&mut Vec<Value>> {
|
||||
match list {
|
||||
Value::Array(a) => Some(a),
|
||||
Value::Object(o) => o.get_mut("processors").and_then(Value::as_array_mut),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Rewrites the processors of a worldgen file that have a data form; each is
|
||||
/// counted by type in `carried`. Whether anything changed.
|
||||
pub fn carry(
|
||||
kind: &str,
|
||||
v: &mut Value,
|
||||
data: &ProcessorData,
|
||||
carried: &mut BTreeMap<String, usize>,
|
||||
) -> bool {
|
||||
each_list(kind, v, &mut |list| {
|
||||
let Some(list) = processors(list) else {
|
||||
return false;
|
||||
};
|
||||
let mut changed = false;
|
||||
let mut out = Vec::with_capacity(list.len());
|
||||
for p in list.drain(..) {
|
||||
let kind = p["processor_type"].as_str().unwrap_or_default().to_owned();
|
||||
match as_data(&kind, &p, data) {
|
||||
Some(replacement) => {
|
||||
*carried.entry(kind).or_default() += 1;
|
||||
out.extend(replacement);
|
||||
changed = true;
|
||||
}
|
||||
None => out.push(p),
|
||||
}
|
||||
}
|
||||
*list = out;
|
||||
changed
|
||||
})
|
||||
}
|
||||
|
||||
/// The data form of a Java processor: the processors to put in its place
|
||||
/// (none for a no-op), or `None` when it has none.
|
||||
fn as_data(kind: &str, p: &Value, data: &ProcessorData) -> Option<Vec<Value>> {
|
||||
let (ns, _) = kind.split_once(':')?;
|
||||
Some(match kind {
|
||||
"moogs_structures:spawner_randomizing_processor" => {
|
||||
let mobs = p["weighted_entities"]
|
||||
.as_array()?
|
||||
.iter()
|
||||
.map(|e| {
|
||||
// The entry's NBT, then its id over it.
|
||||
let mut entity = match &e["nbt"] {
|
||||
Value::Object(o) => o.clone(),
|
||||
_ => serde_json::Map::new(),
|
||||
};
|
||||
entity.insert("id".into(), e["entity"].as_str()?.into());
|
||||
Some(json!({"entity": entity, "weight": e["weight"].as_f64()?}))
|
||||
})
|
||||
.collect::<Option<Vec<_>>>()?;
|
||||
vec![spawner_mobs(p, mobs, None)]
|
||||
}
|
||||
"repurposed_structures:spawner_randomizing_processor" => {
|
||||
// A list the mod does not ship falls back to a vanilla dungeon
|
||||
// mob in the mod; left out here.
|
||||
let list = data
|
||||
.spawners
|
||||
.get(p["rs_spawner_resourcelocation"].as_str()?)?;
|
||||
let mobs = list
|
||||
.iter()
|
||||
.map(|(id, weight)| json!({"entity": {"id": id}, "weight": weight}))
|
||||
.collect();
|
||||
vec![spawner_mobs(p, mobs, repurposed_light(p)?)]
|
||||
}
|
||||
"moogs_structures:vanilla_loot_swap_processor" => {
|
||||
let key = (
|
||||
p["modid"].as_str()?.to_owned(),
|
||||
p["vanilla_key"].as_str()?.to_owned(),
|
||||
);
|
||||
if data.replace_vanilla.contains(&key) {
|
||||
return None;
|
||||
}
|
||||
Vec::new()
|
||||
}
|
||||
_ if ns == "betterdungeons" || ns == "betterdeserttemples" => vec![yung_spawner(kind, p)?],
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// [`as_data`]'s `horizon:spawner_mobs` for the mods' spawner randomizing
|
||||
/// processors, whose fields have the same names and defaults.
|
||||
fn spawner_mobs(p: &Value, mobs: Vec<Value>, rules: Option<Value>) -> Value {
|
||||
let mut out = json!({"processor_type": "horizon:spawner_mobs", "mobs": mobs});
|
||||
for key in [
|
||||
"delay",
|
||||
"min_spawn_delay",
|
||||
"max_spawn_delay",
|
||||
"spawn_count",
|
||||
"max_nearby_entities",
|
||||
"required_player_range",
|
||||
"spawn_range",
|
||||
] {
|
||||
if let Some(n) = p.get(key).filter(|n| n.is_i64()) {
|
||||
out[key] = n.clone();
|
||||
}
|
||||
}
|
||||
if let Some(r) = rules {
|
||||
out["custom_spawn_rules"] = r;
|
||||
}
|
||||
if let Some(b) = p.get("spawner_replacement_block") {
|
||||
out["replacement"] = b.clone();
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Repurposed Structures' `custom_spawn_rules` from its light level ranges:
|
||||
/// `Some(None)` without either, `None` when one does not read. The sky
|
||||
/// light's upper bound is written as `max_exclusive`, as the mod does.
|
||||
fn repurposed_light(p: &Value) -> Option<Option<Value>> {
|
||||
let range = |key: &str| -> Option<Option<(i64, i64)>> {
|
||||
match p.get(key) {
|
||||
None => Some(None),
|
||||
Some(Value::Number(n)) => n.as_i64().map(|n| Some((n, n))),
|
||||
Some(v) => Some(Some((
|
||||
v["min_inclusive"].as_i64()?,
|
||||
v["max_inclusive"].as_i64()?,
|
||||
))),
|
||||
}
|
||||
};
|
||||
let (block, sky) = (
|
||||
range("valid_block_light_level")?,
|
||||
range("valid_sky_light_level")?,
|
||||
);
|
||||
if block.is_none() && sky.is_none() {
|
||||
return Some(None);
|
||||
}
|
||||
let mut rules = json!({});
|
||||
if let Some((min, max)) = block {
|
||||
rules["block_light_limit"] = json!({"min_inclusive": min, "max_inclusive": max});
|
||||
}
|
||||
if let Some((min, max)) = sky {
|
||||
rules["sky_light_limit"] = json!({"min_inclusive": min, "max_exclusive": max});
|
||||
}
|
||||
Some(Some(rules))
|
||||
}
|
||||
|
||||
/// An item as 26.3 saves it.
|
||||
fn item(id: &str) -> Value {
|
||||
json!({"id": format!("minecraft:{id}"), "count": 1})
|
||||
}
|
||||
|
||||
/// YUNG's processors that make a spawner of a fixed mob (YUNG's API's
|
||||
/// `MobSpawnerData`), as vanilla's `rule`: every `input` block becomes a
|
||||
/// spawner with that NBT.
|
||||
fn yung_spawner(kind: &str, p: &Value) -> Option<Value> {
|
||||
const SPAWNER: &str = "minecraft:spawner";
|
||||
// (input block, mob, fields other than the defaults, whether the mob is
|
||||
// also the only potential, its equipment)
|
||||
let (input, mob, fields, potential, equipment): (_, _, &[(&str, i64)], _, _) = match kind {
|
||||
"betterdungeons:mob_spawner_processor" => {
|
||||
(SPAWNER, p["spawner_mob"].as_str()?, &[], true, None)
|
||||
}
|
||||
"betterdungeons:zombie_mob_spawner_processor" => (
|
||||
SPAWNER,
|
||||
"minecraft:zombie",
|
||||
&[("MaxNearbyEntities", 8)],
|
||||
true,
|
||||
None,
|
||||
),
|
||||
"betterdungeons:skeleton_mob_spawner_processor" => (
|
||||
SPAWNER,
|
||||
"minecraft:skeleton",
|
||||
&[
|
||||
("RequiredPlayerRange", 18),
|
||||
("MaxNearbyEntities", 8),
|
||||
("MaxSpawnDelay", 650),
|
||||
],
|
||||
true,
|
||||
None,
|
||||
),
|
||||
"betterdungeons:small_nether_dungeon_mob_spawner_processor" => {
|
||||
let mob = p["spawner_mob"].as_str()?;
|
||||
// Wither skeletons get netherite armor that never drops and a
|
||||
// stone sword (with the mod's default config, they and blazes
|
||||
// keep their loot).
|
||||
let armor = (mob == "minecraft:wither_skeleton").then(|| {
|
||||
json!({
|
||||
"equipment": {
|
||||
"feet": item("netherite_boots"),
|
||||
"legs": item("netherite_leggings"),
|
||||
"chest": item("netherite_chestplate"),
|
||||
"head": item("netherite_helmet"),
|
||||
"mainhand": item("stone_sword"),
|
||||
},
|
||||
"drop_chances": {"feet": 0.0, "legs": 0.0, "chest": 0.0, "head": 0.0},
|
||||
})
|
||||
});
|
||||
(SPAWNER, mob, &[], true, armor)
|
||||
}
|
||||
"betterdungeons:zombie_tombstone_spawner_processor" => (
|
||||
"minecraft:black_stained_glass",
|
||||
"minecraft:skeleton",
|
||||
&[],
|
||||
false,
|
||||
Some(json!({"equipment": {"mainhand": item("iron_sword")}})),
|
||||
),
|
||||
"betterdeserttemples:gravel_processor" => (
|
||||
"minecraft:gravel",
|
||||
"minecraft:husk",
|
||||
&[("MaxNearbyEntities", 8), ("RequiredPlayerRange", 24)],
|
||||
false,
|
||||
None,
|
||||
),
|
||||
// An empty hand list in 1.21.1: the skeletons spawn without a bow,
|
||||
// since a spawn entry with more than its id is not finalized.
|
||||
"betterdeserttemples:bone_block_processor" => (
|
||||
"minecraft:bone_block",
|
||||
"minecraft:skeleton",
|
||||
&[("RequiredPlayerRange", 32)],
|
||||
false,
|
||||
Some(json!({"equipment": {}})),
|
||||
),
|
||||
"betterdeserttemples:infested_cracked_stone_bricks_processor" => (
|
||||
"minecraft:infested_cracked_stone_bricks",
|
||||
"minecraft:silverfish",
|
||||
&[("RequiredPlayerRange", 24)],
|
||||
false,
|
||||
None,
|
||||
),
|
||||
// 1.21.1 ignores the items' old `Count` and `tag` (the shield's
|
||||
// pattern, the boots' dye): plain items.
|
||||
"betterdeserttemples:yellow_wool_processor" => (
|
||||
"minecraft:yellow_wool",
|
||||
"minecraft:husk",
|
||||
&[("MaxNearbyEntities", 8), ("RequiredPlayerRange", 24)],
|
||||
false,
|
||||
Some(json!({"equipment": {
|
||||
"mainhand": item("golden_sword"),
|
||||
"offhand": item("shield"),
|
||||
"feet": item("leather_boots"),
|
||||
"legs": item("leather_leggings"),
|
||||
"chest": item("golden_chestplate"),
|
||||
"head": item("chainmail_helmet"),
|
||||
}})),
|
||||
),
|
||||
_ => return None,
|
||||
};
|
||||
let mut entity = json!({"id": mob});
|
||||
if let Some(Value::Object(extra)) = equipment {
|
||||
entity.as_object_mut()?.extend(extra);
|
||||
}
|
||||
let potentials = match potential {
|
||||
true => json!([{"data": {"entity": entity.clone()}, "weight": 1}]),
|
||||
false => json!([]),
|
||||
};
|
||||
let mut nbt = json!({
|
||||
"Delay": 20, "MinSpawnDelay": 200, "MaxSpawnDelay": 800, "SpawnCount": 4,
|
||||
"MaxNearbyEntities": 6, "RequiredPlayerRange": 16, "SpawnRange": 4,
|
||||
"SpawnData": {"entity": entity},
|
||||
"SpawnPotentials": potentials,
|
||||
});
|
||||
for (key, value) in fields {
|
||||
nbt[*key] = (*value).into();
|
||||
}
|
||||
Some(json!({
|
||||
"processor_type": "minecraft:rule",
|
||||
"rules": [{
|
||||
"input_predicate": {"predicate_type": "minecraft:block_match", "block": input},
|
||||
"location_predicate": {"predicate_type": "minecraft:always_true"},
|
||||
"output_state": {"Name": SPAWNER},
|
||||
"block_entity_modifier": {"type": "minecraft:append_static", "data": nbt},
|
||||
}],
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn data() -> ProcessorData {
|
||||
let mut d = ProcessorData::default();
|
||||
d.spawners.insert(
|
||||
"repurposed_structures:dungeons/badlands".into(),
|
||||
vec![
|
||||
("minecraft:husk".into(), 10.),
|
||||
("minecraft:cave_spider".into(), 3.),
|
||||
],
|
||||
);
|
||||
d.replace_vanilla.insert(("mvs".into(), "village".into()));
|
||||
d
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawner_processors_become_data() {
|
||||
let mut list = json!({"processors": [
|
||||
{"processor_type": "moogs_structures:spawner_randomizing_processor",
|
||||
"weighted_entities": [{"entity": "minecraft:blaze", "weight": 2, "nbt": {"Health": 5}}],
|
||||
"spawn_count": 2, "spawner_replacement_block": {"Name": "minecraft:stone"}},
|
||||
{"processor_type": "repurposed_structures:spawner_randomizing_processor",
|
||||
"rs_spawner_resourcelocation": "repurposed_structures:dungeons/badlands",
|
||||
"valid_block_light_level": {"min_inclusive": 0, "max_inclusive": 7}},
|
||||
{"processor_type": "repurposed_structures:spawner_randomizing_processor",
|
||||
"rs_spawner_resourcelocation": "repurposed_structures:missing"},
|
||||
{"processor_type": "minecraft:gravity", "heightmap": "WORLD_SURFACE_WG", "offset": 0},
|
||||
{"processor_type": "moogs_structures:vanilla_loot_swap_processor",
|
||||
"modid": "mns", "vanilla_key": "fortress", "loot_table_mapping": {}},
|
||||
{"processor_type": "moogs_structures:vanilla_loot_swap_processor",
|
||||
"modid": "mvs", "vanilla_key": "village", "loot_table_mapping": {}}]});
|
||||
let mut carried = BTreeMap::new();
|
||||
assert!(carry("processor_list", &mut list, &data(), &mut carried));
|
||||
let p = list["processors"].as_array().unwrap();
|
||||
assert_eq!(p.len(), 5, "{p:#?}");
|
||||
assert_eq!(
|
||||
p[0],
|
||||
json!({"processor_type": "horizon:spawner_mobs",
|
||||
"mobs": [{"entity": {"Health": 5, "id": "minecraft:blaze"}, "weight": 2.0}],
|
||||
"spawn_count": 2, "replacement": {"Name": "minecraft:stone"}})
|
||||
);
|
||||
assert_eq!(
|
||||
p[1],
|
||||
json!({"processor_type": "horizon:spawner_mobs",
|
||||
"mobs": [{"entity": {"id": "minecraft:husk"}, "weight": 10.0},
|
||||
{"entity": {"id": "minecraft:cave_spider"}, "weight": 3.0}],
|
||||
"custom_spawn_rules": {"block_light_limit": {"min_inclusive": 0, "max_inclusive": 7}}})
|
||||
);
|
||||
// Unknown list, vanilla processor, and a swap whose preset is on: kept
|
||||
// (the Java ones are dropped later); the swap that is off is gone.
|
||||
assert_eq!(
|
||||
p[2]["rs_spawner_resourcelocation"],
|
||||
"repurposed_structures:missing"
|
||||
);
|
||||
assert_eq!(p[3]["processor_type"], "minecraft:gravity");
|
||||
assert_eq!(p[4]["modid"], "mvs");
|
||||
assert_eq!(
|
||||
carried,
|
||||
BTreeMap::from([
|
||||
("moogs_structures:spawner_randomizing_processor".into(), 1),
|
||||
("moogs_structures:vanilla_loot_swap_processor".into(), 1),
|
||||
(
|
||||
"repurposed_structures:spawner_randomizing_processor".into(),
|
||||
1
|
||||
),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn yungs_spawners_become_rules() {
|
||||
let mut pool = json!({"elements": [{"element": {"processors": {"processors": [
|
||||
{"processor_type": "betterdungeons:skeleton_mob_spawner_processor"},
|
||||
{"processor_type": "betterdeserttemples:bone_block_processor"},
|
||||
{"processor_type": "betterdungeons:small_nether_dungeon_mob_spawner_processor",
|
||||
"spawner_mob": "minecraft:wither_skeleton"},
|
||||
{"processor_type": "betterdungeons:candle_processor"}]}}}]});
|
||||
let mut carried = BTreeMap::new();
|
||||
assert!(carry("template_pool", &mut pool, &data(), &mut carried));
|
||||
let p = &pool["elements"][0]["element"]["processors"]["processors"];
|
||||
let rule = |i: usize| &p[i]["rules"][0];
|
||||
assert_eq!(rule(0)["input_predicate"]["block"], "minecraft:spawner");
|
||||
assert_eq!(
|
||||
rule(0)["output_state"],
|
||||
json!({"Name": "minecraft:spawner"})
|
||||
);
|
||||
let nbt = &rule(0)["block_entity_modifier"]["data"];
|
||||
assert_eq!(
|
||||
(
|
||||
nbt["RequiredPlayerRange"].clone(),
|
||||
nbt["MaxNearbyEntities"].clone()
|
||||
),
|
||||
(json!(18), json!(8))
|
||||
);
|
||||
assert_eq!(nbt["MaxSpawnDelay"], 650);
|
||||
assert_eq!(
|
||||
nbt["SpawnPotentials"],
|
||||
json!([{"data": {"entity": {"id": "minecraft:skeleton"}}, "weight": 1}])
|
||||
);
|
||||
// Bone blocks become bowless skeleton spawners with no potentials.
|
||||
let bone = &rule(1)["block_entity_modifier"]["data"];
|
||||
assert_eq!(rule(1)["input_predicate"]["block"], "minecraft:bone_block");
|
||||
assert_eq!(
|
||||
bone["SpawnData"],
|
||||
json!({"entity": {"id": "minecraft:skeleton", "equipment": {}}})
|
||||
);
|
||||
assert_eq!(bone["SpawnPotentials"], json!([]));
|
||||
let wither = &rule(2)["block_entity_modifier"]["data"]["SpawnData"]["entity"];
|
||||
assert_eq!(
|
||||
wither["equipment"]["head"]["id"],
|
||||
"minecraft:netherite_helmet"
|
||||
);
|
||||
assert_eq!(wither["drop_chances"]["feet"], 0.0);
|
||||
assert_eq!(p[3]["processor_type"], "betterdungeons:candle_processor");
|
||||
assert_eq!(carried.values().sum::<usize>(), 3);
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,9 @@ pub struct Upgrade {
|
||||
pub rules_lost: BTreeMap<String, usize>,
|
||||
/// Processors written in Java, taken out of their lists, by type.
|
||||
pub processors_dropped: BTreeMap<String, usize>,
|
||||
/// Processors written in Java carried as data the game runs
|
||||
/// ([`crate::processors`]), by type.
|
||||
pub processors_carried: BTreeMap<String, usize>,
|
||||
/// Entries added to other structure sets and template pools
|
||||
/// (`horizon:add_to`), by the set or pool they join.
|
||||
pub added_to: BTreeMap<String, usize>,
|
||||
@@ -332,49 +335,28 @@ pub fn upgrade(
|
||||
) -> bool {
|
||||
let states = block_states(v);
|
||||
report.block_states += usize::from(states);
|
||||
let dropped = match kind {
|
||||
"processor_list" => drop_java_processors(v, &mut report.processors_dropped),
|
||||
"template_pool" => {
|
||||
let mut changed = false;
|
||||
for e in v["elements"].as_array_mut().into_iter().flatten() {
|
||||
let element = &mut e["element"];
|
||||
if let Some(list) = element.get_mut("elements").and_then(Value::as_array_mut) {
|
||||
for inner in list {
|
||||
if let Some(p) = inner.get_mut("processors") {
|
||||
changed |= drop_java_processors(p, &mut report.processors_dropped);
|
||||
}
|
||||
}
|
||||
} else if let Some(p) = element.get_mut("processors") {
|
||||
changed |= drop_java_processors(p, &mut report.processors_dropped);
|
||||
}
|
||||
}
|
||||
changed
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
let dropped = crate::processors::each_list(kind, v, &mut |list| {
|
||||
drop_java_processors(list, &mut report.processors_dropped)
|
||||
});
|
||||
upgrade_types(kind, v, report, set_tags) || states || dropped
|
||||
}
|
||||
|
||||
/// Takes the processors written in Java (any type outside `minecraft:`)
|
||||
/// out of a processor list: `{"processors": [...]}`, a bare list, or an id
|
||||
/// (left as it is). The game, like vanilla, refuses a list holding a type it
|
||||
/// Takes the processors written in Java (any type outside `minecraft:` and
|
||||
/// the game's own `horizon:`) out of a processor list: `{"processors":
|
||||
/// [...]}`, a bare list, or an id (left as it is). The ones with a data form
|
||||
/// were rewritten before ([`crate::processors::carry`]). The game, like vanilla, refuses a list holding a type it
|
||||
/// does not know, and with it every pool that names the list, so without
|
||||
/// this the structure does not generate at all. Without them it generates
|
||||
/// undecorated: no pillars under it, spawners left as the template has
|
||||
/// them, blocks not swapped. Whether anything was taken out.
|
||||
fn drop_java_processors(list: &mut Value, dropped: &mut BTreeMap<String, usize>) -> bool {
|
||||
let processors = match list {
|
||||
Value::Array(a) => a,
|
||||
Value::Object(o) => match o.get_mut("processors") {
|
||||
Some(Value::Array(a)) => a,
|
||||
_ => return false,
|
||||
},
|
||||
_ => return false,
|
||||
let Some(processors) = crate::processors::processors(list) else {
|
||||
return false;
|
||||
};
|
||||
let before = processors.len();
|
||||
processors.retain(|p| {
|
||||
let t = p["processor_type"].as_str().unwrap_or_default();
|
||||
let java = !t.starts_with("minecraft:");
|
||||
let java = !t.starts_with("minecraft:") && !t.starts_with("horizon:");
|
||||
if java {
|
||||
*dropped.entry(t.to_owned()).or_default() += 1;
|
||||
}
|
||||
|
||||
+19
-3
@@ -438,7 +438,23 @@ Two cases the oracle fills in:
|
||||
list. The structures now generate undecorated (no pillars under them, spawners as the
|
||||
template has them); 1,427 processors of 146 types in ATM10's mods, the most common
|
||||
`lithostitched:block_swap`, Formations' `biome_replacements` and Repurposed Structures'
|
||||
pillar, fluid and void processors. Porting the common ones is next.
|
||||
pillar, fluid and void processors.
|
||||
- **Spawner processors** carried as data (`horizon-port-pack/src/processors.rs`). Most
|
||||
chests in the mods' templates already name their loot table; what the Java processors add
|
||||
is the spawners' mobs. Moog's and Repurposed Structures' spawner randomizing processors
|
||||
become `horizon:spawner_mobs` (a weighted mob per spawner, picked with the placement's
|
||||
random as theirs do, and the spawner NBT they write; Repurposed's `rs_spawners` lists are
|
||||
written in). YUNG's Better Dungeons and Better Desert Temples turn a spawner or a
|
||||
placeholder block (gravel, bone block, yellow wool...) into a spawner of a fixed mob: that
|
||||
is vanilla's `rule` processor with an `append_static` block entity. Moog's vanilla loot
|
||||
swap acts only when a "replace vanilla" preset is on, and they ship off. 119 of the 1,427
|
||||
processors are carried; 1,308 are still taken out (blocks swapped, aged or propped up,
|
||||
Moog's trial spawner and vault configs, YUNG's chest caps).
|
||||
In the 128×128-chunk square (seed 1234), every spawner of a mod structure now has its mob:
|
||||
in the Overworld 83 Better Dungeons spawners held the template's placeholder pig and 17 of
|
||||
Moog's were empty (763 spawners with a mob, up from 628); in the Nether the 52 empty ones
|
||||
in Moog's Nether Structures are filled (162, up from 110). Chests are unchanged: 2,777
|
||||
and 1,405 with a loot table.
|
||||
- **Big templates** (#838). Vanilla reads structure templates with no limit on their tag
|
||||
count; Horizon now does too (`nbt::Limits::templates`). Seven of ATM10's 8,962 carried
|
||||
templates are past the old 1,000,000-tag cap: YUNG's monument start, four When Dungeons
|
||||
@@ -487,8 +503,8 @@ Two cases the oracle fills in:
|
||||
- Repurposed's mineshafts, mansions, monuments, Nether cities and shipwrecks, Better
|
||||
Mineshafts and two Better Dungeons types: Java structure types;
|
||||
- YUNG's and Moog's enhanced terrain adaptation, YUNG's piece modifiers and dead-end pools,
|
||||
and the processors written in Java (YUNG's spawners, chests, banners; 29 in Better Dungeons
|
||||
alone), so these structures place their template blocks only;
|
||||
and the block processors written in Java (YUNG's banners, legs and decorations, Repurposed's
|
||||
pillars and fluid fixes, Lithostitched's block swaps);
|
||||
- MO Structures (38; its library is only on CurseForge).
|
||||
|
||||
With every structure PR above, the same square (seed 1234, chunks -64..63) holds 362
|
||||
|
||||
Reference in New Issue
Block a user