diff --git a/crates/horizon-port-pack/src/processors.rs b/crates/horizon-port-pack/src/processors.rs index ca420b6ef..d72053866 100644 --- a/crates/horizon-port-pack/src/processors.rs +++ b/crates/horizon-port-pack/src/processors.rs @@ -202,6 +202,7 @@ fn pillar_type(kind: &str) -> Option<&'static str> { "repurposed_structures:bottom_pillar_processor" => "horizon:bottom_pillar", "repurposed_structures:close_off_fluid_sources_processor" | "moogs_structures:close_off_fluid_sources_processor" => "horizon:close_off_fluid_sources", + "repurposed_structures:close_off_air_sources_processor" => "horizon:close_off_air_sources", "betterfortresses:pillar_processor" | "betterjungletemples:pillar_processor" => { "horizon:yung_pillar" } @@ -1584,6 +1585,8 @@ mod tests { "pillar_processor_list": "minecraft:empty"}), json!({"processor_type": "moogs_structures:close_off_fluid_sources_processor", "weighted_list_of_replacement_blocks": [{"block": "minecraft:stone", "weight": 1}]}), + json!({"processor_type": "repurposed_structures:close_off_air_sources_processor", + "weighted_list_of_replacement_blocks": [{"block": "minecraft:prismarine", "weight": 1}]}), json!({"processor_type": "betterfortresses:pillar_processor", "target_block": {"Name": "minecraft:orange_terracotta"}, "target_block_output": {"defaultBlockState": {"Name": "minecraft:red_nether_bricks"}, "entries": []}, @@ -1604,6 +1607,7 @@ mod tests { "minecraft:block_rot", "horizon:bottom_pillar", "horizon:close_off_fluid_sources", + "horizon:close_off_air_sources", "horizon:yung_pillar", "horizon:stair_pillar" ] @@ -1618,7 +1622,11 @@ mod tests { ); assert_eq!(inner[1]["processor_type"], "minecraft:block_rot"); assert!(p[2].get("pillar_processor_list").is_none()); - assert_eq!(p[5]["pillar"], "minecraft:red_nether_bricks"); + assert_eq!( + 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); } diff --git a/crates/horizon-world/src/worldgen/structure/processor.rs b/crates/horizon-world/src/worldgen/structure/processor.rs index e77ab5a30..5ed2fe3c1 100644 --- a/crates/horizon-world/src/worldgen/structure/processor.rs +++ b/crates/horizon-world/src/worldgen/structure/processor.rs @@ -312,6 +312,9 @@ pub enum Processor { /// `horizon:close_off_fluid_sources` (Repurposed Structures' and Moog's): /// fluid sources beside open blocks are walled off. CloseOffFluidSources(Box), + /// `horizon:close_off_air_sources` (Repurposed Structures'): air and + /// other liquids beside the template's fluids are walled off. + CloseOffAirSources(Box), /// `horizon:yung_pillar` (YUNG's pillars: Better Fortresses, Better /// Jungle Temples). YungPillar(Box), @@ -807,6 +810,9 @@ impl Processor { "horizon:close_off_fluid_sources" => Self::CloseOffFluidSources(Box::new( pillars::CloseOffFluidSources::decode(value, resources, bindings)?, )), + "horizon:close_off_air_sources" => Self::CloseOffAirSources(Box::new( + pillars::CloseOffAirSources::decode(value, resources, bindings)?, + )), "horizon:yung_pillar" => Self::YungPillar(Box::new(pillars::YungPillar::decode( value, bindings, state, )?)), @@ -1191,6 +1197,7 @@ fn process_block( return p.process(world, resources, position, relative, info, settings); } Processor::CloseOffFluidSources(p) => return p.process(world, info, settings), + Processor::CloseOffAirSources(p) => return p.process(world, info, settings), Processor::YungPillar(p) => return p.process(world, resources, info, settings), Processor::StairPillar(p) => return p.process(world, resources, info, settings), Processor::FloodAir(p) => return p.process(world, info), diff --git a/crates/horizon-world/src/worldgen/structure/processor/pillars.rs b/crates/horizon-world/src/worldgen/structure/processor/pillars.rs index 8896e6fcd..e378714f0 100644 --- a/crates/horizon-world/src/worldgen/structure/processor/pillars.rs +++ b/crates/horizon-world/src/worldgen/structure/processor/pillars.rs @@ -5,6 +5,9 @@ //! block (or the template's bottom layer) down to the ground; //! - `horizon:close_off_fluid_sources`: their fluid fix, which walls off the //! water and lava sources around a structure's open blocks; +//! - `horizon:close_off_air_sources`: Repurposed Structures' opposite fix, +//! which walls off the air and other liquids around a structure's fluids +//! (its ocean mineshafts); //! - `horizon:yung_pillar` and `horizon:stair_pillar`: YUNG's pillar //! processor (Better Fortresses, Better Jungle Temples) and Better //! Fortresses' stair supports. @@ -64,6 +67,8 @@ pub struct Blocks { /// Cobweb and bamboo sapling, which never block motion. no_motion: BTreeSet, structure_void: BTreeSet, + /// Water and lava blocks (LiquidBlock), at every level. + liquid_blocks: BTreeSet, } impl Blocks { fn decode(bindings: &FeatureBlockBindings<'_>) -> Result { @@ -89,6 +94,7 @@ impl Blocks { unbreakable: block_set(&UNBREAKABLE), no_motion: block_set(&["minecraft:cobweb", "minecraft:bamboo_sapling"]), structure_void: block_set(&["minecraft:structure_void"]), + liquid_blocks: block_set(&["minecraft:water", "minecraft:lava"]), }) } fn air(&self, state: BlockStateId) -> bool { @@ -96,9 +102,13 @@ impl Blocks { } /// `!getFluidState().isEmpty()`. fn fluid(&self, state: BlockStateId) -> bool { + self.fluid_kind(state) != FluidKind::Empty + } + /// `getFluidState().getType()`: flowing and still fluids are two. + fn fluid_kind(&self, state: BlockStateId) -> FluidKind { self.fluids .get(state) - .is_some_and(|f| f.kind() != FluidKind::Empty) + .map_or(FluidKind::Empty, |f| f.kind()) } /// What a pillar goes through: blocks that cannot occlude, and when /// forced every block that can be broken. @@ -471,24 +481,7 @@ impl CloseOffFluidSources { resources: &StructureResources, bindings: &FeatureBlockBindings<'_>, ) -> Result { - let replacements = v["weighted_list_of_replacement_blocks"] - .as_array() - .ok_or(DecodeError::Field("weighted_list_of_replacement_blocks"))? - .iter() - .map(|e| { - let name = e["block"].as_str().ok_or(DecodeError::Field("block"))?; - let name = crate::worldgen::tags::identifier(name)?; - let state = resources - .registry - .default_state(&name) - .ok_or_else(|| DecodeError::Registry(format!("unknown block {name}")))?; - let weight = e["weight"].as_i64().ok_or(DecodeError::Field("weight"))?; - Ok((state, weight as i32)) - }) - .collect::, DecodeError>>()?; - if replacements.is_empty() { - return Err(DecodeError::Field("weighted_list_of_replacement_blocks")); - } + let replacements = weighted_blocks(v, resources)?; Ok(Self { replacements, ignore_down: v["ignore_down"].as_bool().unwrap_or(false), @@ -529,6 +522,90 @@ impl CloseOffFluidSources { } } +/// `horizon:close_off_air_sources`: Repurposed Structures' +/// CloseOffAirSourcesProcessor. Around each template block holding a fluid, +/// the world's air beside it, and liquid blocks of another fluid (flowing and +/// still count as two), become a block drawn by weight (none drawn for a +/// single block), so the water of its ocean mineshafts does not pour into +/// caves. Neighbours in other chunks are written too, as the mod writes +/// their sections. +#[derive(Clone, Debug)] +pub struct CloseOffAirSources { + replacements: Vec<(BlockStateId, i32)>, + blocks: Blocks, +} +impl CloseOffAirSources { + pub(super) fn decode( + v: &Value, + resources: &StructureResources, + bindings: &FeatureBlockBindings<'_>, + ) -> Result { + Ok(Self { + replacements: weighted_blocks(v, resources)?, + blocks: Blocks::decode(bindings)?, + }) + } + pub(super) fn process( + &self, + world: &mut W, + info: BlockInfo, + settings: &mut PlaceSettings<'_>, + ) -> ProcessResult { + let fluid = self.blocks.fluid_kind(info.state); + if outside_chunk(settings, info.pos) || fluid == FluidKind::Empty { + return Ok(Some(info)); + } + // Direction.values(): down, up, north, south, west, east. + for d in Direction::ALL { + let at = add(info.pos, d); + if world.outside_build_height(at[1])? { + continue; + } + let Some(beside) = world.section_block(at)? else { + continue; + }; + let other_liquid = self.blocks.liquid_blocks.contains(&beside) + && self.blocks.fluid_kind(beside) != fluid; + if self.blocks.air(beside) || other_liquid { + // One block draws nothing: the settings' random is shared. + let block = match self.replacements.as_slice() { + [(only, _)] => *only, + _ => settings.with_random(info.pos, |random| pick(&self.replacements, random)), + }; + world.set_section_block(at, block)?; + } + } + Ok(Some(info)) + } +} + +/// `weighted_list_of_replacement_blocks`: blocks by name with their weight, +/// at least one. +fn weighted_blocks( + v: &Value, + resources: &StructureResources, +) -> Result, DecodeError> { + let replacements = v["weighted_list_of_replacement_blocks"] + .as_array() + .ok_or(DecodeError::Field("weighted_list_of_replacement_blocks"))? + .iter() + .map(|e| { + let name = e["block"].as_str().ok_or(DecodeError::Field("block"))?; + let name = crate::worldgen::tags::identifier(name)?; + let state = resources + .registry + .default_state(&name) + .ok_or_else(|| DecodeError::Registry(format!("unknown block {name}")))?; + let weight = e["weight"].as_i64().ok_or(DecodeError::Field("weight"))?; + Ok((state, weight as i32)) + }) + .collect::, DecodeError>>()?; + if replacements.is_empty() { + return Err(DecodeError::Field("weighted_list_of_replacement_blocks")); + } + Ok(replacements) +} + /// GeneralUtils.getRandomEntry: `nextFloat() * total` less each weight in /// turn, the last entry when none takes it. fn pick(entries: &[(BlockStateId, i32)], random: &mut dyn ProcessorRandom) -> BlockStateId {