Merge pull request #1032 from ludovic111/feat/rs-waterlog-when-replacing-water

🤖 Agent: merged. Verify passed. Integration proof (main + #1041 #1043 #1021 #1020 #1032 #659 #1029 #1066), 2026-10-21: 97 of 100 harnesses passed on the desktop. world_reopen and save_roundtrip need a display there; they pass on the Mac mini with #1041/#1043. dedicated_server is a pre-existing flake: it fails on plain main too, and is pass/fail in 2 runs on the integration.
This commit is contained in:
Ludovic Marie
2026-10-21 15:38:11 +02:00
committed by GitHub
4 changed files with 131 additions and 0 deletions
@@ -487,6 +487,10 @@ fn as_data(kind: &str, p: &Value, data: &ProcessorData) -> Option<Vec<Value>> {
.collect();
vec![spawner_mobs(p, mobs, repurposed_light(p)?)]
}
// Wet where the world holds water, dry where it does not.
"repurposed_structures:waterlogging_when_replacing_water_processor" => {
vec![json!({"processor_type": "horizon:waterlog_in_world_water"})]
}
"moogs_structures:vanilla_loot_swap_processor" => {
let key = (
p["modid"].as_str()?.to_owned(),
@@ -1337,6 +1341,23 @@ mod tests {
assert_eq!(carried.values().sum::<usize>(), 4);
}
#[test]
fn repurposed_waterlogging_follows_the_world() {
let mut list = json!({"processors": [{"processor_type":
"repurposed_structures:waterlogging_when_replacing_water_processor"}]});
let mut carried = BTreeMap::new();
assert!(carry(
"processor_list",
&mut list,
&ProcessorData::default(),
&mut carried
));
assert_eq!(
list["processors"],
json!([{"processor_type": "horizon:waterlog_in_world_water"}])
);
}
#[test]
fn small_dungeon_chests_are_capped() {
let mut list = json!({"processors": [
@@ -328,6 +328,9 @@ pub enum Processor {
Waterlog,
/// `horizon:keep_world_block` (Better Ocean Monuments' structure void).
KeepWorldBlock(Box<sea_level::KeepWorldBlock>),
/// `horizon:waterlog_in_world_water` (Repurposed Structures'): blocks
/// are waterlogged where the world holds water, dry where it does not.
WaterlogInWorldWater,
}
#[derive(Clone, Debug, Default)]
pub struct ProcessorList(pub Vec<Processor>);
@@ -823,6 +826,7 @@ impl Processor {
Self::FloodAir(Box::new(sea_level::FloodAir::decode(resources.registry)?))
}
"horizon:waterlog" => Self::Waterlog,
"horizon:waterlog_in_world_water" => Self::WaterlogInWorldWater,
"horizon:keep_world_block" => {
Self::KeepWorldBlock(Box::new(sea_level::KeepWorldBlock::decode(value)?))
}
@@ -1207,6 +1211,14 @@ fn process_block<W: PlacementContext>(
Processor::KeepWorldBlock(p) => {
return p.process(world, resources.registry, info, settings);
}
Processor::WaterlogInWorldWater => {
return sea_level::WaterlogInWorldWater::process(
world,
resources.registry,
info,
settings,
);
}
Processor::Pick(pick) => match name(info.state) == pick.block {
true => {
let mut out = settings.with_random(info.pos, |r| pick.apply(info.clone(), r));
@@ -9,8 +9,14 @@
//! - `horizon:keep_world_block`: blocks of `blocks` take the block the world
//! holds there (its StructureVoidProcessor, which, unlike vanilla's
//! structure void, lets the next processors see that block).
//!
//! 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).
use super::{PlaceSettings, ProcessResult, pillars::outside_chunk};
use crate::{
fluid::{FluidKind, FluidState},
registry::{BlockRegistry, BlockStateId},
worldgen::{DecodeError, placement::PlacementContext, structure::BlockInfo},
};
@@ -127,6 +133,45 @@ impl KeepWorldBlock {
}
}
/// `horizon:waterlog_in_world_water`: WaterlogWhenReplacingWaterProcessor.
/// In the chunk being generated, a block that can be waterlogged takes
/// `waterlogged` from the world's fluid there (water, still or flowing, or a
/// waterlogged block), so a template's wet block placed on land is dry; a
/// block placed in water gets a block tick, as the mod schedules one.
pub struct WaterlogInWorldWater;
impl WaterlogInWorldWater {
pub(super) fn process<W: PlacementContext>(
world: &mut W,
registry: &BlockRegistry,
info: BlockInfo,
settings: &PlaceSettings<'_>,
) -> ProcessResult {
let Some(state) = registry.state(info.state) else {
return Ok(Some(info));
};
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));
// 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)? {
world.schedule_block_tick(info.pos, info.state, 0)?;
}
let mut set = state.clone();
set.properties
.insert("waterlogged".into(), water.to_string());
Ok(Some(BlockInfo {
state: registry.id(&set).unwrap_or(info.state),
..info
}))
}
}
#[cfg(test)]
mod tests {
use super::*;
@@ -144,6 +189,7 @@ mod tests {
struct Sea {
world: BlockStateId,
marked: Vec<[i32; 3]>,
ticks: Vec<([i32; 3], BlockStateId)>,
}
impl PlacementContext for Sea {
fn generation(&self) -> WorldGenerationContext {
@@ -165,6 +211,19 @@ mod tests {
fn block_state(&mut self, _: [i32; 3]) -> Result<BlockStateId, PlacementQueryError> {
Ok(self.world)
}
fn max_y(&mut self) -> Result<i32, PlacementQueryError> {
Ok(319)
}
fn schedule_block_tick(
&mut self,
pos: [i32; 3],
block: BlockStateId,
delay: i32,
) -> Result<(), PlacementQueryError> {
assert_eq!(delay, 0);
self.ticks.push((pos, block));
Ok(())
}
}
// 0 air, 1 cave air, 2 water, 3/4 slab dry/wet, 5 purpur slab, 6 stone.
@@ -205,6 +264,7 @@ mod tests {
let mut sea = Sea {
world: BlockStateId(6),
marked: vec![],
ticks: vec![],
};
let state = |i: BlockInfo, sea: &mut Sea| flood.process(sea, i).unwrap().unwrap().state;
assert_eq!(state(info(0, [0, 62, 0]), &mut sea), BlockStateId(2));
@@ -219,6 +279,7 @@ mod tests {
let mut sea = Sea {
world: BlockStateId(6),
marked: vec![],
ticks: vec![],
};
let settings = chunk(-16, 0);
let mut run = |i: BlockInfo| {
@@ -251,6 +312,7 @@ mod tests {
let mut sea = Sea {
world: BlockStateId(1),
marked: vec![],
ticks: vec![],
};
let settings = chunk(0, 0);
let mut run = |i: BlockInfo| {
@@ -264,4 +326,34 @@ mod tests {
assert_eq!(run(info(5, [16, 40, 3])), BlockStateId(5));
assert!(KeepWorldBlock::decode(&json!({})).is_err());
}
#[test]
fn blocks_take_waterlogged_from_the_worlds_water() {
let registry = registry();
let settings = chunk(0, 0);
let mut sea = Sea {
world: BlockStateId(2),
marked: vec![],
ticks: vec![],
};
let run = |sea: &mut Sea, i: BlockInfo| {
WaterlogInWorldWater::process(sea, &registry, i, &settings)
.unwrap()
.unwrap()
.state
};
// In water: wet, with a block tick (any height: the world decides).
assert_eq!(run(&mut sea, info(3, [3, 80, 3])), BlockStateId(4));
assert_eq!(sea.ticks, vec![([3, 80, 3], BlockStateId(3))]);
// A waterlogged block in the world counts as water.
sea.world = BlockStateId(4);
assert_eq!(run(&mut sea, info(3, [3, 40, 3])), BlockStateId(4));
// On land: a wet template block is dry, and no tick.
sea.world = BlockStateId(6);
assert_eq!(run(&mut sea, info(4, [3, 40, 3])), BlockStateId(3));
assert_eq!(sea.ticks.len(), 2);
// Blocks that cannot be waterlogged, and other chunks, are left.
assert_eq!(run(&mut sea, info(6, [3, 40, 3])), BlockStateId(6));
assert_eq!(run(&mut sea, info(4, [16, 40, 3])), BlockStateId(4));
}
}
+6
View File
@@ -537,6 +537,12 @@ Two cases the oracle fills in:
from the template's origin along one axis, and a world height range. The game runs them
as `horizon:matter_phase`, `horizon:piece_origin_axis_aligned_linear_pos` and
`horizon:y_value` with the mod's fields, and carry renames them (213 in 75 lists).
- **Waterlogging.** Repurposed's `waterlogging_when_replacing_water_processor` (the bottom
pillars of its villages and outposts, 16 lists) is `horizon:waterlog_in_world_water`: a
block that can be waterlogged is where the world holds water, dry where it does not, and
one placed in water gets a block tick. Its dropped processors go from 370 to 253 (with
the structure voids carried); around the ocean village at chunk (12, 10), seed 1234, 6
spruce fences of its pillars under the sea are now waterlogged.
- **Namespaces besides the mod id.** Towns and Towers (mod id `t_and_t`) ships all 60 of its
structures under `kaisyn` and `towns_and_towers`, which carry used to leave in `outside/`.
Carry now claims a namespace for the mod when the mod's own files (its id's, its tag