From f3099e83400977df3b1a4cbaf34d96ef693f0ce0 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 18 Oct 2026 15:55:04 +0200 Subject: [PATCH] Start checks: Repurposed's Nether city, Nether shipwreck and End stronghold rules Repurposed Structures' city_nether, shipwreck_nether and stronghold_end types are its generic jigsaw with one more start check each. The `repurposed` key of horizon:start_checks names the check: - city_nether: no block from sea level + 20 to sea level + 45 at the corners of the eight chunks around; - shipwreck_nether: no solid, filled block in a 33x30x33 grid above the start; - stronghold_end: land at least 45 above the bottom at 70 and 35 blocks in each direction and at the start. Co-Authored-By: Claude Opus 5.5 --- .../src/worldgen/structure/start_checks.rs | 195 +++++++++++++++++- 1 file changed, 190 insertions(+), 5 deletions(-) diff --git a/crates/horizon-world/src/worldgen/structure/start_checks.rs b/crates/horizon-world/src/worldgen/structure/start_checks.rs index 45b991531..f182706a8 100644 --- a/crates/horizon-world/src/worldgen/structure/start_checks.rs +++ b/crates/horizon-world/src/worldgen/structure/start_checks.rs @@ -15,9 +15,15 @@ //! "terrain_radius": 1, // chunks, with terrain_range and/or min_y, max_y //! "terrain_range": 15, //! "min_y": 60, -//! "max_y": 200 +//! "max_y": 200, +//! "repurposed": "city_nether" // or "shipwreck_nether", "stronghold_end": below //! } //! ``` +//! +//! `repurposed` is the extra check of one of Repurposed Structures' jigsaw +//! types, after the others: its Nether city needs open air above the lava sea +//! in the chunks around, its Nether shipwreck open air or lava around the +//! start, and its End stronghold land around the chunk. use crate::{heightmap::HeightmapType, worldgen::biome::BiomeId}; use horizon_core::position::ChunkPos; use serde_json::Value; @@ -33,6 +39,20 @@ pub enum LiquidCheck { Lowest, } +/// The extra start check of a Repurposed Structures jigsaw type. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Repurposed { + /// CityNetherStructure: air from sea level + 20 to + 45 (or the top of + /// the noise) at the corner of each of the 8 chunks around. + CityNether, + /// ShipwreckNetherStructure: no solid block at 5×5 columns 8 apart + /// around the chunk corner, from the start height up 30 in steps of 5. + ShipwreckNether, + /// StrongholdEndStructure: land at least 45 above the bottom 35 and 70 + /// blocks away in each direction and at the chunk corner. + StrongholdEnd, +} + /// The checks of one structure; all empty for vanilla's. #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct StartChecks { @@ -42,6 +62,7 @@ pub struct StartChecks { terrain_range: Option, min_y: Option, max_y: Option, + repurposed: Option, } /// The column and biome queries the checks need. @@ -53,6 +74,9 @@ pub trait CheckQueries { /// and does not block motion is a liquid. fn liquid_column(&mut self, x: i32, z: i32) -> (Vec, Vec); fn noise_biome(&mut self, quart: [i32; 3]) -> BiomeId; + fn sea_level(&self) -> i32; + /// The noise's bottom, where the columns start. + fn bottom(&self) -> i32; } impl CheckQueries for T { @@ -71,6 +95,12 @@ impl CheckQueries for T { fn noise_biome(&mut self, quart: [i32; 3]) -> BiomeId { super::start::StartContext::noise_biome(self, quart) } + fn sea_level(&self) -> i32 { + super::start::StartContext::sea_level(self) + } + fn bottom(&self) -> i32 { + self.min_y() + } } impl StartChecks { @@ -91,6 +121,12 @@ impl StartChecks { terrain_range: int("terrain_range"), min_y: int("min_y"), max_y: int("max_y"), + repurposed: match v.get("repurposed").and_then(Value::as_str) { + Some("city_nether") => Some(Repurposed::CityNether), + Some("shipwreck_nether") => Some(Repurposed::ShipwreckNether), + Some("stronghold_end") => Some(Repurposed::StrongholdEnd), + _ => None, + }, } } @@ -155,7 +191,76 @@ impl StartChecks { return false; } } - true + match self.repurposed { + Some(check) => repurposed(check, queries, chunk, y), + None => true, + } + } +} + +/// [`Repurposed`]'s checks. A noise column reads air past its ends; its +/// length is the noise's depth (GeneralUtils.getMaxTerrainLimit). +fn repurposed(check: Repurposed, queries: &mut impl CheckQueries, chunk: ChunkPos, y: i32) -> bool { + let (x0, z0) = (chunk.x * 16, chunk.z * 16); + let bottom = queries.bottom(); + let at = |column: &[bool], y: i32| { + usize::try_from(y - bottom) + .ok() + .and_then(|i| column.get(i).copied()) + .unwrap_or(false) + }; + match check { + Repurposed::CityNether => { + let sea = queries.sea_level(); + for cx in chunk.x - 1..=chunk.x + 1 { + for cz in chunk.z - 1..=chunk.z + 1 { + if (cx, cz) == (chunk.x, chunk.z) { + continue; + } + let (filled, _) = queries.liquid_column(cx << 4, cz << 4); + let top = (bottom + filled.len() as i32).min(sea + 45); + if (sea + 20..top).any(|y| at(&filled, y)) { + return false; + } + } + } + true + } + Repurposed::ShipwreckNether => { + for dx in (-16..=16).step_by(8) { + for dz in (-16..=16).step_by(8) { + let (filled, solid) = queries.liquid_column(x0 + dx, z0 + dz); + // Not air and no fluid: in a noise column, a solid block. + if (0..=30) + .step_by(5) + .any(|dy| at(&filled, y + dy) && at(&solid, y + dy)) + { + return false; + } + } + } + true + } + Repurposed::StrongholdEnd => { + let (filled, _) = queries.liquid_column(x0, z0); + let min_land = (bottom + filled.len() as i32).min(bottom + 45); + // getHeightAt: the lowest height so far, less one at every sample. + let mut land = i32::MAX; + let mut sample = |x: i32, z: i32, land: &mut i32| { + let h = queries.first_free_height(x, z, HeightmapType::WorldSurfaceWg); + *land = (*land).min(h) - 1; + *land >= min_land + }; + for distance in [70, 35] { + // Direction.Plane.HORIZONTAL: north, east, south, west. + for (dx, dz) in [(0, -1), (1, 0), (0, 1), (-1, 0)] { + if !sample(x0 + dx * distance, z0 + dz * distance, &mut land) { + return false; + } + } + } + sample(x0, z0, &mut land) + } } } @@ -172,18 +277,27 @@ mod tests { column: Vec, biomes: BTreeMap<(i32, i32), u32>, asked: Vec<[i32; 3]>, + /// Columns by (x, z), instead of `column`, from y 0. + columns: BTreeMap<(i32, i32), Vec>, } impl CheckQueries for Fake { fn first_free_height(&mut self, x: i32, z: i32, _: HeightmapType) -> i32 { self.heights.get(&(x, z)).copied().unwrap_or(64) } - fn liquid_column(&mut self, _: i32, _: i32) -> (Vec, Vec) { + fn liquid_column(&mut self, x: i32, z: i32) -> (Vec, Vec) { // '.' air, '#' stone, '~' water, from the bottom up. + let column = self.columns.get(&(x, z)).unwrap_or(&self.column); ( - self.column.iter().map(|&c| c != '.').collect(), - self.column.iter().map(|&c| c == '#').collect(), + column.iter().map(|&c| c != '.').collect(), + column.iter().map(|&c| c == '#').collect(), ) } + fn sea_level(&self) -> i32 { + 32 + } + fn bottom(&self) -> i32 { + 0 + } fn noise_biome(&mut self, quart: [i32; 3]) -> BiomeId { self.asked.push(quart); BiomeId(self.biomes.get(&(quart[0], quart[2])).copied().unwrap_or(1)) @@ -274,4 +388,75 @@ mod tests { assert!(bounds(0, 64).pass(&mut fake, &none, CHUNK, 0, None)); assert!(!bounds(0, 59).pass(&mut fake, &none, CHUNK, 0, None)); } + + /// A column of `n` blocks: `fill` up to `top` (exclusive), air above. + fn column(n: usize, top: usize, fill: char) -> Vec { + (0..n).map(|y| if y < top { fill } else { '.' }).collect() + } + + #[test] + fn repurposed_city_needs_air_above_the_lava_sea_around() { + let none = BTreeSet::new(); + let city = checks(json!({"repurposed": "city_nether"})); + // Sea 32: air needed from 52 to 76 (128 deep), in the 8 chunks around. + let mut fake = Fake { + column: column(128, 52, '#'), + ..Fake::default() + }; + // The chunk itself is not read. + fake.columns.insert((32, -16), column(128, 100, '#')); + assert!(city.pass(&mut fake, &none, CHUNK, 33, None)); + fake.columns.insert((48, 0), column(128, 53, '#')); + assert!(!city.pass(&mut fake, &none, CHUNK, 33, None)); + // Above sea + 45 nothing is read. + fake.columns.insert((48, 0), { + let mut c = column(128, 52, '#'); + c[77] = '#'; + c + }); + assert!(city.pass(&mut fake, &none, CHUNK, 33, None)); + } + + #[test] + fn repurposed_shipwreck_needs_no_solid_block_around() { + let none = BTreeSet::new(); + let wreck = checks(json!({"repurposed": "shipwreck_nether"})); + // Lava up to 40, air above: the samples at 28..=58 meet only lava and air. + let mut fake = Fake { + column: column(128, 40, '~'), + ..Fake::default() + }; + assert!(wreck.pass(&mut fake, &none, CHUNK, 28, None)); + // Netherrack at y 43, between samples (28 + 15, + 20 are 43, 48). + let mut rock = column(128, 40, '~'); + rock[43] = '#'; + fake.columns.insert((32 - 16, -16 + 16), rock.clone()); + assert!(!wreck.pass(&mut fake, &none, CHUNK, 28, None)); + rock[43] = '.'; + rock[44] = '#'; + fake.columns.insert((16, 0), rock); + assert!(wreck.pass(&mut fake, &none, CHUNK, 28, None)); + } + + #[test] + fn repurposed_end_stronghold_needs_land_around() { + let none = BTreeSet::new(); + let end = checks(json!({"repurposed": "stronghold_end"})); + let mut fake = Fake { + column: column(256, 0, '#'), + ..Fake::default() + }; + // Every height 64 by default: 63, 62, ... 55 after the 9 samples. + assert!(end.pass(&mut fake, &none, CHUNK, 0, None)); + // Land at least 45 above the bottom, after the sample's minus one: + // 46 at the corner passes, 45 fails. + fake.heights.insert((32, -16), 46); + assert!(end.pass(&mut fake, &none, CHUNK, 0, None)); + fake.heights.insert((32, -16), 45); + assert!(!end.pass(&mut fake, &none, CHUNK, 0, None)); + // Void 70 blocks north fails at once. + fake.heights.clear(); + fake.heights.insert((32, -86), 0); + assert!(!end.pass(&mut fake, &none, CHUNK, 0, None)); + } }