diff --git a/crates/horizon-port-pack/src/carry.rs b/crates/horizon-port-pack/src/carry.rs index dd6b148f3..e6056e519 100644 --- a/crates/horizon-port-pack/src/carry.rs +++ b/crates/horizon-port-pack/src/carry.rs @@ -707,7 +707,8 @@ 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); + let mut processor_data = crate::processors::ProcessorData::read(&mut zip); + processor_data.mark_loaded(loaded); report.namespaces = extra_namespaces(&mut zip, id, pack.mods); let owned: Vec<&str> = std::iter::once(id.as_str()) .chain(report.namespaces.iter().map(String::as_str)) diff --git a/crates/horizon-port-pack/src/processors.rs b/crates/horizon-port-pack/src/processors.rs index 7f26282bf..e6c0fe7d8 100644 --- a/crates/horizon-port-pack/src/processors.rs +++ b/crates/horizon-port-pack/src/processors.rs @@ -16,6 +16,12 @@ //! `condition` become the game's `horizon:apply_random` and //! `horizon:condition`, with the lists inside them carried the same way, //! and its `set_block` (simple or weighted states) `horizon:set_block`. +//! - Repurposed Structures' mineshaft sky view becomes the game's +//! `horizon:mineshaft_sky_view`. +//! - Choice Theorem's Overhauled Village's `modular_compat` runs another +//! list only when the mod it names is loaded: that list is written in its +//! place when the mod is ported along, and it is taken out (a no-op, as in +//! the mod) when it is not. //! //! 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 @@ -37,9 +43,37 @@ pub struct ProcessorData { pub replace_vanilla: BTreeSet<(String, String)>, /// The mod's processor lists by id, for Lithostitched's references. pub lists: BTreeMap, + /// The mods named by its `ctov:modular_compat` processors that are + /// ported along ([`Self::mark_loaded`]). + pub compat_loaded: BTreeSet, } +/// Choice Theorem's Overhauled Village's processor that runs the list +/// `reference` when mod `modid` is loaded (ModularCompatProcessor). +const MODULAR_COMPAT: &str = "ctov:modular_compat"; + impl ProcessorData { + /// Notes which mods its compat processors name are `loaded`. + pub fn mark_loaded(&mut self, loaded: &dyn Fn(&str) -> bool) { + fn walk(v: &Value, out: &mut BTreeSet) { + match v { + Value::Object(o) => { + if o.get("processor_type").and_then(Value::as_str) == Some(MODULAR_COMPAT) { + if let Some(id) = o.get("modid").and_then(Value::as_str) { + out.insert(id.to_owned()); + } + } + o.values().for_each(|v| walk(v, out)); + } + Value::Array(a) => a.iter().for_each(|v| walk(v, out)), + _ => {} + } + } + let mut named = BTreeSet::new(); + self.lists.values().for_each(|l| walk(l, &mut named)); + self.compat_loaded = named.into_iter().filter(|m| loaded(m)).collect(); + } + pub fn read(zip: &mut zip::ZipArchive) -> Self { let mut out = Self::default(); for i in 0..zip.len() { @@ -408,6 +442,17 @@ fn references( let mut out = Vec::with_capacity(list.len()); let mut changed = false; for p in list { + if p["processor_type"] == MODULAR_COMPAT && depth < 8 { + *carried.entry(MODULAR_COMPAT.into()).or_default() += 1; + changed = true; + let loaded = p["modid"] + .as_str() + .is_some_and(|m| data.compat_loaded.contains(m)); + if let Some(inner) = loaded.then(|| referenced(&p["reference"], data)).flatten() { + out.extend(references(inner, data, carried, depth + 1).0); + } + continue; + } let named = (p["processor_type"] == "lithostitched:reference" && depth < 8) .then(|| referenced(&p["processor_lists"], data)) .flatten(); @@ -491,6 +536,10 @@ fn as_data(kind: &str, p: &Value, data: &ProcessorData) -> Option> { "repurposed_structures:waterlogging_when_replacing_water_processor" => { vec![json!({"processor_type": "horizon:waterlog_in_world_water"})] } + // Its mineshafts: nothing above the ocean floor but grounded rails. + "repurposed_structures:mineshaft_sky_view_processor" => { + vec![json!({"processor_type": "horizon:mineshaft_sky_view"})] + } "moogs_structures:vanilla_loot_swap_processor" => { let key = ( p["modid"].as_str()?.to_owned(), @@ -1344,7 +1393,8 @@ mod tests { #[test] fn repurposed_waterlogging_follows_the_world() { let mut list = json!({"processors": [{"processor_type": - "repurposed_structures:waterlogging_when_replacing_water_processor"}]}); + "repurposed_structures:waterlogging_when_replacing_water_processor"}, + {"processor_type": "repurposed_structures:mineshaft_sky_view_processor"}]}); let mut carried = BTreeMap::new(); assert!(carry( "processor_list", @@ -1354,7 +1404,8 @@ mod tests { )); assert_eq!( list["processors"], - json!([{"processor_type": "horizon:waterlog_in_world_water"}]) + json!([{"processor_type": "horizon:waterlog_in_world_water"}, + {"processor_type": "horizon:mineshaft_sky_view"}]) ); } @@ -1391,6 +1442,27 @@ mod tests { assert_eq!(p[1]["processor_type"], "lithostitched:block_swap"); } + #[test] + fn modular_compat_runs_its_list_only_with_its_mod() { + let mut data = ProcessorData::default(); + let swap = json!({"processor_type": "minecraft:rule", "rules": []}); + data.lists + .insert("v:house_ns".into(), json!({"processors": [swap.clone()]})); + let compat = |m: &str| json!({"processor_type": "ctov:modular_compat", "modid": m, "reference": "v:house_ns"}); + let gravity = json!({"processor_type": "minecraft:gravity"}); + data.lists.insert( + "v:house".into(), + json!({"processors": [compat("ns"), compat("absent"), gravity.clone()]}), + ); + data.mark_loaded(&|m| m == "ns"); + assert_eq!(data.compat_loaded, BTreeSet::from(["ns".to_owned()])); + let mut v = json!({"processors": [compat("ns"), compat("absent"), gravity.clone()]}); + let mut carried = BTreeMap::new(); + assert!(carry("processor_list", &mut v, &data, &mut carried)); + assert_eq!(v, json!({"processors": [swap, gravity]})); + assert_eq!(carried["ctov:modular_compat"], 2); + } + #[test] fn lithostitched_references_are_written_in() { let mut data = data(); diff --git a/crates/horizon-world/src/level/feature_world.rs b/crates/horizon-world/src/level/feature_world.rs index 3b781df4a..de2bb0ece 100644 --- a/crates/horizon-world/src/level/feature_world.rs +++ b/crates/horizon-world/src/level/feature_world.rs @@ -122,6 +122,9 @@ impl PlacementContext for LevelFeatureWorld<'_, '_, L> ) -> Result { Ok(self.sim.b.has_flag(state, state_flags::COLLISION_EMPTY)) } + fn can_occlude(&mut self, state: BlockStateId) -> Result { + Ok(self.sim.b.has_flag(state, state_flags::CAN_OCCLUDE)) + } /// BeehiveDecorator's bees go into the nest's block entity (the tree /// checked the nest is there). fn store_beehive_occupants( diff --git a/crates/horizon-world/src/worldgen/generator_decoration.rs b/crates/horizon-world/src/worldgen/generator_decoration.rs index bc5dbda70..1284d0054 100644 --- a/crates/horizon-world/src/worldgen/generator_decoration.rs +++ b/crates/horizon-world/src/worldgen/generator_decoration.rs @@ -816,6 +816,19 @@ impl PlacementContext for World<'_> { .is_face_sturdy(self, state, position, direction, SupportType::Center) .map_err(query) } + fn can_occlude(&mut self, state: BlockStateId) -> Result { + if let Some(behaviours) = self.behaviours { + return Ok(behaviours.has_flag(state, crate::level::data::state_flags::CAN_OCCLUDE)); + } + let properties = &self.blocks()?.properties; + let name = properties + .registry() + .state(state) + .ok_or(PlacementQueryError::Unavailable)? + .name + .clone(); + Ok(properties.definition(&name).is_some_and(|d| d.can_occlude)) + } fn collision_full_block( &mut self, state: BlockStateId, diff --git a/crates/horizon-world/src/worldgen/placement/context.rs b/crates/horizon-world/src/worldgen/placement/context.rs index 8d2a1dab7..96a5df130 100644 --- a/crates/horizon-world/src/worldgen/placement/context.rs +++ b/crates/horizon-world/src/worldgen/placement/context.rs @@ -211,6 +211,13 @@ pub trait PlacementContext { fn water_at(&mut self, _position: [i32; 3]) -> Result { Err(PlacementQueryError::Unavailable) } + /// `BlockState.canOcclude()` of a state. + fn can_occlude( + &mut self, + _state: crate::registry::BlockStateId, + ) -> Result { + Err(PlacementQueryError::Unavailable) + } /// Multiface attachment: neighbor support, then empty-context collision. fn attachment_at( &mut self, diff --git a/crates/horizon-world/src/worldgen/structure/processor.rs b/crates/horizon-world/src/worldgen/structure/processor.rs index 254720d8f..f6f5d4508 100644 --- a/crates/horizon-world/src/worldgen/structure/processor.rs +++ b/crates/horizon-world/src/worldgen/structure/processor.rs @@ -331,6 +331,9 @@ pub enum Processor { /// `horizon:waterlog_in_world_water` (Repurposed Structures'): blocks /// are waterlogged where the world holds water, dry where it does not. WaterlogInWorldWater, + /// `horizon:mineshaft_sky_view` (Repurposed Structures' mineshafts): + /// nothing above the ocean floor but rails on solid ground. + MineshaftSkyView, } #[derive(Clone, Debug, Default)] pub struct ProcessorList(pub Vec); @@ -827,6 +830,7 @@ impl Processor { } "horizon:waterlog" => Self::Waterlog, "horizon:waterlog_in_world_water" => Self::WaterlogInWorldWater, + "horizon:mineshaft_sky_view" => Self::MineshaftSkyView, "horizon:keep_world_block" => { Self::KeepWorldBlock(Box::new(sea_level::KeepWorldBlock::decode(value)?)) } @@ -1219,6 +1223,9 @@ fn process_block( settings, ); } + Processor::MineshaftSkyView => { + return sea_level::MineshaftSkyView::process(world, resources.registry, info); + } Processor::Pick(pick) => match name(info.state) == pick.block { true => { let mut out = settings.with_random(info.pos, |r| pick.apply(info.clone(), r)); diff --git a/crates/horizon-world/src/worldgen/structure/processor/sea_level.rs b/crates/horizon-world/src/worldgen/structure/processor/sea_level.rs index 766e42bad..4f7df2b9f 100644 --- a/crates/horizon-world/src/worldgen/structure/processor/sea_level.rs +++ b/crates/horizon-world/src/worldgen/structure/processor/sea_level.rs @@ -13,10 +13,14 @@ //! And from Repurposed Structures': //! - `horizon:waterlog_in_world_water`: a block that can be waterlogged is //! where the world holds water and is dry where it does not (its -//! WaterlogWhenReplacingWaterProcessor). +//! WaterlogWhenReplacingWaterProcessor); +//! - `horizon:mineshaft_sky_view`: its mineshafts are not built above the +//! ocean floor, but keep their rails on solid ground (its +//! MineshaftSkyViewProcessor). use super::{PlaceSettings, ProcessResult, pillars::outside_chunk}; use crate::{ fluid::{FluidKind, FluidState}, + heightmap::HeightmapType, registry::{BlockRegistry, BlockStateId}, worldgen::{DecodeError, placement::PlacementContext, structure::BlockInfo}, }; @@ -152,11 +156,7 @@ impl WaterlogInWorldWater { if !state.properties.contains_key("waterlogged") || outside_chunk(settings, info.pos) { return Ok(Some(info)); } - let here = world.block_state(info.pos)?; - let water = registry - .state(here) - .and_then(|s| FluidState::from_block(s).ok()) - .is_some_and(|f| f.kind().same_family(FluidKind::Water)); + let water = world_water(world, registry, info.pos)?; // The mod's height check (min to max build height) holds for every // block of the chunk. if water && world.inside_build_height(info.pos)? { @@ -172,6 +172,56 @@ impl WaterlogInWorldWater { } } +/// Whether the world's block at `pos` holds water (still or flowing, or a +/// waterlogged block): `getFluidState().is(FluidTags.WATER)`. +fn world_water( + world: &mut W, + registry: &BlockRegistry, + pos: [i32; 3], +) -> Result { + let here = world.block_state(pos)?; + Ok(registry + .state(here) + .and_then(|s| FluidState::from_block(s).ok()) + .is_some_and(|f| f.kind().same_family(FluidKind::Water))) +} + +/// `horizon:mineshaft_sky_view`: MineshaftSkyViewProcessor. A plain rail +/// whose world block below can occlude is placed, waterlogged where the +/// world holds water; any other block at or above the world's +/// `OCEAN_FLOOR_WG` height in its column is not placed, so a mineshaft cut +/// by a valley or a ravine is not built in the open. +pub struct MineshaftSkyView; +impl MineshaftSkyView { + pub(super) fn process( + world: &mut W, + registry: &BlockRegistry, + info: BlockInfo, + ) -> ProcessResult { + let [x, y, z] = info.pos; + let rail = registry + .state(info.state) + .filter(|s| s.name == "minecraft:rail"); + if let Some(rail) = rail { + let below = world.block_state([x, y - 1, z])?; + if world.can_occlude(below)? { + let mut set = rail.clone(); + let water = world_water(world, registry, info.pos)?; + set.properties + .insert("waterlogged".into(), water.to_string()); + return Ok(Some(BlockInfo { + state: registry.id(&set).unwrap_or(info.state), + ..info + })); + } + } + if y >= world.height(HeightmapType::OceanFloorWg, x, z)? { + return Ok(None); + } + Ok(Some(info)) + } +} + #[cfg(test)] mod tests { use super::*; @@ -198,8 +248,19 @@ mod tests { fn min_y(&mut self) -> Result { Ok(-64) } - fn height(&mut self, _: HeightmapType, _: i32, _: i32) -> Result { - Err(PlacementQueryError::Unavailable) + /// The ocean floor is at 64 everywhere. + fn height( + &mut self, + kind: HeightmapType, + _: i32, + _: i32, + ) -> Result { + assert_eq!(kind, HeightmapType::OceanFloorWg); + Ok(64) + } + /// Only stone can occlude. + fn can_occlude(&mut self, state: BlockStateId) -> Result { + Ok(state == BlockStateId(6)) } fn sea_level(&mut self) -> Result { Ok(63) @@ -226,12 +287,13 @@ mod tests { } } - // 0 air, 1 cave air, 2 water, 3/4 slab dry/wet, 5 purpur slab, 6 stone. + // 0 air, 1 cave air, 2 water, 3/4 slab dry/wet, 5 purpur slab, 6 stone, + // 7/8 rail dry/wet. fn registry() -> BlockRegistry { let row = |name: &str, props: Value| json!([name, false, false, "", {"id": name, "properties": props}]); let facts = json!({"defaults": {"minecraft:air": 0, "minecraft:cave_air": 1, "minecraft:water": 2, "minecraft:prismarine_slab": 3, "minecraft:purpur_slab": 5, - "minecraft:stone": 6}, + "minecraft:stone": 6, "minecraft:rail": 7}, "states": [ ["minecraft:air", false, false, "", "minecraft:air"], ["minecraft:cave_air", false, false, "", "minecraft:cave_air"], @@ -239,7 +301,9 @@ mod tests { row("minecraft:prismarine_slab", json!({"waterlogged": "false"})), row("minecraft:prismarine_slab", json!({"waterlogged": "true"})), ["minecraft:purpur_slab", false, false, "", "minecraft:purpur_slab"], - ["minecraft:stone", false, false, "", "minecraft:stone"]]}); + ["minecraft:stone", false, false, "", "minecraft:stone"], + row("minecraft:rail", json!({"shape": "north_south", "waterlogged": "false"})), + row("minecraft:rail", json!({"shape": "north_south", "waterlogged": "true"}))]}); BlockRegistry::from_facts_json(facts.to_string().as_bytes()).unwrap() } @@ -356,4 +420,29 @@ mod tests { assert_eq!(run(&mut sea, info(6, [3, 40, 3])), BlockStateId(6)); assert_eq!(run(&mut sea, info(4, [16, 40, 3])), BlockStateId(4)); } + + #[test] + fn mineshafts_stop_at_the_ocean_floor_but_keep_grounded_rails() { + let registry = registry(); + let mut sea = Sea { + world: BlockStateId(6), + marked: vec![], + ticks: vec![], + }; + let run = |sea: &mut Sea, i: BlockInfo| { + MineshaftSkyView::process(sea, ®istry, i) + .unwrap() + .map(|i| i.state) + }; + // Over stone a rail stays, above the floor too, dry as the world is. + assert_eq!(run(&mut sea, info(8, [3, 80, 3])), Some(BlockStateId(7))); + // Anything else stops at the floor (64). + assert_eq!(run(&mut sea, info(6, [3, 63, 3])), Some(BlockStateId(6))); + assert_eq!(run(&mut sea, info(6, [3, 64, 3])), None); + assert_eq!(run(&mut sea, info(0, [3, 90, 3])), None); + // Over water a rail is like any block. + sea.world = BlockStateId(2); + assert_eq!(run(&mut sea, info(7, [3, 70, 3])), None); + assert_eq!(run(&mut sea, info(8, [3, 40, 3])), Some(BlockStateId(8))); + } } diff --git a/docs/modpacks.md b/docs/modpacks.md index c9561c3b1..b0d292dd9 100644 --- a/docs/modpacks.md +++ b/docs/modpacks.md @@ -482,7 +482,11 @@ Two cases the oracle fills in: plus the name's hash, at the block, piece or structure). In a CTOV plains village at seed 1234 the farms now grow carrots, potatoes and beetroot besides wheat, and 1,655 cobblestone blocks become paths, grass, mossy cobblestone and planks. No Lithostitched processor is - dropped now (130 before), only CTOV's compat hooks for other mods inside them (142 copies). + dropped now (130 before). CTOV's compat hooks for other mods inside them (its + `modular_compat`, 142 copies) run a list of their own only when the mod they name is + loaded: carry writes that list in when the mod is ported along and takes the hook out (a + no-op, as in the mod) when it is not. In ATM10 all 142 name Nature's Spirit, which the + pack does not have. The processors that build outside their template are carried too: Repurposed's and Moog's pillar processors become the game's `horizon:pillar` (a column from a placeholder block down to the ground, with the processor list they run on each of its blocks written @@ -517,6 +521,11 @@ Two cases the oracle fills in: the world is air, keep it" rules: around the ocean mineshaft at chunk (-18, -54), seed 1234, 650 blocks of air and cave air become prismarine and 614 more template water blocks stay water (1,303 blocks change in its 81 chunks). + Its mineshafts' sky view processor (71 lists) is `horizon:mineshaft_sky_view`: a block + of the template at or above the world's `OCEAN_FLOOR_WG` height in its column is not + placed, so a mineshaft cut by a valley or a ravine is not built in the open, except + plain rails over a block that can occlude, which stay (waterlogged where the world holds + water). Repurposed's dropped processors go from 253 to 182. Still taken out: Formations' biome replacements, 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