Structures: CTOV's mod-compat hooks and Repurposed's mineshaft sky view carried
ctov:modular_compat runs another processor list only when the mod it names is loaded: carry writes that list in when the mod is ported along and takes the hook out otherwise (142 copies in ATM10, all for Nature's Spirit). Repurposed Structures' mineshaft_sky_view_processor (71 lists) becomes the game's horizon:mineshaft_sky_view: nothing at or above the world's OCEAN_FLOOR_WG height, except plain rails over a block that can occlude, waterlogged where the world holds water. Placement contexts gain can_occlude. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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<String, Value>,
|
||||
/// The mods named by its `ctov:modular_compat` processors that are
|
||||
/// ported along ([`Self::mark_loaded`]).
|
||||
pub compat_loaded: BTreeSet<String>,
|
||||
}
|
||||
|
||||
/// 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<String>) {
|
||||
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<R: Read + Seek>(zip: &mut zip::ZipArchive<R>) -> 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<Vec<Value>> {
|
||||
"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();
|
||||
|
||||
@@ -122,6 +122,9 @@ impl<L: LevelAccess + ?Sized> PlacementContext for LevelFeatureWorld<'_, '_, L>
|
||||
) -> Result<bool, PlacementQueryError> {
|
||||
Ok(self.sim.b.has_flag(state, state_flags::COLLISION_EMPTY))
|
||||
}
|
||||
fn can_occlude(&mut self, state: BlockStateId) -> Result<bool, PlacementQueryError> {
|
||||
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(
|
||||
|
||||
@@ -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<bool, PlacementQueryError> {
|
||||
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,
|
||||
|
||||
@@ -211,6 +211,13 @@ pub trait PlacementContext {
|
||||
fn water_at(&mut self, _position: [i32; 3]) -> Result<bool, PlacementQueryError> {
|
||||
Err(PlacementQueryError::Unavailable)
|
||||
}
|
||||
/// `BlockState.canOcclude()` of a state.
|
||||
fn can_occlude(
|
||||
&mut self,
|
||||
_state: crate::registry::BlockStateId,
|
||||
) -> Result<bool, PlacementQueryError> {
|
||||
Err(PlacementQueryError::Unavailable)
|
||||
}
|
||||
/// Multiface attachment: neighbor support, then empty-context collision.
|
||||
fn attachment_at(
|
||||
&mut self,
|
||||
|
||||
@@ -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<Processor>);
|
||||
@@ -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<W: PlacementContext>(
|
||||
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));
|
||||
|
||||
@@ -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<W: PlacementContext>(
|
||||
world: &mut W,
|
||||
registry: &BlockRegistry,
|
||||
pos: [i32; 3],
|
||||
) -> Result<bool, crate::worldgen::placement::PlacementQueryError> {
|
||||
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<W: PlacementContext>(
|
||||
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<i32, PlacementQueryError> {
|
||||
Ok(-64)
|
||||
}
|
||||
fn height(&mut self, _: HeightmapType, _: i32, _: i32) -> Result<i32, PlacementQueryError> {
|
||||
Err(PlacementQueryError::Unavailable)
|
||||
/// The ocean floor is at 64 everywhere.
|
||||
fn height(
|
||||
&mut self,
|
||||
kind: HeightmapType,
|
||||
_: i32,
|
||||
_: i32,
|
||||
) -> Result<i32, PlacementQueryError> {
|
||||
assert_eq!(kind, HeightmapType::OceanFloorWg);
|
||||
Ok(64)
|
||||
}
|
||||
/// Only stone can occlude.
|
||||
fn can_occlude(&mut self, state: BlockStateId) -> Result<bool, PlacementQueryError> {
|
||||
Ok(state == BlockStateId(6))
|
||||
}
|
||||
fn sea_level(&mut self) -> Result<i32, PlacementQueryError> {
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user