Merge pull request #932 from ludovic111/feat/lithostitched-block-swap
🤖 Agent: reviewed; verify passes. Main merged into the stack (processors.rs tests kept from both sides; port-pack tests pass on each layer, clippy clean). Parity: all 269 game-side harnesses on modpacks-8's integration commit, structure-start oracle 35/35.
This commit is contained in:
@@ -284,6 +284,11 @@ fn as_data(kind: &str, p: &Value, data: &ProcessorData) -> Option<Vec<Value>> {
|
||||
{
|
||||
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.
|
||||
@@ -940,6 +945,24 @@ 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");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repurposed_rule_tests_become_the_games() {
|
||||
let rule = |input: Value, position: Value| {
|
||||
|
||||
@@ -288,6 +288,9 @@ pub enum Processor {
|
||||
SpawnerMobs(Box<SpawnerMobs>),
|
||||
Pick(Box<Pick>),
|
||||
CountCap(Box<CountCap>),
|
||||
/// `horizon:block_swap` (Lithostitched's `block_swap`): blocks by name
|
||||
/// become others, keeping the properties both have.
|
||||
BlockSwap(std::collections::BTreeMap<String, String>),
|
||||
}
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct ProcessorList(pub Vec<Processor>);
|
||||
@@ -726,6 +729,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::<Result<_, DecodeError>>()?,
|
||||
),
|
||||
"horizon:count_cap" => Self::CountCap(Box::new(CountCap::decode(value, state)?)),
|
||||
_ => return Err(DecodeError::Field("structure processor type")),
|
||||
})
|
||||
@@ -818,6 +835,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<BlockStateId> {
|
||||
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:")? {
|
||||
@@ -961,6 +1002,15 @@ fn process_block<W: PlacementContext>(
|
||||
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;
|
||||
@@ -1819,4 +1869,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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user