From 255f1960ee1b9fbfc25b3869b740f957419cdf81 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 22 Oct 2026 08:33:20 +0200 Subject: [PATCH] Structures: Mo' Structures generate (jigsaw with its terrain check, config spacing, exclusion by spread) Carry maps mostructures:generic to vanilla's jigsaw with horizon:start_checks (terrain_radius 2, terrain_range = heightRange) and mostructures:type to a random spread with the config's default spacing and separation and its sets to avoid as horizon:exclusion_zone. The game's exclusion zone gains "their_zones": false, which tests the avoided sets by spread and frequency alone, as ModStructurePlacement does. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-port-pack/src/worldgen.rs | 142 ++++++++++++++++++ .../src/worldgen/structure/start.rs | 104 ++++++++++--- docs/modpacks.md | 13 +- 3 files changed, 238 insertions(+), 21 deletions(-) diff --git a/crates/horizon-port-pack/src/worldgen.rs b/crates/horizon-port-pack/src/worldgen.rs index 918dbf05e..51c96da84 100644 --- a/crates/horizon-port-pack/src/worldgen.rs +++ b/crates/horizon-port-pack/src/worldgen.rs @@ -86,6 +86,31 @@ const YUNG_REPLACES: [(&str, &str); 7] = [ ("betterfortresses:fortress", "minecraft:fortress"), ("bettermineshafts:mineshaft_", "minecraft:mineshaft"), ]; +/// Mo' Structures' placement (`mostructures:type`) takes its spacing and +/// separation from the mod's config, not its files: the defaults it writes +/// (MoStructuresConfig), by config key, as (spacing, separation). +const MO_SPREADS: [(&str, i64, i64); 17] = [ + ("abandoned_church", 33, 20), + ("air_balloon", 22, 12), + ("barn_house", 32, 16), + ("big_pyramid", 32, 25), + ("ice_tower", 28, 20), + ("jungle_pyramid", 25, 22), + ("killer_bunny_castle", 32, 22), + ("lighthouse", 24, 14), + ("moai", 17, 15), + ("pillager_factory", 34, 16), + ("pillager_mines", 40, 27), + ("pirate_ship", 32, 16), + ("tavern", 26, 16), + ("the_castle_in_the_sky", 32, 22), + ("villager_market", 32, 16), + ("villager_tower", 26, 16), + ("sphinx", 24, 16), +]; +/// Mo' Structures keeps a start out of this many chunks around a start of +/// each set in its `structure_set_to_avoid`. +const MO_AVOID_CHUNKS: i64 = 3; /// Moog's Structure Lib spreads its structures 1.65 times as far apart as /// its files say (AdvancedRandomSpread's constructor). const MOOGS_SPACING: f64 = 1.65; @@ -510,6 +535,22 @@ fn upgrade_types( v["type"] = "minecraft:jigsaw".into(); true } + // Mo' Structures' ModStructure: vanilla's jigsaw that starts only + // where the terrain under the 5×5 chunks around varies by no + // more than `heightRange` blocks (-1: anywhere). + Some("mostructures:generic") => { + let range = v + .as_object_mut() + .and_then(|o| o.remove("heightRange")) + .and_then(|r| r.as_i64()) + .unwrap_or(-1); + if range >= 0 { + v["horizon:start_checks"] = + serde_json::json!({"terrain_radius": 2, "terrain_range": range}); + } + v["type"] = "minecraft:jigsaw".into(); + true + } // Formations' SimpleStructure: its pool and placement, laid out // by the game (`horizon_world::worldgen::structure::formations`). Some("formations:simple") => { @@ -533,6 +574,7 @@ fn upgrade_types( p["type"] = "minecraft:random_spread".into(); true } + Some("mostructures:type") => mo_placement(&mut v["placement"], lost), Some(t) if YUNG_SPREADS.contains(&t) => { let t = t.to_owned(); yung_placement(&t, &mut v["placement"], set_tags, lost); @@ -1022,6 +1064,41 @@ fn placement_rules( } } +/// Mo' Structures' placement as vanilla's random spread: the spacing and +/// separation of its config key, and its sets to avoid as +/// `horizon:exclusion_zone` tested by their spread alone +/// (ModStructurePlacement.exclusionZoneCheck). A key the config does not +/// have fails the mod's codec, and the set stays as it is. +fn mo_placement(p: &mut Value, lost: &mut BTreeMap) -> bool { + let key = p["config_key"].as_str().unwrap_or_default(); + let Some(&(_, spacing, separation)) = MO_SPREADS.iter().find(|(k, ..)| *k == key) else { + *lost.entry("config_key".into()).or_default() += 1; + return false; + }; + let Some(o) = p.as_object_mut() else { + return false; + }; + o.remove("config_key"); + o.insert("spacing".into(), spacing.into()); + o.insert("separation".into(), separation.into()); + let avoid = o.remove("structure_set_to_avoid"); + let sets: Vec = avoid + .iter() + .flat_map(|a| a.as_array().into_iter().flatten()) + .filter(|s| s.is_string()) + .cloned() + .collect(); + if !sets.is_empty() { + o.insert( + "horizon:exclusion_zone".into(), + serde_json::json!({"other_sets": sets, "chunk_count": MO_AVOID_CHUNKS, + "their_zones": false}), + ); + } + o.insert("type".into(), "minecraft:random_spread".into()); + true +} + /// One of YUNG's placements as vanilla's random spread with `horizon:` keys: /// the enhanced exclusion zone as `horizon:exclusion_zone`; the temples' /// ocean and river search (findBiomeHorizontal around the chunk's middle @@ -1385,6 +1462,71 @@ mod tests { ); } + #[test] + fn mo_structures_become_vanillas_jigsaw_and_spread() { + let mut report = Upgrade::default(); + let mut s = json!({"type": "mostructures:generic", "start_pool": "mostructures:a/base", + "size": 7, "heightRange": 25, "use_expansion_hack": true, + "start_height": {"absolute": 0}, "max_distance_from_center": 80}); + assert!(upgrade("structure", &mut s, &mut report, &BTreeMap::new())); + assert_eq!(s["type"], "minecraft:jigsaw"); + assert!(s.get("heightRange").is_none()); + assert_eq!( + s["horizon:start_checks"], + json!({"terrain_radius": 2, "terrain_range": 25}) + ); + let mut anywhere = json!({"type": "mostructures:generic", "heightRange": -1}); + assert!(upgrade( + "structure", + &mut anywhere, + &mut report, + &BTreeMap::new() + )); + assert!(anywhere.get("horizon:start_checks").is_none()); + + // The config's spacing and separation, not the file's. + let mut set = json!({"placement": {"type": "mostructures:type", "config_key": "moai", + "salt": 12994829, "spacing": 17, "separation": 15, + "structure_set_to_avoid": ["minecraft:villages", "mostructures:lighthouse"]}}); + assert!(upgrade( + "structure_set", + &mut set, + &mut report, + &BTreeMap::new() + )); + assert_eq!( + set["placement"], + json!({"type": "minecraft:random_spread", "salt": 12994829, "spacing": 17, + "separation": 15, "horizon:exclusion_zone": {"chunk_count": 3, + "other_sets": ["minecraft:villages", "mostructures:lighthouse"], + "their_zones": false}}) + ); + let mut set = json!({"placement": {"type": "mostructures:type", + "config_key": "jungle_pyramid", "salt": 1, "spacing": 16, "separation": 14}}); + assert!(upgrade( + "structure_set", + &mut set, + &mut report, + &BTreeMap::new() + )); + assert_eq!( + ( + &set["placement"]["spacing"], + &set["placement"]["separation"] + ), + (&json!(25), &json!(22)) + ); + assert!(set["placement"].get("horizon:exclusion_zone").is_none()); + let mut unknown = json!({"placement": {"type": "mostructures:type", "config_key": "x"}}); + assert!(!upgrade( + "structure_set", + &mut unknown, + &mut report, + &BTreeMap::new() + )); + assert_eq!(report.rules_lost["config_key"], 1); + } + #[test] fn super_exclusion_zones_name_their_sets() { let mut zip = zip::ZipWriter::new(std::io::Cursor::new(Vec::new())); diff --git a/crates/horizon-world/src/worldgen/structure/start.rs b/crates/horizon-world/src/worldgen/structure/start.rs index b3dbe363f..aa2933192 100644 --- a/crates/horizon-world/src/worldgen/structure/start.rs +++ b/crates/horizon-world/src/worldgen/structure/start.rs @@ -149,13 +149,24 @@ pub struct StructureSet { /// and none within `chunk_count` chunks of any of several sets /// (`"horizon:exclusion_zone"`: `other_sets`, `chunk_count`). min_distance: Option, - avoid: Option<(Vec, i32)>, + avoid: Option, /// `"horizon:ring_sections"`: starts only in odd rings around the origin. rings: Option, /// `"horizon:avoid_biomes"`: no start with one of these biomes near. avoid_biomes: Option, } +/// `"horizon:exclusion_zone"`: no start within `chunk_count` chunks of a +/// start of any of `sets`. With `"their_zones": false` those sets' own +/// exclusion zones are not checked (Mo' Structures' ModStructurePlacement +/// tests the sets it avoids by their spread and frequency alone). +#[derive(Debug, Clone)] +struct Avoid { + sets: Vec, + chunk_count: i32, + their_zones: bool, +} + /// YUNG's Better Strongholds' placement (BetterStrongholdsPlacement /// .isPlacementChunk): the world is cut into rings `thickness` chunks wide, /// the first one starting `distance_to_first_ring` chunks out; a start is @@ -444,16 +455,15 @@ impl StructureRegistry { min_distance: p .get("horizon:min_distance_from_world_origin") .and_then(Value::as_i64), - avoid: p.get("horizon:exclusion_zone").map(|z| { - ( - z["other_sets"] - .as_array() - .into_iter() - .flatten() - .filter_map(|s| Some(s.as_str()?.to_owned())) - .collect(), - z["chunk_count"].as_i64().unwrap_or(0) as i32, - ) + avoid: p.get("horizon:exclusion_zone").map(|z| Avoid { + sets: z["other_sets"] + .as_array() + .into_iter() + .flatten() + .filter_map(|s| Some(s.as_str()?.to_owned())) + .collect(), + chunk_count: z["chunk_count"].as_i64().unwrap_or(0) as i32, + their_zones: z["their_zones"].as_bool().unwrap_or(true), }), rings: p.get("horizon:ring_sections").map(RingSections::decode), avoid_biomes: p @@ -534,6 +544,19 @@ impl StructureRegistry { x: i32, z: i32, rings: &Rings, + ) -> bool { + self.structure_chunk(set, seed, x, z, rings, true) + } + /// [`Self::is_structure_chunk`]; without the set's exclusion zones when + /// `zones` is false. + fn structure_chunk( + &self, + set: &StructureSet, + seed: i64, + x: i32, + z: i32, + rings: &Rings, + zones: bool, ) -> bool { let placed = match set.placement { Placement::RandomSpread { @@ -576,24 +599,28 @@ impl StructureRegistry { return false; } } - if let Some((others, range)) = &set.avoid { - if others - .iter() - .any(|other| self.has_start_in_range(other, seed, x, z, *range, rings)) - { + if let Some(avoid) = set.avoid.as_ref().filter(|_| zones) { + if avoid.sets.iter().any(|other| { + let range = avoid.chunk_count; + self.has_start_in_range(other, seed, x, z, range, rings, avoid.their_zones) + }) { return false; } } if set.frequency < 1. && !reduce(set.reduction, seed, set.salt, x, z, set.frequency) { return false; } - match &set.exclusion { - Some((other, range)) => !self.has_start_in_range(other, seed, x, z, *range, rings), + match set.exclusion.as_ref().filter(|_| zones) { + Some((other, range)) => { + !self.has_start_in_range(other, seed, x, z, *range, rings, true) + } None => true, } } /// ChunkGeneratorStructureState.hasStructureChunkInRange: whether set - /// `other` places a structure within `range` chunks of (`x`, `z`). + /// `other` places a structure within `range` chunks of (`x`, `z`), + /// checking its own exclusion zones when `zones` is true. + #[allow(clippy::too_many_arguments)] fn has_start_in_range( &self, other: &str, @@ -602,12 +629,14 @@ impl StructureRegistry { z: i32, range: i32, rings: &Rings, + zones: bool, ) -> bool { let Some(other) = self.sets.iter().find(|s| s.name == other) else { return false; }; (x - range..=x + range).any(|tx| { - (z - range..=z + range).any(|tz| self.is_structure_chunk(other, seed, tx, tz, rings)) + (z - range..=z + range) + .any(|tz| self.structure_chunk(other, seed, tx, tz, rings, zones)) }) } } @@ -1429,6 +1458,41 @@ mod tests { ); } + #[test] + fn exclusion_zones_may_skip_the_other_sets_own() { + let set = |avoid: Value| { + json!({"structures": [{"structure": "t:s", "weight": 1}], + "placement": {"type": "minecraft:random_spread", "spacing": 1, "separation": 0, + "salt": 1, "horizon:exclusion_zone": avoid}}) + }; + let r = registry( + &[("t:s", json!({"type": "minecraft:igloo", "biomes": []}))], + &[ + ("t:c", set(json!({"other_sets": [], "chunk_count": 0}))), + // Every chunk is b's spread chunk, and c keeps b out of all. + ("t:b", set(json!({"other_sets": ["t:c"], "chunk_count": 1}))), + ( + "t:full", + set(json!({"other_sets": ["t:b"], "chunk_count": 1})), + ), + ( + "t:spread", + set(json!({"other_sets": ["t:b"], "chunk_count": 1, "their_zones": false})), + ), + ], + ); + let chunk = |name: &str| { + let s = r.sets.iter().find(|s| s.name == name).unwrap(); + r.is_structure_chunk(s, 0, 5, -3, &Rings::new()) + }; + assert!(!chunk("t:b")); + assert!( + chunk("t:full"), + "b places nothing once its own zone is checked" + ); + assert!(!chunk("t:spread"), "b's spread alone is in range"); + } + #[test] fn ring_sections_keep_the_odd_rings() { let rings = RingSections::decode( diff --git a/docs/modpacks.md b/docs/modpacks.md index c9561c3b1..e3daa6218 100644 --- a/docs/modpacks.md +++ b/docs/modpacks.md @@ -444,6 +444,18 @@ Two cases the oracle fills in: also spreads its structures 1.65 times as far apart as its files say, which carry now applies. MVS went from 829 starts to 90 in a 128×128-chunk square (seed 1234): 294 from the spacing, the rest from the start checks. + - **Mo' Structures** (LGPL-3.0; 38 files). Its `mostructures:generic` is vanilla's jigsaw + that starts only where the terrain under the 5×5 chunks around it varies by no more than + its `heightRange`: carry writes `minecraft:jigsaw` with `horizon:start_checks` + (`terrain_radius` 2, `terrain_range`). Its placement `mostructures:type` takes spacing and + separation from the mod's config, not its files; carry writes the config's defaults + (keyed by `config_key`) and the sets it avoids within 3 chunks as `horizon:exclusion_zone` + with `"their_zones": false`: like the mod, the game tests those sets by their spread and + frequency alone, not by their own exclusion zones. Its two block-ageing processors + (`jungle_rot_processor`, `simple_cobblestone`, 3 uses) are still dropped, as is its + mixin that keeps lakes out of its structures. Over chunks -64..63 that adds 13 starts at + seed 1234 (pirate ships, churches, a tavern, the castle in the sky...) and 16 at seed 2, + and every other start stays as it was. - **Processors written in Java** are taken out of their lists (#822). The game, like vanilla, refuses a list holding a type it does not know, and with it every pool naming the list. The structures now generate undecorated (no pillars under them, spawners as the @@ -627,7 +639,6 @@ Two cases the oracle fills in: Dungeons types: Java structure types; - the block processors written in Java (YUNG's banners and decorations, Better Strongholds' legs, Lithostitched's block swaps); - - MO Structures (38; its library is only on CurseForge). - **Formations** (Overworld and Nether: 50 structures, 128 pool elements) places one template per start at a height found in the noise columns under its corners and centre: on the surface, on water or lava, or in a cave (on its floor, under its ceiling, buried in