From a9ad185287ca9e369bdb3a02f0da537cf56f0757 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 18 Oct 2026 22:45:28 +0200 Subject: [PATCH] Lithostitched's block swaps, with the properties both blocks have ChoiceTheorem's Overhauled Village swaps blocks in its templates through Lithostitched's block_swap processor (137 lists): a map of block to block, the new one taking Block.withPropertiesOf the old state, and the block left alone when the new one is not registered. Carry dropped it. - Game: horizon:block_swap, the same map; the new block's default state with each property of the old one it has too (by name, when the value is one of its own). - Carry: lithostitched:block_swap becomes it. ATM10: processors carried 136 -> 273 of 1,427 (dropped 1,291 -> 1,154). Co-Authored-By: Claude Opus 5.5 --- crates/horizon-port-pack/src/processors.rs | 23 ++++++ .../src/worldgen/structure/processor.rs | 82 +++++++++++++++++++ docs/modpacks.md | 8 +- 3 files changed, 111 insertions(+), 2 deletions(-) diff --git a/crates/horizon-port-pack/src/processors.rs b/crates/horizon-port-pack/src/processors.rs index 818e5db14..39fc2ef33 100644 --- a/crates/horizon-port-pack/src/processors.rs +++ b/crates/horizon-port-pack/src/processors.rs @@ -241,6 +241,11 @@ fn as_data(kind: &str, p: &Value, data: &ProcessorData) -> Option> { { vec![processor] } + "lithostitched:block_swap" => { + // The same map; the game's swap keeps the properties both have. + p["blocks"].as_object()?; + vec![json!({"processor_type": "horizon:block_swap", "blocks": p["blocks"]})] + } "betterdungeons:small_dungeon_chest_processor" => { // Its config's defaults: one chest at least, two at most, a // fifth of the others kept until then; ChestBlock covers both. @@ -896,4 +901,22 @@ mod tests { ); assert_eq!(cap["replacement"], json!({"id": "minecraft:cave_air"})); } + + #[test] + fn lithostitched_block_swaps_become_the_games() { + let mut list = json!({"processors": [ + {"processor_type": "lithostitched:block_swap", + "blocks": {"minecraft:cobblestone": "minecraft:mossy_cobblestone"}}, + {"processor_type": "lithostitched:block_swap", "blocks": []}]}); + let mut carried = BTreeMap::new(); + assert!(carry("processor_list", &mut list, &data(), &mut carried)); + let p = list["processors"].as_array().unwrap(); + assert_eq!( + p[0], + json!({"processor_type": "horizon:block_swap", + "blocks": {"minecraft:cobblestone": "minecraft:mossy_cobblestone"}}) + ); + // A map that is not one stays Java (dropped later). + assert_eq!(p[1]["processor_type"], "lithostitched:block_swap"); + } } diff --git a/crates/horizon-world/src/worldgen/structure/processor.rs b/crates/horizon-world/src/worldgen/structure/processor.rs index 922664cba..4be7a07aa 100644 --- a/crates/horizon-world/src/worldgen/structure/processor.rs +++ b/crates/horizon-world/src/worldgen/structure/processor.rs @@ -184,6 +184,9 @@ pub enum Processor { SpawnerMobs(Box), Pick(Box), CountCap(Box), + /// `horizon:block_swap` (Lithostitched's `block_swap`): blocks by name + /// become others, keeping the properties both have. + BlockSwap(std::collections::BTreeMap), } #[derive(Clone, Debug, Default)] pub struct ProcessorList(pub Vec); @@ -622,6 +625,20 @@ impl Processor { })?)) } "horizon:pick" => Self::Pick(Box::new(Pick::decode(value, state)?)), + "horizon:block_swap" => Self::BlockSwap( + value["blocks"] + .as_object() + .ok_or(DecodeError::Field("blocks"))? + .iter() + .map(|(from, to)| { + let to = to.as_str().ok_or(DecodeError::Field("blocks"))?; + Ok(( + super::super::tags::identifier(from)?.to_string(), + super::super::tags::identifier(to)?.to_string(), + )) + }) + .collect::>()?, + ), "horizon:count_cap" => Self::CountCap(Box::new(CountCap::decode(value, state)?)), _ => return Err(DecodeError::Field("structure processor type")), }) @@ -714,6 +731,30 @@ impl<'a> PlaceSettings<'a> { } } +/// Block.withPropertiesOf: `block`'s default state with each property of +/// `from` it has too (by name, when the value is one of its own). None for +/// a block the registry does not know (the mod keeps the block then). +fn with_properties_of( + registry: &crate::registry::BlockRegistry, + block: &str, + from: BlockStateId, +) -> Option { + let default = registry.default_state(block)?; + let mut state = registry.state(default)?.clone(); + for (key, value) in ®istry.state(from)?.properties { + if let Some(own) = state.properties.get(key) + && own != value + { + let mut changed = state.clone(); + changed.properties.insert(key.clone(), value.clone()); + if registry.id(&changed).is_some() { + state = changed; + } + } + } + registry.id(&state) +} + /// BlackstoneReplaceProcessor's block map. fn blackstone(name: &str) -> Option<&'static str> { Some(match name.strip_prefix("minecraft:")? { @@ -890,6 +931,15 @@ fn process_block( Some(info) } Processor::Capped { .. } => Some(info), + Processor::BlockSwap(blocks) => { + let swapped = blocks + .get(name(info.state)) + .and_then(|to| with_properties_of(registry, to, info.state)); + Some(match swapped { + Some(state) => BlockInfo { state, ..info }, + None => info, + }) + } Processor::CountCap(cap) => match cap.blocks.contains(name(info.state)) { true => { let pos = info.pos; @@ -1712,4 +1762,36 @@ mod tests { CountCap::decode(&json!({"blocks": [], "min": -1}), |_| Ok(BlockStateId(5))).is_err() ); } + + #[test] + fn block_swaps_keep_the_properties_both_blocks_have() { + let row = |name: &str, props: Value| json!([name, false, false, "", {"id": name, "properties": props}]); + let facts = json!({"defaults": {"a:log": 1, "a:stairs": 4, "a:stone": 6}, + "states": [ + row("a:log", json!({"axis": "x"})), row("a:log", json!({"axis": "y"})), + row("a:stairs", json!({"facing": "east", "half": "top"})), + row("a:stairs", json!({"facing": "east", "half": "bottom"})), + row("a:stairs", json!({"facing": "north", "half": "bottom"})), + row("a:stairs", json!({"facing": "north", "half": "top"})), + ["a:stone", false, false, "", "a:stone"]]}); + let registry = + crate::registry::BlockRegistry::from_facts_json(facts.to_string().as_bytes()).unwrap(); + // facing and half carried over; the default where `from` has none. + assert_eq!( + with_properties_of(®istry, "a:stairs", BlockStateId(2)), + Some(BlockStateId(2)) + ); + assert_eq!( + with_properties_of(®istry, "a:stairs", BlockStateId(0)), + Some(BlockStateId(4)) + ); + assert_eq!( + with_properties_of(®istry, "a:stone", BlockStateId(5)), + Some(BlockStateId(6)) + ); + assert_eq!( + with_properties_of(®istry, "a:missing", BlockStateId(0)), + None + ); + } } diff --git a/docs/modpacks.md b/docs/modpacks.md index b6daee867..faca959b9 100644 --- a/docs/modpacks.md +++ b/docs/modpacks.md @@ -461,8 +461,12 @@ Two cases the oracle fills in: mod. Better Dungeons' small dungeons keep one chest and each other one with a fifth's chance, two at most (the game's `horizon:count_cap`, counted per placement as the mod's DungeonContext is): 12 chests in five small dungeons at seed 1234 become 6. - 136 of the 1,427 processors are carried; 1,291 are still taken out (blocks swapped, aged - or propped up). + Lithostitched's `block_swap` (137 lists, all in ChoiceTheorem's Overhauled Village) is the + game's `horizon:block_swap`: the same map, with Block.withPropertiesOf's properties kept; + a target block the game does not have (most of them are Nature's Spirit's and Croptopia's) + leaves the block as it is, as the mod does. 273 of the 1,427 processors are carried; 1,154 + are still taken out (Formations' biome replacements, Repurposed's pillars and fluid fixes, + Lithostitched's reference, condition and apply_random, blocks aged or propped up). 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