WIP snapshot: mansion, monument, ruined portal and temple structures
Uncommitted work from a finished agent worktree on ludothinkpad (/home/ludovic/.t3/scratch/2026-10-03-i-want-you-to-retro-e5fa4461/.claude/worktrees/agent-aecc9e1511b717b74), saved before the worktree was removed. Not built or verified. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1023,9 +1023,33 @@ where
|
||||
/// ChunkGenerator.getBaseHeight: the first free Y above the noise column
|
||||
/// (with aquifers, without terrain adaptation) for a heightmap type.
|
||||
fn base_height(&self, x: i32, z: i32, kind: HeightmapType) -> i32 {
|
||||
let min = self.settings.min_y;
|
||||
let mut found = min;
|
||||
self.noise_column(x, z, &mut |y, state| {
|
||||
if kind.is_opaque(self.data.states.get(state)) {
|
||||
found = y + 1;
|
||||
return true;
|
||||
}
|
||||
false
|
||||
});
|
||||
found
|
||||
}
|
||||
/// ChunkGenerator.getBaseColumn: opacity of each noise-column state for
|
||||
/// a heightmap type, indexed from the minimum Y.
|
||||
fn base_column(&self, x: i32, z: i32, kind: HeightmapType) -> Vec<bool> {
|
||||
let (min, height) = (self.settings.min_y, self.settings.height);
|
||||
let mut column = vec![false; height as usize];
|
||||
self.noise_column(x, z, &mut |y, state| {
|
||||
column[(y - min) as usize] = kind.is_opaque(self.data.states.get(state));
|
||||
false
|
||||
});
|
||||
column
|
||||
}
|
||||
/// iterateNoiseColumn from the top down until `visit` returns true.
|
||||
fn noise_column(&self, x: i32, z: i32, visit: &mut dyn FnMut(i32, BlockStateId) -> bool) {
|
||||
let (min, height) = (self.settings.min_y, self.settings.height);
|
||||
let Ok(volume) = DensityVolume::new([1, height, 1], [x, min, z], [1; 3]) else {
|
||||
return min;
|
||||
return;
|
||||
};
|
||||
let mut context = SamplerContext::cached();
|
||||
let mut aquifer: Box<dyn TerrainAquifer> = match &self.aquifer {
|
||||
@@ -1045,7 +1069,7 @@ where
|
||||
.ok()
|
||||
}) {
|
||||
Some(aquifer) => Box::new(aquifer),
|
||||
None => return min,
|
||||
None => return,
|
||||
},
|
||||
None => Box::new(DisabledAquifer::new(
|
||||
self.picker,
|
||||
@@ -1059,7 +1083,7 @@ where
|
||||
.sample_volume(&mut context, &mut density, volume)
|
||||
.is_err()
|
||||
{
|
||||
return min;
|
||||
return;
|
||||
}
|
||||
for y in (0..height).rev() {
|
||||
let state = aquifer
|
||||
@@ -1071,11 +1095,10 @@ where
|
||||
.ok()
|
||||
.flatten()
|
||||
.unwrap_or(self.settings.default_block);
|
||||
if kind.is_opaque(self.data.states.get(state)) {
|
||||
return min + y + 1;
|
||||
if visit(min + y, state) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
min
|
||||
}
|
||||
}
|
||||
/// Biome and height queries for structure generation on one worker.
|
||||
@@ -1120,6 +1143,17 @@ where
|
||||
fn seed(&self) -> i64 {
|
||||
self.pipeline.seed
|
||||
}
|
||||
fn sea_level(&self) -> i32 {
|
||||
self.pipeline.settings.sea_level
|
||||
}
|
||||
fn base_column(&mut self, x: i32, z: i32, kind: HeightmapType) -> Vec<bool> {
|
||||
self.pipeline.base_column(x, z, kind)
|
||||
}
|
||||
fn cold_enough_to_snow(&mut self, biome: BiomeId, pos: [i32; 3]) -> bool {
|
||||
let sea = self.pipeline.settings.sea_level;
|
||||
self.worker.temperatures[biome.0 as usize]
|
||||
.cold_enough_to_snow(BlockPos::new(pos[0], pos[1], pos[2]), sea)
|
||||
}
|
||||
fn generation(&self) -> WorldGenerationContext {
|
||||
self.pipeline.generation()
|
||||
}
|
||||
@@ -1306,7 +1340,7 @@ where
|
||||
self.generation(),
|
||||
worker,
|
||||
region,
|
||||
|| random.next_boolean(),
|
||||
&mut random,
|
||||
self.structures.as_ref(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ impl Decoration {
|
||||
generation: WorldGenerationContext,
|
||||
worker: &mut WorkerState,
|
||||
region: &mut [ProtoChunk; 9],
|
||||
next_boolean: impl FnMut() -> bool,
|
||||
level_random: &mut dyn super::structure::legacy::PieceRandom,
|
||||
structures: Option<&super::generator_structures::StructureState>,
|
||||
) -> Result<DecorateStats, GeneratorError> {
|
||||
let center = region[4].position();
|
||||
@@ -294,14 +294,13 @@ impl Decoration {
|
||||
Ok(terrain) => terrain,
|
||||
Err(e) => return Err(resource(e.to_string())),
|
||||
};
|
||||
let mut next_boolean = next_boolean;
|
||||
let mut block_entities = Vec::new();
|
||||
for chunk in region.iter_mut() {
|
||||
block_entities.append(&mut chunk.block_entities);
|
||||
}
|
||||
let mut world = World {
|
||||
block_entities,
|
||||
next_boolean: &mut next_boolean,
|
||||
level_random,
|
||||
blocks: data
|
||||
.feature_resources
|
||||
.as_ref()
|
||||
@@ -417,7 +416,7 @@ impl Decoration {
|
||||
/// the FEATURES step's write radius, biome lookups through the biome zoom.
|
||||
struct World<'a> {
|
||||
block_entities: Vec<([i32; 3], crate::nbt::Compound)>,
|
||||
next_boolean: &'a mut dyn FnMut() -> bool,
|
||||
level_random: &'a mut dyn super::structure::legacy::PieceRandom,
|
||||
blocks: Option<&'a BlockBehavior>,
|
||||
region: TerrainRegion<'static, GenBlockStates>,
|
||||
biomes: BiomeRegion<BiomeId>,
|
||||
@@ -539,7 +538,13 @@ impl PlacementContext for World<'_> {
|
||||
.map_err(query)
|
||||
}
|
||||
fn next_world_boolean(&mut self) -> Result<bool, PlacementQueryError> {
|
||||
Ok((self.next_boolean)())
|
||||
Ok(self.level_random.boolean())
|
||||
}
|
||||
fn next_world_float(&mut self) -> Result<f32, PlacementQueryError> {
|
||||
Ok(self.level_random.float())
|
||||
}
|
||||
fn next_world_int(&mut self, bound: i32) -> Result<i32, PlacementQueryError> {
|
||||
Ok(self.level_random.int(bound))
|
||||
}
|
||||
fn block_survives(
|
||||
&mut self,
|
||||
|
||||
@@ -202,6 +202,12 @@ pub trait PlacementContext {
|
||||
fn next_world_boolean(&mut self) -> Result<bool, PlacementQueryError> {
|
||||
Err(PlacementQueryError::Unavailable)
|
||||
}
|
||||
fn next_world_float(&mut self) -> Result<f32, PlacementQueryError> {
|
||||
Err(PlacementQueryError::Unavailable)
|
||||
}
|
||||
fn next_world_int(&mut self, _bound: i32) -> Result<i32, PlacementQueryError> {
|
||||
Err(PlacementQueryError::Unavailable)
|
||||
}
|
||||
/// Schedule the block type identified by its registry default state.
|
||||
fn schedule_block_tick(
|
||||
&mut self,
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
//! and structure pieces.
|
||||
pub mod features;
|
||||
pub mod jigsaw;
|
||||
pub mod mansion;
|
||||
pub mod monument;
|
||||
pub mod legacy;
|
||||
pub mod ocean_ruin;
|
||||
pub mod processor;
|
||||
pub mod ruined_portal;
|
||||
pub mod simple;
|
||||
pub mod start;
|
||||
pub mod template;
|
||||
pub mod temple;
|
||||
|
||||
use crate::{
|
||||
nbt::{self, Limits},
|
||||
|
||||
@@ -48,6 +48,15 @@ pub trait PieceWorld {
|
||||
fn max_y(&mut self) -> Result<i32>;
|
||||
fn block_entity(&mut self, pos: [i32; 3], nbt: Compound) -> Result<()>;
|
||||
fn post_process(&mut self, pos: [i32; 3]) -> Result<()>;
|
||||
/// WorldGenLevel.getSeed.
|
||||
fn seed(&mut self) -> Result<i64>;
|
||||
/// Draws from WorldGenLevel.getRandom (the region random).
|
||||
fn level_boolean(&mut self) -> Result<bool>;
|
||||
fn level_float(&mut self) -> Result<f32>;
|
||||
fn level_int(&mut self, bound: i32) -> Result<i32>;
|
||||
fn sea_level(&mut self) -> Result<i32>;
|
||||
/// Block.isFaceFull of the block's shape at `pos` on face `direction`.
|
||||
fn face_full(&mut self, pos: [i32; 3], direction: Direction) -> Result<bool>;
|
||||
fn place_template(
|
||||
&mut self,
|
||||
resources: &StructureResources,
|
||||
@@ -85,6 +94,24 @@ impl<W: FeatureWorld + PlacementContext> PieceWorld for W {
|
||||
fn post_process(&mut self, pos: [i32; 3]) -> Result<()> {
|
||||
self.mark_postprocessing(pos)
|
||||
}
|
||||
fn seed(&mut self) -> Result<i64> {
|
||||
self.world_seed()
|
||||
}
|
||||
fn level_boolean(&mut self) -> Result<bool> {
|
||||
self.next_world_boolean()
|
||||
}
|
||||
fn level_float(&mut self) -> Result<f32> {
|
||||
self.next_world_float()
|
||||
}
|
||||
fn level_int(&mut self, bound: i32) -> Result<i32> {
|
||||
self.next_world_int(bound)
|
||||
}
|
||||
fn sea_level(&mut self) -> Result<i32> {
|
||||
PlacementContext::sea_level(self)
|
||||
}
|
||||
fn face_full(&mut self, pos: [i32; 3], direction: Direction) -> Result<bool> {
|
||||
self.attachment_at(offset(pos, direction, 1), opposite(direction))
|
||||
}
|
||||
fn place_template(
|
||||
&mut self,
|
||||
resources: &StructureResources,
|
||||
@@ -204,6 +231,11 @@ pub trait LegacyPiece: std::fmt::Debug + Send + Sync {
|
||||
/// The vanilla StructurePieceType id, for diagnostics and comparisons.
|
||||
fn type_name(&self) -> &'static str;
|
||||
fn post_process(&self, context: &mut PieceContext<'_>) -> Result<()>;
|
||||
/// Structure.afterPlace, run on the first piece once per chunk after all
|
||||
/// pieces were placed, with every piece's current box.
|
||||
fn after_place(&self, _context: &mut PieceContext<'_>, _pieces: &[BoundingBox]) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// StructurePiece's orientation transform and block helpers.
|
||||
@@ -674,6 +706,8 @@ pub enum TemplateHandler {
|
||||
large: bool,
|
||||
integrity: f32,
|
||||
},
|
||||
RuinedPortal(super::ruined_portal::PortalProps),
|
||||
Mansion,
|
||||
Plain,
|
||||
}
|
||||
impl TemplatePiece {
|
||||
|
||||
@@ -0,0 +1,879 @@
|
||||
//! Woodland mansions (WoodlandMansionStructure, WoodlandMansionPieces).
|
||||
use super::{
|
||||
BoundingBox, Mirror, Rotation, StructureResources,
|
||||
legacy::{
|
||||
HORIZONTAL, PieceContext, Result, TemplateHandler, TemplatePiece, clockwise,
|
||||
counter_clockwise, create_chest, direction_name, offset, opposite,
|
||||
},
|
||||
processor::ProcessorList,
|
||||
};
|
||||
use horizon_core::{geometry::Direction, random::RandomSource};
|
||||
use std::sync::Arc;
|
||||
|
||||
const CORRIDOR_FLAG: i32 = 8_388_608;
|
||||
const STAIRS_FLAG: i32 = 4_194_304;
|
||||
const DOOR_FLAG: i32 = 2_097_152;
|
||||
const ORIGIN_FLAG: i32 = 1_048_576;
|
||||
const TYPE_MASK: i32 = 983_040;
|
||||
const ID_MASK: i32 = 65_535;
|
||||
const ROOM_1X1: i32 = 65_536;
|
||||
const ROOM_1X2: i32 = 131_072;
|
||||
const ROOM_2X2: i32 = 262_144;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Grid {
|
||||
cells: Vec<i32>,
|
||||
width: i32,
|
||||
height: i32,
|
||||
outside: i32,
|
||||
}
|
||||
impl Grid {
|
||||
fn new(width: i32, height: i32, outside: i32) -> Self {
|
||||
Self {
|
||||
cells: vec![0; (width * height) as usize],
|
||||
width,
|
||||
height,
|
||||
outside,
|
||||
}
|
||||
}
|
||||
fn set(&mut self, x: i32, y: i32, value: i32) {
|
||||
if x >= 0 && x < self.width && y >= 0 && y < self.height {
|
||||
self.cells[(x * self.height + y) as usize] = value;
|
||||
}
|
||||
}
|
||||
fn fill(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, value: i32) {
|
||||
for y in y0..=y1 {
|
||||
for x in x0..=x1 {
|
||||
self.set(x, y, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn get(&self, x: i32, y: i32) -> i32 {
|
||||
if x >= 0 && x < self.width && y >= 0 && y < self.height {
|
||||
self.cells[(x * self.height + y) as usize]
|
||||
} else {
|
||||
self.outside
|
||||
}
|
||||
}
|
||||
fn set_if(&mut self, x: i32, y: i32, if_value: i32, value: i32) {
|
||||
if self.get(x, y) == if_value {
|
||||
self.set(x, y, value);
|
||||
}
|
||||
}
|
||||
fn edges_to(&self, x: i32, y: i32, value: i32) -> bool {
|
||||
self.get(x - 1, y) == value
|
||||
|| self.get(x + 1, y) == value
|
||||
|| self.get(x, y + 1) == value
|
||||
|| self.get(x, y - 1) == value
|
||||
}
|
||||
}
|
||||
fn is_house(grid: &Grid, x: i32, y: i32) -> bool {
|
||||
matches!(grid.get(x, y), 1..=4)
|
||||
}
|
||||
fn step(d: Direction) -> (i32, i32) {
|
||||
let n = d.normal();
|
||||
(n[0], n[2])
|
||||
}
|
||||
fn from_2d(value: i32) -> Direction {
|
||||
[
|
||||
Direction::South,
|
||||
Direction::West,
|
||||
Direction::North,
|
||||
Direction::East,
|
||||
][value as usize & 3]
|
||||
}
|
||||
fn shuffle<T>(list: &mut [T], random: &mut impl RandomSource) {
|
||||
for i in (2..=list.len()).rev() {
|
||||
let j = random.next_int_bound(i as i32).unwrap_or(0) as usize;
|
||||
list.swap(i - 1, j);
|
||||
}
|
||||
}
|
||||
|
||||
struct MansionGrid {
|
||||
base: Grid,
|
||||
third: Grid,
|
||||
rooms: [Grid; 3],
|
||||
entrance_x: i32,
|
||||
entrance_y: i32,
|
||||
}
|
||||
impl MansionGrid {
|
||||
fn new(r: &mut impl RandomSource) -> Self {
|
||||
let (ex, ey) = (7, 4);
|
||||
let mut base = Grid::new(11, 11, 5);
|
||||
base.fill(ex, ey, ex + 1, ey + 1, 3);
|
||||
base.fill(ex - 1, ey, ex - 1, ey + 1, 2);
|
||||
base.fill(ex + 2, ey - 2, ex + 3, ey + 3, 5);
|
||||
base.fill(ex + 1, ey - 2, ex + 1, ey - 1, 1);
|
||||
base.fill(ex + 1, ey + 2, ex + 1, ey + 3, 1);
|
||||
base.set(ex - 1, ey - 1, 1);
|
||||
base.set(ex - 1, ey + 2, 1);
|
||||
base.fill(0, 0, 11, 1, 5);
|
||||
base.fill(0, 9, 11, 11, 5);
|
||||
corridor(&mut base, r, ex, ey - 2, Direction::West, 6);
|
||||
corridor(&mut base, r, ex, ey + 3, Direction::West, 6);
|
||||
corridor(&mut base, r, ex - 2, ey - 1, Direction::West, 3);
|
||||
corridor(&mut base, r, ex - 2, ey + 2, Direction::West, 3);
|
||||
while clean_edges(&mut base) {}
|
||||
let mut rooms = [Grid::new(11, 11, 5), Grid::new(11, 11, 5), Grid::new(11, 11, 5)];
|
||||
identify_rooms(&base, &mut rooms[0], r);
|
||||
identify_rooms(&base, &mut rooms[1], r);
|
||||
rooms[0].fill(ex + 1, ey, ex + 1, ey + 1, CORRIDOR_FLAG);
|
||||
rooms[1].fill(ex + 1, ey, ex + 1, ey + 1, CORRIDOR_FLAG);
|
||||
let mut grid = Self {
|
||||
third: Grid::new(base.width, base.height, 5),
|
||||
base,
|
||||
rooms,
|
||||
entrance_x: ex,
|
||||
entrance_y: ey,
|
||||
};
|
||||
grid.setup_third_floor(r);
|
||||
let mut third_rooms = std::mem::replace(&mut grid.rooms[2], Grid::new(0, 0, 0));
|
||||
identify_rooms(&grid.third, &mut third_rooms, r);
|
||||
grid.rooms[2] = third_rooms;
|
||||
grid
|
||||
}
|
||||
fn is_room_id(&self, x: i32, y: i32, floor: usize, id: i32) -> bool {
|
||||
(self.rooms[floor].get(x, y) & ID_MASK) == id
|
||||
}
|
||||
fn room_direction_1x2(&self, x: i32, y: i32, floor: usize, id: i32) -> Option<Direction> {
|
||||
HORIZONTAL.into_iter().find(|&d| {
|
||||
let (dx, dz) = step(d);
|
||||
self.is_room_id(x + dx, y + dz, floor, id)
|
||||
})
|
||||
}
|
||||
fn setup_third_floor(&mut self, r: &mut impl RandomSource) {
|
||||
let mut potential = Vec::new();
|
||||
for y in 0..self.third.height {
|
||||
for x in 0..self.third.width {
|
||||
let data = self.rooms[1].get(x, y);
|
||||
if data & TYPE_MASK == ROOM_1X2 && data & DOOR_FLAG == DOOR_FLAG {
|
||||
potential.push((x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
let (w, h) = (self.third.width, self.third.height);
|
||||
if potential.is_empty() {
|
||||
self.third.fill(0, 0, w, h, 5);
|
||||
return;
|
||||
}
|
||||
let (rx, ry) = potential[r.next_int_bound(potential.len() as i32).unwrap_or(0) as usize];
|
||||
let data = self.rooms[1].get(rx, ry);
|
||||
self.rooms[1].set(rx, ry, data | STAIRS_FLAG);
|
||||
let Some(dir) = self.room_direction_1x2(rx, ry, 1, data & ID_MASK) else {
|
||||
return;
|
||||
};
|
||||
let (dx, dz) = step(dir);
|
||||
let (ex, ey) = (rx + dx, ry + dz);
|
||||
for y in 0..h {
|
||||
for x in 0..w {
|
||||
if !is_house(&self.base, x, y) {
|
||||
self.third.set(x, y, 5);
|
||||
} else if x == rx && y == ry {
|
||||
self.third.set(x, y, 3);
|
||||
} else if x == ex && y == ey {
|
||||
self.third.set(x, y, 3);
|
||||
self.rooms[2].set(x, y, CORRIDOR_FLAG);
|
||||
}
|
||||
}
|
||||
}
|
||||
let corridors: Vec<Direction> = HORIZONTAL
|
||||
.into_iter()
|
||||
.filter(|&d| {
|
||||
let (dx, dz) = step(d);
|
||||
self.third.get(ex + dx, ey + dz) == 0
|
||||
})
|
||||
.collect();
|
||||
if corridors.is_empty() {
|
||||
self.third.fill(0, 0, w, h, 5);
|
||||
self.rooms[1].set(rx, ry, data);
|
||||
} else {
|
||||
let d = corridors[r.next_int_bound(corridors.len() as i32).unwrap_or(0) as usize];
|
||||
let (dx, dz) = step(d);
|
||||
corridor(&mut self.third, r, ex + dx, ey + dz, d, 4);
|
||||
while clean_edges(&mut self.third) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
fn corridor(g: &mut Grid, r: &mut impl RandomSource, x: i32, y: i32, heading: Direction, depth: i32) {
|
||||
if depth <= 0 {
|
||||
return;
|
||||
}
|
||||
let (hx, hz) = step(heading);
|
||||
g.set(x, y, 1);
|
||||
g.set_if(x + hx, y + hz, 0, 1);
|
||||
for _ in 0..8 {
|
||||
let next = from_2d(r.next_int_bound(4).unwrap_or(0));
|
||||
if next != opposite(heading) && (next != Direction::East || !r.next_boolean()) {
|
||||
let (nx, ny) = (x + hx, y + hz);
|
||||
let (dx, dz) = step(next);
|
||||
if g.get(nx + dx, ny + dz) == 0 && g.get(nx + dx * 2, ny + dz * 2) == 0 {
|
||||
corridor(g, r, x + hx + dx, y + hz + dz, next, depth - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
let (cx, cz) = step(clockwise(heading));
|
||||
let (ax, az) = step(counter_clockwise(heading));
|
||||
g.set_if(x + cx, y + cz, 0, 2);
|
||||
g.set_if(x + ax, y + az, 0, 2);
|
||||
g.set_if(x + hx + cx, y + hz + cz, 0, 2);
|
||||
g.set_if(x + hx + ax, y + hz + az, 0, 2);
|
||||
g.set_if(x + hx * 2, y + hz * 2, 0, 2);
|
||||
g.set_if(x + cx * 2, y + cz * 2, 0, 2);
|
||||
g.set_if(x + ax * 2, y + az * 2, 0, 2);
|
||||
}
|
||||
fn clean_edges(g: &mut Grid) -> bool {
|
||||
let mut touched = false;
|
||||
for y in 0..g.height {
|
||||
for x in 0..g.width {
|
||||
if g.get(x, y) != 0 {
|
||||
continue;
|
||||
}
|
||||
let house = |g: &Grid, x, y| i32::from(is_house(g, x, y));
|
||||
let direct = house(g, x + 1, y) + house(g, x - 1, y) + house(g, x, y + 1) + house(g, x, y - 1);
|
||||
if direct >= 3 {
|
||||
g.set(x, y, 2);
|
||||
touched = true;
|
||||
} else if direct == 2 {
|
||||
let diagonal = house(g, x + 1, y + 1)
|
||||
+ house(g, x - 1, y + 1)
|
||||
+ house(g, x + 1, y - 1)
|
||||
+ house(g, x - 1, y - 1);
|
||||
if diagonal <= 1 {
|
||||
g.set(x, y, 2);
|
||||
touched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
touched
|
||||
}
|
||||
fn identify_rooms(from: &Grid, rooms: &mut Grid, r: &mut impl RandomSource) {
|
||||
let mut positions = Vec::new();
|
||||
for y in 0..from.height {
|
||||
for x in 0..from.width {
|
||||
if from.get(x, y) == 2 {
|
||||
positions.push((x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
shuffle(&mut positions, r);
|
||||
let mut id = 10;
|
||||
for (x, y) in positions {
|
||||
if rooms.get(x, y) != 0 {
|
||||
continue;
|
||||
}
|
||||
let (mut x0, mut x1, mut y0, mut y1) = (x, x, y, y);
|
||||
let mut kind = ROOM_1X1;
|
||||
let free = |dx: i32, dy: i32| rooms.get(x + dx, y + dy) == 0 && from.get(x + dx, y + dy) == 2;
|
||||
if free(1, 0) && free(0, 1) && free(1, 1) {
|
||||
x1 += 1;
|
||||
y1 += 1;
|
||||
kind = ROOM_2X2;
|
||||
} else if free(-1, 0) && free(0, 1) && free(-1, 1) {
|
||||
x0 -= 1;
|
||||
y1 += 1;
|
||||
kind = ROOM_2X2;
|
||||
} else if free(-1, 0) && free(0, -1) && free(-1, -1) {
|
||||
x0 -= 1;
|
||||
y0 -= 1;
|
||||
kind = ROOM_2X2;
|
||||
} else if free(1, 0) {
|
||||
x1 += 1;
|
||||
kind = ROOM_1X2;
|
||||
} else if free(0, 1) {
|
||||
y1 += 1;
|
||||
kind = ROOM_1X2;
|
||||
} else if free(-1, 0) {
|
||||
x0 -= 1;
|
||||
kind = ROOM_1X2;
|
||||
} else if free(0, -1) {
|
||||
y0 -= 1;
|
||||
kind = ROOM_1X2;
|
||||
}
|
||||
let mut door_x = if r.next_boolean() { x0 } else { x1 };
|
||||
let mut door_y = if r.next_boolean() { y0 } else { y1 };
|
||||
let mut door = DOOR_FLAG;
|
||||
let swap = |v: i32, a: i32, b: i32| if v == a { b } else { a };
|
||||
if !from.edges_to(door_x, door_y, 1) {
|
||||
door_x = swap(door_x, x0, x1);
|
||||
door_y = swap(door_y, y0, y1);
|
||||
if !from.edges_to(door_x, door_y, 1) {
|
||||
door_y = swap(door_y, y0, y1);
|
||||
if !from.edges_to(door_x, door_y, 1) {
|
||||
door_x = swap(door_x, x0, x1);
|
||||
door_y = swap(door_y, y0, y1);
|
||||
if !from.edges_to(door_x, door_y, 1) {
|
||||
door = 0;
|
||||
door_x = x0;
|
||||
door_y = y0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for ry in y0..=y1 {
|
||||
for rx in x0..=x1 {
|
||||
if rx == door_x && ry == door_y {
|
||||
rooms.set(rx, ry, ORIGIN_FLAG | door | kind | id);
|
||||
} else {
|
||||
rooms.set(rx, ry, kind | id);
|
||||
}
|
||||
}
|
||||
}
|
||||
id += 1;
|
||||
}
|
||||
}
|
||||
|
||||
struct Piece {
|
||||
name: String,
|
||||
position: [i32; 3],
|
||||
rotation: Rotation,
|
||||
mirror: Mirror,
|
||||
}
|
||||
struct Placement {
|
||||
position: [i32; 3],
|
||||
rotation: Rotation,
|
||||
wall: &'static str,
|
||||
}
|
||||
fn up(p: [i32; 3], n: i32) -> [i32; 3] {
|
||||
[p[0], p[1] + n, p[2]]
|
||||
}
|
||||
fn rel(p: [i32; 3], rotation: Rotation, d: Direction, n: i32) -> [i32; 3] {
|
||||
offset(p, rotation.rotate_direction(d), n)
|
||||
}
|
||||
/// One floor's room-template choices (First/Second/ThirdFloorRoomCollection).
|
||||
fn room_name(floor: usize, kind: &str, r: &mut impl RandomSource, stairs: bool) -> String {
|
||||
let mut n = |b: i32| r.next_int_bound(b).unwrap_or(0) + 1;
|
||||
if floor == 0 {
|
||||
match kind {
|
||||
"1x1" => format!("1x1_a{}", n(5)),
|
||||
"1x1s" => format!("1x1_as{}", n(4)),
|
||||
"side" => format!("1x2_a{}", n(9)),
|
||||
"front" => format!("1x2_b{}", n(5)),
|
||||
"1x2s" => format!("1x2_s{}", n(2)),
|
||||
"2x2" => format!("2x2_a{}", n(4)),
|
||||
_ => "2x2_s1".into(),
|
||||
}
|
||||
} else {
|
||||
match kind {
|
||||
"1x1" => format!("1x1_b{}", n(5)),
|
||||
"1x1s" => format!("1x1_as{}", n(4)),
|
||||
"side" if stairs => "1x2_c_stairs".into(),
|
||||
"side" => format!("1x2_c{}", n(4)),
|
||||
"front" if stairs => "1x2_d_stairs".into(),
|
||||
"front" => format!("1x2_d{}", n(5)),
|
||||
"1x2s" => format!("1x2_se{}", n(1)),
|
||||
"2x2" => format!("2x2_b{}", n(5)),
|
||||
_ => "2x2_s1".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
struct Placer<'a, R: RandomSource> {
|
||||
random: &'a mut R,
|
||||
pieces: Vec<Piece>,
|
||||
start_x: i32,
|
||||
start_y: i32,
|
||||
}
|
||||
impl<R: RandomSource> Placer<'_, R> {
|
||||
fn add(&mut self, name: impl Into<String>, position: [i32; 3], rotation: Rotation, mirror: Mirror) {
|
||||
self.pieces.push(Piece {
|
||||
name: name.into(),
|
||||
position,
|
||||
rotation,
|
||||
mirror,
|
||||
});
|
||||
}
|
||||
fn grid_pos(&self, origin: [i32; 3], rotation: Rotation, x: i32, y: i32, east: i32) -> [i32; 3] {
|
||||
let p = rel(origin, rotation, Direction::South, 8 + (y - self.start_y) * 8);
|
||||
rel(p, rotation, Direction::East, east + (x - self.start_x) * 8)
|
||||
}
|
||||
fn create(&mut self, origin: [i32; 3], rotation: Rotation, mansion: &MansionGrid) {
|
||||
let mut data = Placement {
|
||||
position: origin,
|
||||
rotation,
|
||||
wall: "wall_flat",
|
||||
};
|
||||
let west = rotation.rotate_direction(Direction::West);
|
||||
self.add("entrance", offset(data.position, west, 9), rotation, Mirror::None);
|
||||
data.position = rel(data.position, rotation, Direction::South, 16);
|
||||
let mut second = Placement {
|
||||
position: up(data.position, 8),
|
||||
rotation: data.rotation,
|
||||
wall: "wall_window",
|
||||
};
|
||||
let (base, third) = (&mansion.base, &mansion.third);
|
||||
self.start_x = mansion.entrance_x + 1;
|
||||
self.start_y = mansion.entrance_y + 1;
|
||||
let (end_x, end_y) = (mansion.entrance_x + 1, mansion.entrance_y);
|
||||
let (sx, sy) = (self.start_x, self.start_y);
|
||||
self.outer_walls(&mut data, base, Direction::South, sx, sy, end_x, end_y);
|
||||
self.outer_walls(&mut second, base, Direction::South, sx, sy, end_x, end_y);
|
||||
let mut third_data = Placement {
|
||||
position: up(data.position, 19),
|
||||
rotation: data.rotation,
|
||||
wall: "wall_window",
|
||||
};
|
||||
'done: for y in 0..third.height {
|
||||
for x in (0..third.width).rev() {
|
||||
if is_house(third, x, y) {
|
||||
third_data.position = self.grid_pos(third_data.position, rotation, x, y, 0);
|
||||
self.wall_piece(&mut third_data);
|
||||
self.outer_walls(&mut third_data, third, Direction::South, x, y, x, y);
|
||||
break 'done;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.roof(up(origin, 16), rotation, base, Some(third));
|
||||
self.roof(up(origin, 27), rotation, third, None);
|
||||
for floor in 0..3 {
|
||||
let floor_origin = up(origin, 8 * floor as i32 + if floor == 2 { 3 } else { 0 });
|
||||
let rooms = &mansion.rooms[floor];
|
||||
let grid = if floor == 2 { third } else { base };
|
||||
let south_piece = if floor == 0 { "carpet_south_1" } else { "carpet_south_2" };
|
||||
let west_piece = if floor == 0 { "carpet_west_1" } else { "carpet_west_2" };
|
||||
let corridor = |x, y| grid.get(x, y) == 1 || rooms.get(x, y) & CORRIDOR_FLAG == CORRIDOR_FLAG;
|
||||
for y in 0..grid.height {
|
||||
for x in 0..grid.width {
|
||||
if grid.get(x, y) != 1 {
|
||||
continue;
|
||||
}
|
||||
let pos = self.grid_pos(floor_origin, rotation, x, y, 0);
|
||||
self.add("corridor_floor", pos, rotation, Mirror::None);
|
||||
if corridor(x, y - 1) {
|
||||
let p = up(rel(pos, rotation, Direction::East, 1), 1);
|
||||
self.add("carpet_north", p, rotation, Mirror::None);
|
||||
}
|
||||
if corridor(x + 1, y) {
|
||||
let p = rel(pos, rotation, Direction::South, 1);
|
||||
let p = up(rel(p, rotation, Direction::East, 5), 1);
|
||||
self.add("carpet_east", p, rotation, Mirror::None);
|
||||
}
|
||||
if corridor(x, y + 1) {
|
||||
let p = rel(pos, rotation, Direction::South, 5);
|
||||
let p = rel(p, rotation, Direction::West, 1);
|
||||
self.add(south_piece, p, rotation, Mirror::None);
|
||||
}
|
||||
if corridor(x - 1, y) {
|
||||
let p = rel(pos, rotation, Direction::West, 1);
|
||||
let p = rel(p, rotation, Direction::North, 1);
|
||||
self.add(west_piece, p, rotation, Mirror::None);
|
||||
}
|
||||
}
|
||||
}
|
||||
let wall = if floor == 0 { "indoors_wall_1" } else { "indoors_wall_2" };
|
||||
let door = if floor == 0 { "indoors_door_1" } else { "indoors_door_2" };
|
||||
for y in 0..grid.height {
|
||||
for x in 0..grid.width {
|
||||
let mut third_start = floor == 2 && grid.get(x, y) == 3;
|
||||
if grid.get(x, y) != 2 && !third_start {
|
||||
continue;
|
||||
}
|
||||
let data = rooms.get(x, y);
|
||||
let kind = data & TYPE_MASK;
|
||||
let id = data & ID_MASK;
|
||||
third_start = third_start && data & CORRIDOR_FLAG == CORRIDOR_FLAG;
|
||||
let mut doors = Vec::new();
|
||||
if data & DOOR_FLAG == DOOR_FLAG {
|
||||
for d in HORIZONTAL {
|
||||
let (dx, dz) = step(d);
|
||||
if grid.get(x + dx, y + dz) == 1 {
|
||||
doors.push(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
let door_dir = if !doors.is_empty() {
|
||||
Some(doors[self.random.next_int_bound(doors.len() as i32).unwrap_or(0) as usize])
|
||||
} else if data & ORIGIN_FLAG == ORIGIN_FLAG {
|
||||
Some(Direction::Up)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let room_pos = self.grid_pos(floor_origin, rotation, x, y, -1);
|
||||
let pick = |d: Direction| if door_dir == Some(d) { door } else { wall };
|
||||
if is_house(grid, x - 1, y) && !mansion.is_room_id(x - 1, y, floor, id) {
|
||||
self.add(pick(Direction::West), room_pos, rotation, Mirror::None);
|
||||
}
|
||||
if grid.get(x + 1, y) == 1 && !third_start {
|
||||
let p = rel(room_pos, rotation, Direction::East, 8);
|
||||
self.add(pick(Direction::East), p, rotation, Mirror::None);
|
||||
}
|
||||
let cw90 = rotation.get_rotated(Rotation::Clockwise90);
|
||||
if is_house(grid, x, y + 1) && !mansion.is_room_id(x, y + 1, floor, id) {
|
||||
let p = rel(room_pos, rotation, Direction::South, 7);
|
||||
let p = rel(p, rotation, Direction::East, 7);
|
||||
self.add(pick(Direction::South), p, cw90, Mirror::None);
|
||||
}
|
||||
if grid.get(x, y - 1) == 1 && !third_start {
|
||||
let p = rel(room_pos, rotation, Direction::North, 1);
|
||||
let p = rel(p, rotation, Direction::East, 7);
|
||||
self.add(pick(Direction::North), p, cw90, Mirror::None);
|
||||
}
|
||||
if kind == ROOM_1X1 {
|
||||
self.room_1x1(room_pos, rotation, door_dir, floor);
|
||||
} else if kind == ROOM_1X2 && door_dir.is_some() {
|
||||
let room_dir = mansion.room_direction_1x2(x, y, floor, id);
|
||||
let stairs = data & STAIRS_FLAG == STAIRS_FLAG;
|
||||
if let (Some(room_dir), Some(door_dir)) = (room_dir, door_dir) {
|
||||
self.room_1x2(room_pos, rotation, room_dir, door_dir, floor, stairs);
|
||||
}
|
||||
} else if kind == ROOM_2X2 && door_dir.is_some_and(|d| d != Direction::Up) {
|
||||
let door_dir = door_dir.unwrap();
|
||||
let mut room_dir = clockwise(door_dir);
|
||||
let (dx, dz) = step(room_dir);
|
||||
if !mansion.is_room_id(x + dx, y + dz, floor, id) {
|
||||
room_dir = opposite(room_dir);
|
||||
}
|
||||
self.room_2x2(room_pos, rotation, room_dir, door_dir, floor);
|
||||
} else if kind == ROOM_2X2 && door_dir == Some(Direction::Up) {
|
||||
let name = room_name(floor, "2x2s", self.random, false);
|
||||
let p = rel(room_pos, rotation, Direction::East, 1);
|
||||
self.add(name, p, rotation, Mirror::None);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn outer_walls(
|
||||
&mut self,
|
||||
data: &mut Placement,
|
||||
grid: &Grid,
|
||||
direction: Direction,
|
||||
start_x: i32,
|
||||
start_y: i32,
|
||||
end_x: i32,
|
||||
end_y: i32,
|
||||
) {
|
||||
let (mut gx, mut gy, mut dir) = (start_x, start_y, direction);
|
||||
let start_dir = direction;
|
||||
loop {
|
||||
let (dx, dz) = step(dir);
|
||||
if !is_house(grid, gx + dx, gy + dz) {
|
||||
data.position = rel(data.position, data.rotation, Direction::South, -1);
|
||||
self.add("wall_corner", data.position, data.rotation, Mirror::None);
|
||||
data.position = rel(data.position, data.rotation, Direction::South, -7);
|
||||
data.position = rel(data.position, data.rotation, Direction::West, -6);
|
||||
data.rotation = data.rotation.get_rotated(Rotation::Clockwise90);
|
||||
dir = clockwise(dir);
|
||||
if gx != end_x || gy != end_y || start_dir != dir {
|
||||
self.wall_piece(data);
|
||||
}
|
||||
} else if {
|
||||
let (cx, cz) = step(counter_clockwise(dir));
|
||||
is_house(grid, gx + dx + cx, gy + dz + cz)
|
||||
} {
|
||||
data.position = rel(data.position, data.rotation, Direction::South, 6);
|
||||
data.position = rel(data.position, data.rotation, Direction::East, 8);
|
||||
data.rotation = data.rotation.get_rotated(Rotation::Counterclockwise90);
|
||||
gx += dx;
|
||||
gy += dz;
|
||||
dir = counter_clockwise(dir);
|
||||
} else {
|
||||
gx += dx;
|
||||
gy += dz;
|
||||
if gx != end_x || gy != end_y || start_dir != dir {
|
||||
self.wall_piece(data);
|
||||
}
|
||||
}
|
||||
if gx == end_x && gy == end_y && start_dir == dir {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fn wall_piece(&mut self, data: &mut Placement) {
|
||||
let p = rel(data.position, data.rotation, Direction::East, 7);
|
||||
self.add(data.wall, p, data.rotation, Mirror::None);
|
||||
data.position = rel(data.position, data.rotation, Direction::South, 8);
|
||||
}
|
||||
fn roof(&mut self, origin: [i32; 3], rotation: Rotation, grid: &Grid, above: Option<&Grid>) {
|
||||
use Direction::{East, North, South, West};
|
||||
let r = |rot: Rotation| rotation.get_rotated(rot);
|
||||
let (cw90, cw180, ccw90) = (
|
||||
r(Rotation::Clockwise90),
|
||||
r(Rotation::Clockwise180),
|
||||
r(Rotation::Counterclockwise90),
|
||||
);
|
||||
let none = Mirror::None;
|
||||
for y in 0..grid.height {
|
||||
for x in 0..grid.width {
|
||||
let pos = self.grid_pos(origin, rotation, x, y, 0);
|
||||
let is_above = above.is_some_and(|a| is_house(a, x, y));
|
||||
if !is_house(grid, x, y) || is_above {
|
||||
continue;
|
||||
}
|
||||
self.add("roof", up(pos, 3), rotation, none);
|
||||
if !is_house(grid, x + 1, y) {
|
||||
self.add("roof_front", rel(pos, rotation, East, 6), rotation, none);
|
||||
}
|
||||
if !is_house(grid, x - 1, y) {
|
||||
let p = rel(rel(pos, rotation, East, 0), rotation, South, 7);
|
||||
self.add("roof_front", p, cw180, none);
|
||||
}
|
||||
if !is_house(grid, x, y - 1) {
|
||||
self.add("roof_front", rel(pos, rotation, West, 1), ccw90, none);
|
||||
}
|
||||
if !is_house(grid, x, y + 1) {
|
||||
let p = rel(rel(pos, rotation, East, 6), rotation, South, 6);
|
||||
self.add("roof_front", p, cw90, none);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(above) = above {
|
||||
for y in 0..grid.height {
|
||||
for x in 0..grid.width {
|
||||
let pos = self.grid_pos(origin, rotation, x, y, 0);
|
||||
if !(is_house(grid, x, y) && is_house(above, x, y)) {
|
||||
continue;
|
||||
}
|
||||
if !is_house(grid, x + 1, y) {
|
||||
self.add("small_wall", rel(pos, rotation, East, 7), rotation, none);
|
||||
}
|
||||
if !is_house(grid, x - 1, y) {
|
||||
let p = rel(rel(pos, rotation, West, 1), rotation, South, 6);
|
||||
self.add("small_wall", p, cw180, none);
|
||||
}
|
||||
if !is_house(grid, x, y - 1) {
|
||||
let p = rel(rel(pos, rotation, West, 0), rotation, North, 1);
|
||||
self.add("small_wall", p, ccw90, none);
|
||||
}
|
||||
if !is_house(grid, x, y + 1) {
|
||||
let p = rel(rel(pos, rotation, East, 6), rotation, South, 7);
|
||||
self.add("small_wall", p, cw90, none);
|
||||
}
|
||||
if !is_house(grid, x + 1, y) {
|
||||
if !is_house(grid, x, y - 1) {
|
||||
let p = rel(rel(pos, rotation, East, 7), rotation, North, 2);
|
||||
self.add("small_wall_corner", p, rotation, none);
|
||||
}
|
||||
if !is_house(grid, x, y + 1) {
|
||||
let p = rel(rel(pos, rotation, East, 8), rotation, South, 7);
|
||||
self.add("small_wall_corner", p, cw90, none);
|
||||
}
|
||||
}
|
||||
if !is_house(grid, x - 1, y) {
|
||||
if !is_house(grid, x, y - 1) {
|
||||
let p = rel(rel(pos, rotation, West, 2), rotation, North, 1);
|
||||
self.add("small_wall_corner", p, ccw90, none);
|
||||
}
|
||||
if !is_house(grid, x, y + 1) {
|
||||
let p = rel(rel(pos, rotation, West, 1), rotation, South, 8);
|
||||
self.add("small_wall_corner", p, cw180, none);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for y in 0..grid.height {
|
||||
for x in 0..grid.width {
|
||||
let pos = self.grid_pos(origin, rotation, x, y, 0);
|
||||
let is_above = above.is_some_and(|a| is_house(a, x, y));
|
||||
if !is_house(grid, x, y) || is_above {
|
||||
continue;
|
||||
}
|
||||
if !is_house(grid, x + 1, y) {
|
||||
let p2 = rel(pos, rotation, East, 6);
|
||||
if !is_house(grid, x, y + 1) {
|
||||
self.add("roof_corner", rel(p2, rotation, South, 6), rotation, none);
|
||||
} else if is_house(grid, x + 1, y + 1) {
|
||||
self.add("roof_inner_corner", rel(p2, rotation, South, 5), rotation, none);
|
||||
}
|
||||
if !is_house(grid, x, y - 1) {
|
||||
self.add("roof_corner", p2, ccw90, none);
|
||||
} else if is_house(grid, x + 1, y - 1) {
|
||||
let p3 = rel(rel(pos, rotation, East, 9), rotation, North, 2);
|
||||
self.add("roof_inner_corner", p3, cw90, none);
|
||||
}
|
||||
}
|
||||
if !is_house(grid, x - 1, y) {
|
||||
let p2 = rel(rel(pos, rotation, East, 0), rotation, South, 0);
|
||||
if !is_house(grid, x, y + 1) {
|
||||
self.add("roof_corner", rel(p2, rotation, South, 6), cw90, none);
|
||||
} else if is_house(grid, x - 1, y + 1) {
|
||||
let p3 = rel(rel(p2, rotation, South, 8), rotation, West, 3);
|
||||
self.add("roof_inner_corner", p3, ccw90, none);
|
||||
}
|
||||
if !is_house(grid, x, y - 1) {
|
||||
self.add("roof_corner", p2, cw180, none);
|
||||
} else if is_house(grid, x - 1, y - 1) {
|
||||
self.add("roof_inner_corner", rel(p2, rotation, South, 1), cw180, none);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fn room_1x1(&mut self, room_pos: [i32; 3], rotation: Rotation, door: Option<Direction>, floor: usize) {
|
||||
let mut piece_rot = Rotation::None;
|
||||
let mut name = room_name(floor, "1x1", self.random, false);
|
||||
if door != Some(Direction::East) {
|
||||
match door {
|
||||
Some(Direction::North) => piece_rot = Rotation::Counterclockwise90,
|
||||
Some(Direction::West) => piece_rot = Rotation::Clockwise180,
|
||||
Some(Direction::South) => piece_rot = Rotation::Clockwise90,
|
||||
_ => name = room_name(floor, "1x1s", self.random, false),
|
||||
}
|
||||
}
|
||||
let o = match piece_rot {
|
||||
Rotation::Counterclockwise90 => [1, 0, 6],
|
||||
Rotation::Clockwise90 => [7, 0, 0],
|
||||
Rotation::Clockwise180 => [7, 0, 6],
|
||||
Rotation::None => [1, 0, 0],
|
||||
};
|
||||
let piece_rot = piece_rot.get_rotated(rotation);
|
||||
let o = match rotation {
|
||||
Rotation::Clockwise90 => [-o[2], o[1], o[0]],
|
||||
Rotation::Clockwise180 => [-o[0], o[1], -o[2]],
|
||||
Rotation::Counterclockwise90 => [o[2], o[1], -o[0]],
|
||||
Rotation::None => o,
|
||||
};
|
||||
let pos = [room_pos[0] + o[0], room_pos[1], room_pos[2] + o[2]];
|
||||
self.add(name, pos, piece_rot, Mirror::None);
|
||||
}
|
||||
fn room_1x2(
|
||||
&mut self,
|
||||
room_pos: [i32; 3],
|
||||
rotation: Rotation,
|
||||
room: Direction,
|
||||
door: Direction,
|
||||
floor: usize,
|
||||
stairs: bool,
|
||||
) {
|
||||
use Direction::{East, North, South, Up, West};
|
||||
let r = |rot: Rotation| rotation.get_rotated(rot);
|
||||
let at = |east: i32, south: i32| {
|
||||
rel(rel(room_pos, rotation, East, east), rotation, South, south)
|
||||
};
|
||||
let (kind, pos, rot, mirror) = match (door, room) {
|
||||
(East, South) => ("side", at(1, 0), rotation, Mirror::None),
|
||||
(East, North) => ("side", at(1, 6), rotation, Mirror::LeftRight),
|
||||
(West, North) => ("side", at(7, 6), r(Rotation::Clockwise180), Mirror::None),
|
||||
(West, South) => ("side", at(7, 0), rotation, Mirror::FrontBack),
|
||||
(South, East) => ("side", at(1, 0), r(Rotation::Clockwise90), Mirror::LeftRight),
|
||||
(South, West) => ("side", at(7, 0), r(Rotation::Clockwise90), Mirror::None),
|
||||
(North, West) => ("side", at(7, 6), r(Rotation::Clockwise90), Mirror::FrontBack),
|
||||
(North, East) => ("side", at(1, 6), r(Rotation::Counterclockwise90), Mirror::None),
|
||||
(South, North) => ("front", at(1, -8), rotation, Mirror::None),
|
||||
(North, South) => ("front", at(7, 14), r(Rotation::Clockwise180), Mirror::None),
|
||||
(West, East) => ("front", at(15, 0), r(Rotation::Clockwise90), Mirror::None),
|
||||
(East, West) => ("front", at(-7, 6), r(Rotation::Counterclockwise90), Mirror::None),
|
||||
(Up, East) => ("1x2s", at(15, 0), r(Rotation::Clockwise90), Mirror::None),
|
||||
(Up, South) => ("1x2s", at(1, 0), rotation, Mirror::None),
|
||||
_ => return,
|
||||
};
|
||||
let name = room_name(floor, kind, self.random, stairs);
|
||||
self.add(name, pos, rot, mirror);
|
||||
}
|
||||
fn room_2x2(&mut self, room_pos: [i32; 3], rotation: Rotation, room: Direction, door: Direction, floor: usize) {
|
||||
use Direction::{East, North, South, West};
|
||||
let r = |rot: Rotation| rotation.get_rotated(rot);
|
||||
let (east, south, rot, mirror) = match (door, room) {
|
||||
(East, South) => (-7, 0, rotation, Mirror::None),
|
||||
(East, North) => (-7, 6, rotation, Mirror::LeftRight),
|
||||
(North, East) => (1, 14, r(Rotation::Counterclockwise90), Mirror::None),
|
||||
(North, West) => (7, 14, r(Rotation::Counterclockwise90), Mirror::LeftRight),
|
||||
(South, West) => (7, -8, r(Rotation::Clockwise90), Mirror::None),
|
||||
(South, East) => (1, -8, r(Rotation::Clockwise90), Mirror::LeftRight),
|
||||
(West, North) => (15, 6, r(Rotation::Clockwise180), Mirror::None),
|
||||
(West, South) => (15, 0, rotation, Mirror::FrontBack),
|
||||
_ => (0, 0, rotation, Mirror::None),
|
||||
};
|
||||
let pos = rel(rel(room_pos, rotation, East, east), rotation, South, south);
|
||||
let name = room_name(floor, "2x2", self.random, false);
|
||||
self.add(name, pos, rot, mirror);
|
||||
}
|
||||
}
|
||||
|
||||
/// WoodlandMansionPieces.generateMansion.
|
||||
pub fn pieces(
|
||||
resources: &StructureResources,
|
||||
origin: [i32; 3],
|
||||
rotation: Rotation,
|
||||
random: &mut impl RandomSource,
|
||||
) -> Option<Vec<TemplatePiece>> {
|
||||
let grid = MansionGrid::new(random);
|
||||
let mut placer = Placer {
|
||||
random,
|
||||
pieces: Vec::new(),
|
||||
start_x: 0,
|
||||
start_y: 0,
|
||||
};
|
||||
placer.create(origin, rotation, &grid);
|
||||
let processors = Arc::new(ProcessorList::default());
|
||||
placer
|
||||
.pieces
|
||||
.into_iter()
|
||||
.map(|p| {
|
||||
let name = format!("minecraft:woodland_mansion/{}", p.name);
|
||||
Some(TemplatePiece::new(
|
||||
"minecraft:wmp",
|
||||
&name,
|
||||
resources.template(&name)?,
|
||||
p.position,
|
||||
p.rotation,
|
||||
p.mirror,
|
||||
[0; 3],
|
||||
processors.clone(),
|
||||
true,
|
||||
vec!["minecraft:structure_block".into()],
|
||||
TemplateHandler::Mansion,
|
||||
))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// WoodlandMansionPiece.postProcess with its data markers.
|
||||
pub fn post_process(piece: &TemplatePiece, c: &mut PieceContext<'_>) -> Result<()> {
|
||||
let Some(markers) = piece.place_at(c, piece.position, &[])? else {
|
||||
return Ok(());
|
||||
};
|
||||
for (marker, pos) in markers {
|
||||
if marker.starts_with("Chest") {
|
||||
let facing = match marker.as_str() {
|
||||
"ChestWest" => Direction::West,
|
||||
"ChestEast" => Direction::East,
|
||||
"ChestSouth" => Direction::South,
|
||||
_ => Direction::North,
|
||||
};
|
||||
let facing = if marker == "Chest" {
|
||||
Direction::North
|
||||
} else {
|
||||
piece.rotation.rotate_direction(facing)
|
||||
};
|
||||
let state = c.state_with("chest", &[("facing", direction_name(facing))]);
|
||||
create_chest(c, pos, "minecraft:chests/woodland_mansion", Some(state))?;
|
||||
} else if matches!(marker.as_str(), "Mage" | "Warrior" | "Group of Allays") {
|
||||
// Mobs are not spawned; the marker is cleared as after a spawn.
|
||||
if marker == "Group of Allays" {
|
||||
c.world.level_int(3)?;
|
||||
}
|
||||
c.world.set(pos, c.state("air"), 2)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// WoodlandMansionStructure.afterPlace: cobblestone columns under the pieces.
|
||||
pub fn after_place(c: &mut PieceContext<'_>, boxes: &[BoundingBox]) -> Result<()> {
|
||||
let min_y = c.world.min_y()?;
|
||||
let bb = super::temple::union(boxes);
|
||||
let y_start = bb.min[1];
|
||||
let cobble = c.state("cobblestone");
|
||||
for x in c.chunk_box.min[0]..=c.chunk_box.max[0] {
|
||||
for z in c.chunk_box.min[2]..=c.chunk_box.max[2] {
|
||||
let pos = [x, y_start, z];
|
||||
let state = c.world.block(pos)?;
|
||||
if c.is_air(state) || !bb.is_inside(pos) || !boxes.iter().any(|b| b.is_inside(pos)) {
|
||||
continue;
|
||||
}
|
||||
let mut y = y_start - 1;
|
||||
while y > min_y {
|
||||
let state = c.world.block([x, y, z])?;
|
||||
if !c.is_air(state) && !c.is_liquid(state) {
|
||||
break;
|
||||
}
|
||||
c.world.set([x, y, z], cobble, 2)?;
|
||||
y -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -86,6 +86,7 @@ pub enum Processor {
|
||||
JigsawReplacement,
|
||||
BlockAge(f32),
|
||||
LavaSubmerged,
|
||||
BlackstoneReplace,
|
||||
}
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct ProcessorList(pub Vec<Processor>);
|
||||
@@ -195,6 +196,7 @@ impl Processor {
|
||||
"minecraft:jigsaw_replacement" => Self::JigsawReplacement,
|
||||
"minecraft:block_age" => Self::BlockAge(float(value, "mossiness")?),
|
||||
"minecraft:lava_submerged_block" => Self::LavaSubmerged,
|
||||
"minecraft:blackstone_replace" => Self::BlackstoneReplace,
|
||||
"minecraft:capped" => Self::Capped {
|
||||
delegate: Box::new(Self::decode(&value["delegate"], resources, bindings)?),
|
||||
limit: IntProvider::from_json(&value["limit"].to_string())?,
|
||||
@@ -344,6 +346,26 @@ impl<'a> PlaceSettings<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// BlackstoneReplaceProcessor's block map.
|
||||
fn blackstone(name: &str) -> Option<&'static str> {
|
||||
Some(match name.strip_prefix("minecraft:")? {
|
||||
"cobblestone" | "mossy_cobblestone" => "blackstone",
|
||||
"stone" => "polished_blackstone",
|
||||
"stone_bricks" | "mossy_stone_bricks" => "polished_blackstone_bricks",
|
||||
"cobblestone_stairs" | "mossy_cobblestone_stairs" => "blackstone_stairs",
|
||||
"stone_stairs" => "polished_blackstone_stairs",
|
||||
"stone_brick_stairs" | "mossy_stone_brick_stairs" => "polished_blackstone_brick_stairs",
|
||||
"cobblestone_slab" | "mossy_cobblestone_slab" => "blackstone_slab",
|
||||
"smooth_stone_slab" | "stone_slab" => "polished_blackstone_slab",
|
||||
"stone_brick_slab" | "mossy_stone_brick_slab" => "polished_blackstone_brick_slab",
|
||||
"stone_brick_wall" | "mossy_stone_brick_wall" => "polished_blackstone_brick_wall",
|
||||
"cobblestone_wall" | "mossy_cobblestone_wall" => "blackstone_wall",
|
||||
"chiseled_stone_bricks" => "chiseled_polished_blackstone",
|
||||
"cracked_stone_bricks" => "cracked_polished_blackstone_bricks",
|
||||
"iron_bars" => "iron_chain",
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
type ProcessResult = Result<Option<BlockInfo>, PlacementQueryError>;
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn process_block<W: PlacementContext>(
|
||||
@@ -410,6 +432,20 @@ fn process_block<W: PlacementContext>(
|
||||
}
|
||||
}
|
||||
Processor::BlockAge(mossiness) => block_age(*mossiness, info, settings, resources),
|
||||
Processor::BlackstoneReplace => {
|
||||
let Some(target) = blackstone(name(info.state)) else {
|
||||
return Ok(Some(info));
|
||||
};
|
||||
let old = registry.state(info.state);
|
||||
let properties: Vec<(&str, &str)> = ["facing", "half", "type"]
|
||||
.into_iter()
|
||||
.filter_map(|k| Some((k, old?.properties.get(k)?.as_str())))
|
||||
.collect();
|
||||
Some(BlockInfo {
|
||||
state: super::legacy::state(resources, target, &properties),
|
||||
..info
|
||||
})
|
||||
}
|
||||
Processor::Rule(rules) => {
|
||||
let mut random = LegacyRandom::new(position_seed(BlockPos::new(
|
||||
info.pos[0],
|
||||
|
||||
@@ -0,0 +1,370 @@
|
||||
//! Ruined portals (RuinedPortalStructure, RuinedPortalPiece).
|
||||
use super::{
|
||||
Mirror, Rotation, StructureResources,
|
||||
legacy::{
|
||||
HORIZONTAL, PieceContext, Result, TemplateHandler, TemplatePiece, direction_name, offset,
|
||||
opposite,
|
||||
},
|
||||
processor::ProcessorList,
|
||||
start::StartContext,
|
||||
};
|
||||
use crate::{
|
||||
heightmap::HeightmapType,
|
||||
registry::BlockStateId,
|
||||
worldgen::block_feature::FeatureBlockBindings,
|
||||
};
|
||||
use horizon_core::{geometry::Direction, position::ChunkPos, random::RandomSource};
|
||||
use serde_json::{Value, json};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Vertical {
|
||||
OnLandSurface,
|
||||
PartlyBuried,
|
||||
OnOceanFloor,
|
||||
InMountain,
|
||||
Underground,
|
||||
InNether,
|
||||
}
|
||||
impl Vertical {
|
||||
fn heightmap(self) -> HeightmapType {
|
||||
if self == Self::OnOceanFloor {
|
||||
HeightmapType::OceanFloorWg
|
||||
} else {
|
||||
HeightmapType::WorldSurfaceWg
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Setup {
|
||||
placement: Vertical,
|
||||
air_pocket: f32,
|
||||
mossiness: f32,
|
||||
overgrown: bool,
|
||||
vines: bool,
|
||||
can_be_cold: bool,
|
||||
blackstone: bool,
|
||||
weight: f32,
|
||||
}
|
||||
impl Setup {
|
||||
pub fn decode(v: &Value) -> Self {
|
||||
let float = |k: &str| v[k].as_f64().unwrap_or(0.) as f32;
|
||||
let flag = |k: &str| v[k].as_bool().unwrap_or(false);
|
||||
Self {
|
||||
placement: match v["placement"].as_str().unwrap_or_default() {
|
||||
"partly_buried" => Vertical::PartlyBuried,
|
||||
"on_ocean_floor" => Vertical::OnOceanFloor,
|
||||
"in_mountain" => Vertical::InMountain,
|
||||
"underground" => Vertical::Underground,
|
||||
"in_nether" => Vertical::InNether,
|
||||
_ => Vertical::OnLandSurface,
|
||||
},
|
||||
air_pocket: float("air_pocket_probability"),
|
||||
mossiness: float("mossiness"),
|
||||
overgrown: flag("overgrown"),
|
||||
vines: flag("vines"),
|
||||
can_be_cold: flag("can_be_cold"),
|
||||
blackstone: flag("replace_with_blackstone"),
|
||||
weight: float("weight"),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct PortalProps {
|
||||
placement: Vertical,
|
||||
cold: bool,
|
||||
overgrown: bool,
|
||||
vines: bool,
|
||||
}
|
||||
|
||||
fn between(random: &mut impl RandomSource, min: i32, max: i32) -> i32 {
|
||||
random.next_int_bound(max - min + 1).unwrap_or(0) + min
|
||||
}
|
||||
fn within(random: &mut impl RandomSource, min: i32, max: i32) -> i32 {
|
||||
if min < max {
|
||||
between(random, min, max)
|
||||
} else {
|
||||
max
|
||||
}
|
||||
}
|
||||
|
||||
/// RuinedPortalStructure.findGenerationPoint: the start position and piece.
|
||||
pub fn start(
|
||||
context: &mut impl StartContext,
|
||||
resources: &StructureResources,
|
||||
bindings: &FeatureBlockBindings<'_>,
|
||||
random: &mut impl RandomSource,
|
||||
chunk: ChunkPos,
|
||||
setups: &[Setup],
|
||||
) -> Option<([i32; 3], TemplatePiece)> {
|
||||
let setup = if setups.len() > 1 {
|
||||
let total: f32 = setups.iter().map(|s| s.weight).sum();
|
||||
let mut pick = random.next_float();
|
||||
setups.iter().find(|s| {
|
||||
pick -= s.weight / total;
|
||||
pick < 0.
|
||||
})?
|
||||
} else {
|
||||
setups.first()?
|
||||
};
|
||||
let air_pocket = match setup.air_pocket {
|
||||
0. => false,
|
||||
1. => true,
|
||||
p => random.next_float() < p,
|
||||
};
|
||||
let name = if random.next_float() < 0.05 {
|
||||
format!(
|
||||
"minecraft:ruined_portal/giant_portal_{}",
|
||||
random.next_int_bound(3).ok()? + 1
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"minecraft:ruined_portal/portal_{}",
|
||||
random.next_int_bound(10).ok()? + 1
|
||||
)
|
||||
};
|
||||
let template = resources.template(&name)?;
|
||||
let rotation = Rotation::random(random);
|
||||
let mirror = if random.next_float() < 0.5 {
|
||||
Mirror::None
|
||||
} else {
|
||||
Mirror::FrontBack
|
||||
};
|
||||
let pivot = [template.size[0] / 2, 0, template.size[2] / 2];
|
||||
let base = [chunk.x * 16, 0, chunk.z * 16];
|
||||
let b = template.bounding_box(base, rotation, pivot, mirror);
|
||||
let center = b.center();
|
||||
let surface = context.base_height(center[0], center[2], setup.placement.heightmap()) - 1;
|
||||
let span = b.span()[1];
|
||||
let min_y = context.min_y() + 15;
|
||||
let new_y = match setup.placement {
|
||||
Vertical::InNether => {
|
||||
if air_pocket {
|
||||
between(random, 32, 100)
|
||||
} else if random.next_float() < 0.5 {
|
||||
between(random, 27, 29)
|
||||
} else {
|
||||
between(random, 29, 100)
|
||||
}
|
||||
}
|
||||
Vertical::InMountain => within(random, 70, surface - span),
|
||||
Vertical::Underground => within(random, min_y, surface - span),
|
||||
Vertical::PartlyBuried => surface - span + between(random, 2, 8),
|
||||
_ => surface,
|
||||
};
|
||||
let kind = setup.placement.heightmap();
|
||||
let columns: Vec<Vec<bool>> = [
|
||||
[b.min[0], b.min[2]],
|
||||
[b.max[0], b.min[2]],
|
||||
[b.min[0], b.max[2]],
|
||||
[b.max[0], b.max[2]],
|
||||
]
|
||||
.into_iter()
|
||||
.map(|[x, z]| context.base_column(x, z, kind))
|
||||
.collect();
|
||||
let world_min = context.min_y();
|
||||
let mut y = new_y;
|
||||
'search: while y > min_y {
|
||||
let mut solid = 0;
|
||||
for column in &columns {
|
||||
let index = y - world_min;
|
||||
if index >= 0 && column.get(index as usize).copied().unwrap_or(false) {
|
||||
solid += 1;
|
||||
if solid == 3 {
|
||||
break 'search;
|
||||
}
|
||||
}
|
||||
}
|
||||
y -= 1;
|
||||
}
|
||||
let origin = [base[0], y, base[2]];
|
||||
let cold = setup.can_be_cold && {
|
||||
let biome = context.noise_biome(origin.map(|v| v >> 2));
|
||||
context.cold_enough_to_snow(biome, origin)
|
||||
};
|
||||
let props = PortalProps {
|
||||
placement: setup.placement,
|
||||
cold,
|
||||
overgrown: setup.overgrown,
|
||||
vines: setup.vines,
|
||||
};
|
||||
let rule = |source: &str, probability: Option<f32>, target: &str| {
|
||||
let input = match probability {
|
||||
Some(p) => json!({"predicate_type": "minecraft:random_block_match", "block": source, "probability": p}),
|
||||
None => json!({"predicate_type": "minecraft:block_match", "block": source}),
|
||||
};
|
||||
json!({"input_predicate": input, "location_predicate": {"predicate_type": "minecraft:always_true"}, "output_state": target})
|
||||
};
|
||||
let mut rules = vec![rule("minecraft:gold_block", Some(0.3), "minecraft:air")];
|
||||
rules.push(if setup.placement == Vertical::OnOceanFloor {
|
||||
rule("minecraft:lava", None, "minecraft:magma_block")
|
||||
} else if cold {
|
||||
rule("minecraft:lava", None, "minecraft:netherrack")
|
||||
} else {
|
||||
rule("minecraft:lava", Some(0.2), "minecraft:magma_block")
|
||||
});
|
||||
if !cold {
|
||||
rules.push(rule("minecraft:netherrack", Some(0.07), "minecraft:magma_block"));
|
||||
}
|
||||
let mut list = vec![
|
||||
json!({"processor_type": "minecraft:rule", "rules": rules}),
|
||||
json!({"processor_type": "minecraft:block_age", "mossiness": setup.mossiness}),
|
||||
json!({"processor_type": "minecraft:protected_blocks", "value": "#minecraft:features_cannot_replace"}),
|
||||
json!({"processor_type": "minecraft:lava_submerged_block"}),
|
||||
];
|
||||
if setup.blackstone {
|
||||
list.push(json!({"processor_type": "minecraft:blackstone_replace"}));
|
||||
}
|
||||
let processors =
|
||||
ProcessorList::decode(&json!({ "processors": list }).to_string(), resources, bindings)
|
||||
.ok()?;
|
||||
let mut ignore = vec!["minecraft:structure_block".to_owned()];
|
||||
if !air_pocket {
|
||||
ignore.push("minecraft:air".into());
|
||||
}
|
||||
let piece = TemplatePiece::new(
|
||||
"minecraft:rupo",
|
||||
&name,
|
||||
template,
|
||||
origin,
|
||||
rotation,
|
||||
mirror,
|
||||
pivot,
|
||||
Arc::new(processors),
|
||||
true,
|
||||
ignore,
|
||||
TemplateHandler::RuinedPortal(props),
|
||||
);
|
||||
Some((origin, piece))
|
||||
}
|
||||
|
||||
const NETHERRACK_BY_DISTANCE: [f32; 14] = [
|
||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.9, 0.9, 0.8, 0.7, 0.6, 0.4, 0.2,
|
||||
];
|
||||
fn replaceable(c: &PieceContext<'_>, props: PortalProps, state: BlockStateId) -> bool {
|
||||
let name = c.name(state);
|
||||
name != "minecraft:air"
|
||||
&& name != "minecraft:obsidian"
|
||||
&& !c
|
||||
.resources
|
||||
.block_tags
|
||||
.get("minecraft:features_cannot_replace")
|
||||
.is_some_and(|t| t.contains(name))
|
||||
&& (props.placement == Vertical::InNether || name != "minecraft:lava")
|
||||
}
|
||||
fn netherrack_or_magma(c: &mut PieceContext<'_>, props: PortalProps, pos: [i32; 3]) -> Result<()> {
|
||||
let state = c.world.block(pos)?;
|
||||
if replaceable(c, props, state) {
|
||||
let block = if !props.cold && c.random.float() < 0.07 {
|
||||
"magma_block"
|
||||
} else {
|
||||
"netherrack"
|
||||
};
|
||||
c.world.set(pos, c.state(block), 3)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn drip_column(c: &mut PieceContext<'_>, props: PortalProps, mut pos: [i32; 3]) -> Result<()> {
|
||||
netherrack_or_magma(c, props, pos)?;
|
||||
let mut remaining = 8;
|
||||
while remaining > 0 && c.random.float() < 0.5 {
|
||||
pos[1] -= 1;
|
||||
remaining -= 1;
|
||||
netherrack_or_magma(c, props, pos)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn leaves_above(c: &mut PieceContext<'_>, pos: [i32; 3]) -> Result<()> {
|
||||
if c.random.float() < 0.5 && c.is_block(pos, "minecraft:netherrack")? {
|
||||
let above = [pos[0], pos[1] + 1, pos[2]];
|
||||
let state = c.world.block(above)?;
|
||||
if c.is_air(state) {
|
||||
let leaves = c.state_with("jungle_leaves", &[("persistent", "true")]);
|
||||
c.world.set(above, leaves, 3)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn vines(c: &mut PieceContext<'_>, pos: [i32; 3]) -> Result<()> {
|
||||
let state = c.world.block(pos)?;
|
||||
if c.is_air(state) || c.name(state) == "minecraft:vine" {
|
||||
return Ok(());
|
||||
}
|
||||
let direction = random_horizontal_dyn(c);
|
||||
let neighbour = offset(pos, direction, 1);
|
||||
let n = c.world.block(neighbour)?;
|
||||
if c.is_air(n) && c.world.face_full(pos, direction)? {
|
||||
let vine = c.state_with("vine", &[(direction_name(opposite(direction)), "true")]);
|
||||
c.world.set(neighbour, vine, 3)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn random_horizontal_dyn(c: &mut PieceContext<'_>) -> Direction {
|
||||
HORIZONTAL[c.random.int(4) as usize]
|
||||
}
|
||||
/// RuinedPortalPiece.postProcess.
|
||||
pub fn post_process(piece: &TemplatePiece, c: &mut PieceContext<'_>) -> Result<()> {
|
||||
let TemplateHandler::RuinedPortal(props) = piece.handler else {
|
||||
return Ok(());
|
||||
};
|
||||
let b = piece.bounding_box;
|
||||
if !c.chunk_box.is_inside(b.center()) {
|
||||
return Ok(());
|
||||
}
|
||||
c.chunk_box.encapsulate(&b);
|
||||
piece.place_at(c, piece.position, &[])?;
|
||||
// spreadNetherrack
|
||||
let follow = matches!(
|
||||
props.placement,
|
||||
Vertical::OnLandSurface | Vertical::OnOceanFloor
|
||||
);
|
||||
let [cx, _, cz] = b.center();
|
||||
let max = NETHERRACK_BY_DISTANCE.len() as i32;
|
||||
let [sx, _, sz] = b.span();
|
||||
let adjustment = c.random.int((8 - (sx + sz) / 2 / 2).max(1));
|
||||
for x in cx - max..=cx + max {
|
||||
for z in cz - max..=cz + max {
|
||||
let distance = (x - cx).abs() + (z - cz).abs();
|
||||
let adjusted = (distance + adjustment).max(0);
|
||||
if adjusted >= max {
|
||||
continue;
|
||||
}
|
||||
if c.random.double() < f64::from(NETHERRACK_BY_DISTANCE[adjusted as usize]) {
|
||||
let surface = c.world.height(props.placement.heightmap(), x, z)? - 1;
|
||||
let y = if follow { surface } else { b.min[1].min(surface) };
|
||||
let pos = [x, y, z];
|
||||
let state = c.world.block(pos)?;
|
||||
if (y - b.min[1]).abs() <= 3 && replaceable(c, props, state) {
|
||||
netherrack_or_magma(c, props, pos)?;
|
||||
if props.overgrown {
|
||||
leaves_above(c, pos)?;
|
||||
}
|
||||
drip_column(c, props, [x, y - 1, z])?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// addNetherrackDripColumnsBelowPortal
|
||||
for x in b.min[0] + 1..b.max[0] {
|
||||
for z in b.min[2] + 1..b.max[2] {
|
||||
if c.is_block([x, b.min[1], z], "minecraft:netherrack")? {
|
||||
drip_column(c, props, [x, b.min[1] - 1, z])?;
|
||||
}
|
||||
}
|
||||
}
|
||||
if props.vines || props.overgrown {
|
||||
for z in b.min[2]..=b.max[2] {
|
||||
for y in b.min[1]..=b.max[1] {
|
||||
for x in b.min[0]..=b.max[0] {
|
||||
if props.vines {
|
||||
vines(c, [x, y, z])?;
|
||||
}
|
||||
if props.overgrown {
|
||||
leaves_above(c, [x, y, z])?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -197,6 +197,12 @@ impl LegacyPiece for TemplatePiece {
|
||||
fn bounding_box(&self) -> BoundingBox {
|
||||
self.bounding_box
|
||||
}
|
||||
fn after_place(&self, c: &mut PieceContext<'_>, pieces: &[BoundingBox]) -> Result<()> {
|
||||
match self.handler {
|
||||
TemplateHandler::Mansion => super::mansion::after_place(c, pieces),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
fn type_name(&self) -> &'static str {
|
||||
self.type_name
|
||||
}
|
||||
@@ -312,6 +318,12 @@ impl LegacyPiece for TemplatePiece {
|
||||
TemplateHandler::OceanRuin { .. } => {
|
||||
super::ocean_ruin::post_process(self, c)?;
|
||||
}
|
||||
TemplateHandler::RuinedPortal(_) => {
|
||||
super::ruined_portal::post_process(self, c)?;
|
||||
}
|
||||
TemplateHandler::Mansion => {
|
||||
super::mansion::post_process(self, c)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -62,6 +62,12 @@ pub enum StructureKind {
|
||||
BuriedTreasure,
|
||||
Igloo,
|
||||
SwampHut,
|
||||
DesertPyramid,
|
||||
JungleTemple,
|
||||
RuinedPortal(Vec<super::ruined_portal::Setup>),
|
||||
Mansion,
|
||||
/// The biomes allowed around a monument (#required_ocean_monument_surrounding).
|
||||
Monument(BTreeSet<BiomeId>),
|
||||
Shipwreck {
|
||||
beached: bool,
|
||||
},
|
||||
@@ -175,6 +181,20 @@ impl StructureRegistry {
|
||||
"minecraft:buried_treasure" => StructureKind::BuriedTreasure,
|
||||
"minecraft:igloo" => StructureKind::Igloo,
|
||||
"minecraft:swamp_hut" => StructureKind::SwampHut,
|
||||
"minecraft:desert_pyramid" => StructureKind::DesertPyramid,
|
||||
"minecraft:jungle_temple" => StructureKind::JungleTemple,
|
||||
"minecraft:woodland_mansion" => StructureKind::Mansion,
|
||||
"minecraft:ocean_monument" => StructureKind::Monument(biome_set(
|
||||
&serde_json::json!("#minecraft:required_ocean_monument_surrounding"),
|
||||
)?),
|
||||
"minecraft:ruined_portal" => StructureKind::RuinedPortal(
|
||||
v["setups"]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(super::ruined_portal::Setup::decode)
|
||||
.collect(),
|
||||
),
|
||||
"minecraft:shipwreck" => StructureKind::Shipwreck {
|
||||
beached: v["is_beached"].as_bool().unwrap_or(false),
|
||||
},
|
||||
@@ -395,6 +415,11 @@ pub struct StructureStart {
|
||||
/// Biome and height queries for one structure generation attempt.
|
||||
pub trait StartContext: JigsawContext {
|
||||
fn seed(&self) -> i64;
|
||||
fn sea_level(&self) -> i32;
|
||||
/// ChunkGenerator.getBaseColumn as heightmap opacity, indexed from min_y.
|
||||
fn base_column(&mut self, x: i32, z: i32, kind: HeightmapType) -> Vec<bool>;
|
||||
/// Biome.coldEnoughToSnow at a position.
|
||||
fn cold_enough_to_snow(&mut self, biome: BiomeId, pos: [i32; 3]) -> bool;
|
||||
fn generation(&self) -> WorldGenerationContext;
|
||||
/// Noise biome at a quart position (caching resolver, no zoom).
|
||||
fn noise_biome(&mut self, quart: [i32; 3]) -> BiomeId;
|
||||
@@ -530,6 +555,81 @@ fn try_generate(
|
||||
let piece = super::simple::SwampHutPiece::new(&mut random, chunk.x * 16, chunk.z * 16);
|
||||
(stub, legacy(vec![piece]))
|
||||
}
|
||||
StructureKind::DesertPyramid | StructureKind::JungleTemple => {
|
||||
let desert = matches!(def.kind, StructureKind::DesertPyramid);
|
||||
let (width, depth) = if desert { (21, 21) } else { (12, 15) };
|
||||
let (x, z) = (chunk.x * 16, chunk.z * 16);
|
||||
if !context.column_has_valid_biome(x + 8, z + 8, context.min_y() - 1, context.max_y()) {
|
||||
return None;
|
||||
}
|
||||
let lowest = corner_heights(context, x, width, z, depth)
|
||||
.into_iter()
|
||||
.min()
|
||||
.unwrap_or(0);
|
||||
if lowest < context.sea_level() {
|
||||
return None;
|
||||
}
|
||||
let stub = [x + 8, first_occupied(context, x + 8, z + 8), z + 8];
|
||||
let piece: Box<dyn LegacyPiece> = if desert {
|
||||
Box::new(super::temple::DesertPyramidPiece::new(&mut random, x, z))
|
||||
} else {
|
||||
Box::new(super::temple::JungleTemplePiece::new(&mut random, x, z))
|
||||
};
|
||||
(stub, vec![Piece::Legacy(piece)])
|
||||
}
|
||||
StructureKind::Monument(surrounding) => {
|
||||
let (x, z) = (chunk.x * 16 + 9, chunk.z * 16 + 9);
|
||||
let (y, r) = (context.sea_level(), 29);
|
||||
for qz in (z - r) >> 2..=(z + r) >> 2 {
|
||||
for qx in (x - r) >> 2..=(x + r) >> 2 {
|
||||
for qy in (y - r) >> 2..=(y + r) >> 2 {
|
||||
if !surrounding.contains(&context.noise_biome([qx, qy, qz])) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let stub = top_of_chunk_center(context, chunk, HeightmapType::OceanFloorWg)?;
|
||||
let direction = super::legacy::random_horizontal(&mut random);
|
||||
let piece = super::monument::MonumentBuilding::new(
|
||||
&mut random,
|
||||
chunk.x * 16 - 29,
|
||||
chunk.z * 16 - 29,
|
||||
direction,
|
||||
);
|
||||
(stub, legacy(vec![piece]))
|
||||
}
|
||||
StructureKind::Mansion => {
|
||||
let (x, z) = (chunk.x * 16 + 7, chunk.z * 16 + 7);
|
||||
if !context.column_has_valid_biome(x, z, context.min_y() - 1, context.max_y()) {
|
||||
return None;
|
||||
}
|
||||
let rotation = super::Rotation::random(&mut random);
|
||||
let (sx, sz) = match rotation {
|
||||
super::Rotation::None => (5, 5),
|
||||
super::Rotation::Clockwise90 => (-5, 5),
|
||||
super::Rotation::Clockwise180 => (-5, -5),
|
||||
super::Rotation::Counterclockwise90 => (5, -5),
|
||||
};
|
||||
let y = corner_heights(context, x, sx, z, sz).into_iter().min().unwrap_or(0);
|
||||
if y < 60 {
|
||||
return None;
|
||||
}
|
||||
let start = [x, y, z];
|
||||
let pieces = super::mansion::pieces(resources, start, rotation, &mut random)?;
|
||||
(start, legacy(pieces))
|
||||
}
|
||||
StructureKind::RuinedPortal(setups) => {
|
||||
let (position, piece) = super::ruined_portal::start(
|
||||
context,
|
||||
resources,
|
||||
bindings,
|
||||
&mut random,
|
||||
chunk,
|
||||
setups,
|
||||
)?;
|
||||
(position, legacy(vec![piece]))
|
||||
}
|
||||
StructureKind::Shipwreck { beached } => {
|
||||
let kind = if *beached {
|
||||
HeightmapType::WorldSurfaceWg
|
||||
@@ -771,5 +871,17 @@ pub fn place_in_chunk<W: FeatureWorld + PlacementContext, R: RandomSource + 'sta
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Piece::Legacy(p) = first {
|
||||
let boxes: Vec<BoundingBox> = start.pieces.iter().map(Piece::bounding_box).collect();
|
||||
let mut context = PieceContext {
|
||||
world,
|
||||
resources,
|
||||
random,
|
||||
chunk_box,
|
||||
chunk: ChunkPos::new(chunk_box.min[0] >> 4, chunk_box.min[2] >> 4),
|
||||
reference,
|
||||
};
|
||||
p.after_place(&mut context, &boxes)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,572 @@
|
||||
//! Desert pyramids and jungle temples (DesertPyramidPiece, JungleTemplePiece).
|
||||
use super::{
|
||||
BoundingBox,
|
||||
legacy::{HORIZONTAL, LegacyPiece, PieceContext, Result, random_horizontal},
|
||||
simple::Scattered,
|
||||
};
|
||||
use crate::nbt::{Compound, Tag};
|
||||
use horizon_core::{
|
||||
geometry::Direction,
|
||||
position::BlockPos,
|
||||
random::{LegacyRandom, PositionalRandom, RandomSource},
|
||||
};
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DesertPyramidPiece {
|
||||
pub base: Scattered,
|
||||
placed_chest: Mutex<[bool; 4]>,
|
||||
}
|
||||
impl DesertPyramidPiece {
|
||||
pub fn new(random: &mut impl RandomSource, west: i32, north: i32) -> Self {
|
||||
let direction = random_horizontal(random);
|
||||
Self {
|
||||
base: Scattered::new(west, 64, north, 21, 15, 21, direction),
|
||||
placed_chest: Mutex::new([false; 4]),
|
||||
}
|
||||
}
|
||||
/// getPotentialSuspiciousSandWorldPositions, in placement order.
|
||||
fn sand_positions(&self) -> Vec<[i32; 3]> {
|
||||
let f = self.base.frame();
|
||||
let (x, y, z) = (16, -4, 13);
|
||||
let mut out = Vec::new();
|
||||
for py in y + 1..=y + 3 {
|
||||
for px in x - 2..=x + 2 {
|
||||
for pz in z - 2..=z + 2 {
|
||||
out.push(f.world_pos(px, py, pz));
|
||||
}
|
||||
}
|
||||
}
|
||||
for [px, pz] in [[x + 3, z], [x - 3, z], [x, z + 3], [x, z - 3]] {
|
||||
out.push(f.world_pos(px, y + 1, pz));
|
||||
out.push(f.world_pos(px, y + 2, pz));
|
||||
}
|
||||
out
|
||||
}
|
||||
fn collapsed_roof(&self, seed: i64) -> [i32; 3] {
|
||||
let f = self.base.frame();
|
||||
let [x0, y0, z0] = f.world_pos(14, 0, 11);
|
||||
let mut random = LegacyRandom::new(seed)
|
||||
.fork_positional()
|
||||
.at(BlockPos::new(x0, y0, z0));
|
||||
let rx = 14 + random.next_int_bound(5).unwrap_or(0);
|
||||
let rz = 11 + random.next_int_bound(5).unwrap_or(0);
|
||||
f.world_pos(rx, 0, rz)
|
||||
}
|
||||
}
|
||||
pub fn union(boxes: &[BoundingBox]) -> BoundingBox {
|
||||
let mut out = boxes[0];
|
||||
for b in &boxes[1..] {
|
||||
out.encapsulate(b);
|
||||
}
|
||||
out
|
||||
}
|
||||
fn suspicious_sand(c: &mut PieceContext<'_>, pos: [i32; 3]) -> Result<()> {
|
||||
if c.chunk_box.is_inside(pos) {
|
||||
c.world.set(pos, c.state("suspicious_sand"), 2)?;
|
||||
let mut nbt = Compound::new();
|
||||
nbt.insert("id".into(), Tag::String("minecraft:brushable_block".into()));
|
||||
nbt.insert(
|
||||
"LootTable".into(),
|
||||
Tag::String("minecraft:archaeology/desert_pyramid".into()),
|
||||
);
|
||||
nbt.insert(
|
||||
"LootTableSeed".into(),
|
||||
Tag::Long(BlockPos::new(pos[0], pos[1], pos[2]).pack()),
|
||||
);
|
||||
c.world.block_entity(pos, nbt)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
impl LegacyPiece for DesertPyramidPiece {
|
||||
fn bounding_box(&self) -> BoundingBox {
|
||||
self.base.frame().bounding_box
|
||||
}
|
||||
fn type_name(&self) -> &'static str {
|
||||
"minecraft:tedp"
|
||||
}
|
||||
fn post_process(&self, c: &mut PieceContext<'_>) -> Result<()> {
|
||||
let offset = -c.random.int(3);
|
||||
if !self.base.lowest_ground(c, offset)? {
|
||||
return Ok(());
|
||||
}
|
||||
let f = self.base.frame();
|
||||
let (w, d) = (21, 21);
|
||||
let sandstone = c.state("sandstone");
|
||||
let cut = c.state("cut_sandstone");
|
||||
let chiseled = c.state("chiseled_sandstone");
|
||||
let air = c.state("air");
|
||||
let orange = c.state("orange_terracotta");
|
||||
let blue = c.state("blue_terracotta");
|
||||
let stairs = |c: &PieceContext<'_>, facing: &str| {
|
||||
c.state_with("sandstone_stairs", &[("facing", facing)])
|
||||
};
|
||||
let north = stairs(c, "north");
|
||||
let south = stairs(c, "south");
|
||||
let east = stairs(c, "east");
|
||||
let west = stairs(c, "west");
|
||||
f.generate_box(c, [0, -4, 0], [w - 1, 0, d - 1], sandstone, sandstone, false)?;
|
||||
for p in 1..=9 {
|
||||
f.generate_box(c, [p, p, p], [w - 1 - p, p, d - 1 - p], sandstone, sandstone, false)?;
|
||||
f.generate_box(c, [p + 1, p, p + 1], [w - 2 - p, p, d - 2 - p], air, air, false)?;
|
||||
}
|
||||
for x in 0..w {
|
||||
for z in 0..d {
|
||||
f.fill_column_down(c, sandstone, x, -5, z)?;
|
||||
}
|
||||
}
|
||||
f.generate_box(c, [0, 0, 0], [4, 9, 4], sandstone, air, false)?;
|
||||
f.generate_box(c, [1, 10, 1], [3, 10, 3], sandstone, sandstone, false)?;
|
||||
f.place(c, north, 2, 10, 0)?;
|
||||
f.place(c, south, 2, 10, 4)?;
|
||||
f.place(c, east, 0, 10, 2)?;
|
||||
f.place(c, west, 4, 10, 2)?;
|
||||
f.generate_box(c, [w - 5, 0, 0], [w - 1, 9, 4], sandstone, air, false)?;
|
||||
f.generate_box(c, [w - 4, 10, 1], [w - 2, 10, 3], sandstone, sandstone, false)?;
|
||||
f.place(c, north, w - 3, 10, 0)?;
|
||||
f.place(c, south, w - 3, 10, 4)?;
|
||||
f.place(c, east, w - 5, 10, 2)?;
|
||||
f.place(c, west, w - 1, 10, 2)?;
|
||||
f.generate_box(c, [8, 0, 0], [12, 4, 4], sandstone, air, false)?;
|
||||
f.generate_box(c, [9, 1, 0], [11, 3, 4], air, air, false)?;
|
||||
for [x, y] in [[9, 1], [9, 2], [9, 3], [10, 3], [11, 3], [11, 2], [11, 1]] {
|
||||
f.place(c, cut, x, y, 1)?;
|
||||
}
|
||||
f.generate_box(c, [4, 1, 1], [8, 3, 3], sandstone, air, false)?;
|
||||
f.generate_box(c, [4, 1, 2], [8, 2, 2], air, air, false)?;
|
||||
f.generate_box(c, [12, 1, 1], [16, 3, 3], sandstone, air, false)?;
|
||||
f.generate_box(c, [12, 1, 2], [16, 2, 2], air, air, false)?;
|
||||
f.generate_box(c, [5, 4, 5], [w - 6, 4, d - 6], sandstone, sandstone, false)?;
|
||||
f.generate_box(c, [9, 4, 9], [11, 4, 11], air, air, false)?;
|
||||
for [x, z] in [[8, 8], [12, 8], [8, 12], [12, 12]] {
|
||||
f.generate_box(c, [x, 1, z], [x, 3, z], cut, cut, false)?;
|
||||
}
|
||||
f.generate_box(c, [1, 1, 5], [4, 4, 11], sandstone, sandstone, false)?;
|
||||
f.generate_box(c, [w - 5, 1, 5], [w - 2, 4, 11], sandstone, sandstone, false)?;
|
||||
f.generate_box(c, [6, 7, 9], [6, 7, 11], sandstone, sandstone, false)?;
|
||||
f.generate_box(c, [w - 7, 7, 9], [w - 7, 7, 11], sandstone, sandstone, false)?;
|
||||
f.generate_box(c, [5, 5, 9], [5, 7, 11], cut, cut, false)?;
|
||||
f.generate_box(c, [w - 6, 5, 9], [w - 6, 7, 11], cut, cut, false)?;
|
||||
f.place(c, air, 5, 5, 10)?;
|
||||
f.place(c, air, 5, 6, 10)?;
|
||||
f.place(c, air, 6, 6, 10)?;
|
||||
f.place(c, air, w - 6, 5, 10)?;
|
||||
f.place(c, air, w - 6, 6, 10)?;
|
||||
f.place(c, air, w - 7, 6, 10)?;
|
||||
f.generate_box(c, [2, 4, 4], [2, 6, 4], air, air, false)?;
|
||||
f.generate_box(c, [w - 3, 4, 4], [w - 3, 6, 4], air, air, false)?;
|
||||
f.place(c, north, 2, 4, 5)?;
|
||||
f.place(c, north, 2, 3, 4)?;
|
||||
f.place(c, north, w - 3, 4, 5)?;
|
||||
f.place(c, north, w - 3, 3, 4)?;
|
||||
f.generate_box(c, [1, 1, 3], [2, 2, 3], sandstone, sandstone, false)?;
|
||||
f.generate_box(c, [w - 3, 1, 3], [w - 2, 2, 3], sandstone, sandstone, false)?;
|
||||
f.place(c, sandstone, 1, 1, 2)?;
|
||||
f.place(c, sandstone, w - 2, 1, 2)?;
|
||||
let slab = c.state("sandstone_slab");
|
||||
f.place(c, slab, 1, 2, 2)?;
|
||||
f.place(c, slab, w - 2, 2, 2)?;
|
||||
f.place(c, west, 2, 1, 2)?;
|
||||
f.place(c, east, w - 3, 1, 2)?;
|
||||
f.generate_box(c, [4, 3, 5], [4, 3, 17], sandstone, sandstone, false)?;
|
||||
f.generate_box(c, [w - 5, 3, 5], [w - 5, 3, 17], sandstone, sandstone, false)?;
|
||||
f.generate_box(c, [3, 1, 5], [4, 2, 16], air, air, false)?;
|
||||
f.generate_box(c, [w - 6, 1, 5], [w - 5, 2, 16], air, air, false)?;
|
||||
for z in (5..=17).step_by(2) {
|
||||
f.place(c, cut, 4, 1, z)?;
|
||||
f.place(c, chiseled, 4, 2, z)?;
|
||||
f.place(c, cut, w - 5, 1, z)?;
|
||||
f.place(c, chiseled, w - 5, 2, z)?;
|
||||
}
|
||||
for [x, z] in [
|
||||
[10, 7],
|
||||
[10, 8],
|
||||
[9, 9],
|
||||
[11, 9],
|
||||
[8, 10],
|
||||
[12, 10],
|
||||
[7, 10],
|
||||
[13, 10],
|
||||
[9, 11],
|
||||
[11, 11],
|
||||
[10, 12],
|
||||
[10, 13],
|
||||
] {
|
||||
f.place(c, orange, x, 0, z)?;
|
||||
}
|
||||
f.place(c, blue, 10, 0, 10)?;
|
||||
// Rows of the corner towers (y 2..=8, three blocks each).
|
||||
let rows = [
|
||||
[cut, orange, cut],
|
||||
[cut, orange, cut],
|
||||
[orange, chiseled, orange],
|
||||
[cut, orange, cut],
|
||||
[orange, chiseled, orange],
|
||||
[orange, orange, orange],
|
||||
[cut, cut, cut],
|
||||
];
|
||||
for x in [0, w - 1] {
|
||||
for (i, row) in rows.iter().enumerate() {
|
||||
for (j, &state) in row.iter().enumerate() {
|
||||
f.place(c, state, x, 2 + i as i32, 1 + j as i32)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
for x in [2, w - 3] {
|
||||
for (i, row) in rows.iter().enumerate() {
|
||||
for (j, &state) in row.iter().enumerate() {
|
||||
f.place(c, state, x - 1 + j as i32, 2 + i as i32, 0)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
f.generate_box(c, [8, 4, 0], [12, 6, 0], cut, cut, false)?;
|
||||
f.place(c, air, 8, 6, 0)?;
|
||||
f.place(c, air, 12, 6, 0)?;
|
||||
f.place(c, orange, 9, 5, 0)?;
|
||||
f.place(c, chiseled, 10, 5, 0)?;
|
||||
f.place(c, orange, 11, 5, 0)?;
|
||||
f.generate_box(c, [8, -14, 8], [12, -11, 12], cut, cut, false)?;
|
||||
f.generate_box(c, [8, -10, 8], [12, -10, 12], chiseled, chiseled, false)?;
|
||||
f.generate_box(c, [8, -9, 8], [12, -9, 12], cut, cut, false)?;
|
||||
f.generate_box(c, [8, -8, 8], [12, -1, 12], sandstone, sandstone, false)?;
|
||||
f.generate_box(c, [9, -11, 9], [11, -1, 11], air, air, false)?;
|
||||
f.place(c, c.state("stone_pressure_plate"), 10, -11, 10)?;
|
||||
f.generate_box(c, [9, -13, 9], [11, -13, 11], c.state("tnt"), air, false)?;
|
||||
for [x, z, ox, oz] in [[8, 10, 7, 10], [12, 10, 13, 10], [10, 8, 10, 7], [10, 12, 10, 13]] {
|
||||
f.place(c, air, x, -11, z)?;
|
||||
f.place(c, air, x, -10, z)?;
|
||||
f.place(c, chiseled, ox, -10, oz)?;
|
||||
f.place(c, cut, ox, -11, oz)?;
|
||||
}
|
||||
for (i, d) in HORIZONTAL.into_iter().enumerate() {
|
||||
if !self.placed_chest.lock().unwrap()[i] {
|
||||
let s = d.normal();
|
||||
let placed = f.create_chest(
|
||||
c,
|
||||
10 + s[0] * 2,
|
||||
-11,
|
||||
10 + s[2] * 2,
|
||||
"minecraft:chests/desert_pyramid",
|
||||
)?;
|
||||
self.placed_chest.lock().unwrap()[i] = placed;
|
||||
}
|
||||
}
|
||||
// addCellar: stairs, then the room.
|
||||
let (x, y, z) = (16, -4, 13);
|
||||
let ccw = stairs(c, "west");
|
||||
f.place(c, ccw, 13, -1, 17)?;
|
||||
f.place(c, ccw, 14, -2, 17)?;
|
||||
f.place(c, ccw, 15, -3, 17)?;
|
||||
let sand = c.state("sand");
|
||||
let variant = c.world.level_boolean()?;
|
||||
for dx in -4..=0 {
|
||||
f.place(c, sand, x + dx, y + 4, z + 4)?;
|
||||
}
|
||||
f.place(c, sand, x - 2, y + 3, z + 4)?;
|
||||
f.place(c, if variant { sand } else { sandstone }, x - 1, y + 3, z + 4)?;
|
||||
f.place(c, if variant { sandstone } else { sand }, x, y + 3, z + 4)?;
|
||||
f.place(c, sand, x - 1, y + 2, z + 4)?;
|
||||
f.place(c, sandstone, x, y + 2, z + 4)?;
|
||||
f.place(c, sand, x, y + 1, z + 4)?;
|
||||
for (state, yy) in [(cut, y + 1), (chiseled, y + 2), (cut, -1)] {
|
||||
f.generate_box(c, [x - 3, yy, z - 3], [x - 3, yy, z + 2], state, state, true)?;
|
||||
f.generate_box(c, [x + 3, yy, z - 3], [x + 3, yy, z + 2], state, state, true)?;
|
||||
f.generate_box(c, [x - 3, yy, z - 3], [x + 3, yy, z - 2], state, state, true)?;
|
||||
f.generate_box(c, [x - 3, yy, z + 3], [x + 3, yy, z + 3], state, state, true)?;
|
||||
}
|
||||
for px in x - 2..=x + 2 {
|
||||
for pz in z - 2..=z + 2 {
|
||||
let state = if c.world.level_float()? < 0.33 {
|
||||
sandstone
|
||||
} else {
|
||||
sand
|
||||
};
|
||||
f.place(c, state, px, y + 4, pz)?;
|
||||
}
|
||||
}
|
||||
f.place(c, blue, x, y, z)?;
|
||||
for [dx, dz] in [[1, -1], [1, 1], [-1, -1], [-1, 1], [2, 0], [-2, 0], [0, 2], [0, -2]] {
|
||||
f.place(c, orange, x + dx, y, z + dz)?;
|
||||
}
|
||||
f.place(c, orange, x + 3, y, z)?;
|
||||
f.place(c, cut, x + 4, y + 1, z)?;
|
||||
f.place(c, chiseled, x + 4, y + 2, z)?;
|
||||
f.place(c, orange, x - 3, y, z)?;
|
||||
f.place(c, cut, x - 4, y + 1, z)?;
|
||||
f.place(c, chiseled, x - 4, y + 2, z)?;
|
||||
f.place(c, orange, x, y, z + 3)?;
|
||||
f.place(c, orange, x, y, z - 3)?;
|
||||
f.place(c, cut, x, y + 1, z - 4)?;
|
||||
f.place(c, chiseled, x, -2, z - 4)?;
|
||||
Ok(())
|
||||
}
|
||||
/// DesertPyramidStructure.afterPlace.
|
||||
fn after_place(&self, c: &mut PieceContext<'_>, pieces: &[BoundingBox]) -> Result<()> {
|
||||
if *self.base.height_position.lock().unwrap() < 0 {
|
||||
return Ok(());
|
||||
}
|
||||
let seed = c.world.seed()?;
|
||||
let mut positions = self.sand_positions();
|
||||
positions.sort_by_key(|p| (p[1], p[2], p[0]));
|
||||
positions.dedup();
|
||||
suspicious_sand(c, self.collapsed_roof(seed))?;
|
||||
let center = union(pieces).center();
|
||||
let mut random = LegacyRandom::new(seed)
|
||||
.fork_positional()
|
||||
.at(BlockPos::new(center[0], center[1], center[2]));
|
||||
for i in (2..=positions.len()).rev() {
|
||||
let j = random.next_int_bound(i as i32).unwrap_or(0) as usize;
|
||||
positions.swap(i - 1, j);
|
||||
}
|
||||
let mut remaining = (positions.len() as i32).min(5 + random.next_int_bound(3).unwrap_or(0));
|
||||
let sand = c.state("sand");
|
||||
for pos in positions {
|
||||
if remaining > 0 {
|
||||
remaining -= 1;
|
||||
suspicious_sand(c, pos)?;
|
||||
} else if c.chunk_box.is_inside(pos) {
|
||||
c.world.set(pos, sand, 2)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct JungleTemplePiece {
|
||||
pub base: Scattered,
|
||||
/// placedMainChest, placedHiddenChest, placedTrap1, placedTrap2.
|
||||
placed: Mutex<[bool; 4]>,
|
||||
}
|
||||
impl JungleTemplePiece {
|
||||
pub fn new(random: &mut impl RandomSource, west: i32, north: i32) -> Self {
|
||||
let direction = random_horizontal(random);
|
||||
Self {
|
||||
base: Scattered::new(west, 64, north, 12, 10, 15, direction),
|
||||
placed: Mutex::new([false; 4]),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl LegacyPiece for JungleTemplePiece {
|
||||
fn bounding_box(&self) -> BoundingBox {
|
||||
self.base.frame().bounding_box
|
||||
}
|
||||
fn type_name(&self) -> &'static str {
|
||||
"minecraft:tejp"
|
||||
}
|
||||
fn post_process(&self, c: &mut PieceContext<'_>) -> Result<()> {
|
||||
if !self.base.average_ground(c, 0)? {
|
||||
return Ok(());
|
||||
}
|
||||
let f = self.base.frame();
|
||||
let cobble = c.state("cobblestone");
|
||||
let mossy = c.state("mossy_cobblestone");
|
||||
let air = c.state("air");
|
||||
let stone = |c: &mut PieceContext<'_>, a: [i32; 3], b: [i32; 3]| {
|
||||
f.generate_box_selector(c, a, b, false, &mut |c, _, _, _, _| {
|
||||
if c.random.float() < 0.4 { cobble } else { mossy }
|
||||
})
|
||||
};
|
||||
stone(c, [0, -4, 0], [11, 0, 14])?;
|
||||
for (a, b) in [
|
||||
([2, 1, 2], [9, 2, 2]),
|
||||
([2, 1, 12], [9, 2, 12]),
|
||||
([2, 1, 3], [2, 2, 11]),
|
||||
([9, 1, 3], [9, 2, 11]),
|
||||
([1, 3, 1], [10, 6, 1]),
|
||||
([1, 3, 13], [10, 6, 13]),
|
||||
([1, 3, 2], [1, 6, 12]),
|
||||
([10, 3, 2], [10, 6, 12]),
|
||||
([2, 3, 2], [9, 3, 12]),
|
||||
([2, 6, 2], [9, 6, 12]),
|
||||
([3, 7, 3], [8, 7, 11]),
|
||||
([4, 8, 4], [7, 8, 10]),
|
||||
] {
|
||||
stone(c, a, b)?;
|
||||
}
|
||||
for (a, b) in [
|
||||
([3, 1, 3], [8, 2, 11]),
|
||||
([4, 3, 6], [7, 3, 9]),
|
||||
([2, 4, 2], [9, 5, 12]),
|
||||
([4, 6, 5], [7, 6, 9]),
|
||||
([5, 7, 6], [6, 7, 8]),
|
||||
([5, 1, 2], [6, 2, 2]),
|
||||
([5, 2, 12], [6, 2, 12]),
|
||||
([5, 5, 1], [6, 5, 1]),
|
||||
([5, 5, 13], [6, 5, 13]),
|
||||
] {
|
||||
f.generate_box(c, a, b, air, air, false)?;
|
||||
}
|
||||
f.place(c, air, 1, 5, 5)?;
|
||||
f.place(c, air, 10, 5, 5)?;
|
||||
f.place(c, air, 1, 5, 9)?;
|
||||
f.place(c, air, 10, 5, 9)?;
|
||||
for z in [0, 14] {
|
||||
for x in [2, 4, 7, 9] {
|
||||
stone(c, [x, 4, z], [x, 5, z])?;
|
||||
}
|
||||
}
|
||||
stone(c, [5, 6, 0], [6, 6, 0])?;
|
||||
for x in [0, 11] {
|
||||
for z in (2..=12).step_by(2) {
|
||||
stone(c, [x, 4, z], [x, 5, z])?;
|
||||
}
|
||||
stone(c, [x, 6, 5], [x, 6, 5])?;
|
||||
stone(c, [x, 6, 9], [x, 6, 9])?;
|
||||
}
|
||||
for (a, b) in [
|
||||
([2, 7, 2], [2, 9, 2]),
|
||||
([9, 7, 2], [9, 9, 2]),
|
||||
([2, 7, 12], [2, 9, 12]),
|
||||
([9, 7, 12], [9, 9, 12]),
|
||||
([4, 9, 4], [4, 9, 4]),
|
||||
([7, 9, 4], [7, 9, 4]),
|
||||
([4, 9, 10], [4, 9, 10]),
|
||||
([7, 9, 10], [7, 9, 10]),
|
||||
([5, 9, 7], [6, 9, 7]),
|
||||
] {
|
||||
stone(c, a, b)?;
|
||||
}
|
||||
let stairs =
|
||||
|c: &PieceContext<'_>, facing: &str| c.state_with("cobblestone_stairs", &[("facing", facing)]);
|
||||
let east = stairs(c, "east");
|
||||
let west = stairs(c, "west");
|
||||
let south = stairs(c, "south");
|
||||
let north = stairs(c, "north");
|
||||
f.place(c, north, 5, 9, 6)?;
|
||||
f.place(c, north, 6, 9, 6)?;
|
||||
f.place(c, south, 5, 9, 8)?;
|
||||
f.place(c, south, 6, 9, 8)?;
|
||||
for [x, y, z] in [
|
||||
[4, 0, 0],
|
||||
[5, 0, 0],
|
||||
[6, 0, 0],
|
||||
[7, 0, 0],
|
||||
[4, 1, 8],
|
||||
[4, 2, 9],
|
||||
[4, 3, 10],
|
||||
[7, 1, 8],
|
||||
[7, 2, 9],
|
||||
[7, 3, 10],
|
||||
] {
|
||||
f.place(c, north, x, y, z)?;
|
||||
}
|
||||
stone(c, [4, 1, 9], [4, 1, 9])?;
|
||||
stone(c, [7, 1, 9], [7, 1, 9])?;
|
||||
stone(c, [4, 1, 10], [7, 2, 10])?;
|
||||
stone(c, [5, 4, 5], [6, 4, 5])?;
|
||||
f.place(c, east, 4, 4, 5)?;
|
||||
f.place(c, west, 7, 4, 5)?;
|
||||
for i in 0..4 {
|
||||
f.place(c, south, 5, -i, 6 + i)?;
|
||||
f.place(c, south, 6, -i, 6 + i)?;
|
||||
f.generate_box(c, [5, -i, 7 + i], [6, -i, 9 + i], air, air, false)?;
|
||||
}
|
||||
f.generate_box(c, [1, -3, 12], [10, -1, 13], air, air, false)?;
|
||||
f.generate_box(c, [1, -3, 1], [3, -1, 13], air, air, false)?;
|
||||
f.generate_box(c, [1, -3, 1], [9, -1, 5], air, air, false)?;
|
||||
for z in (1..=13).step_by(2) {
|
||||
stone(c, [1, -3, z], [1, -2, z])?;
|
||||
}
|
||||
for z in (2..=12).step_by(2) {
|
||||
stone(c, [1, -1, z], [3, -1, z])?;
|
||||
}
|
||||
stone(c, [2, -2, 1], [5, -2, 1])?;
|
||||
stone(c, [7, -2, 1], [9, -2, 1])?;
|
||||
stone(c, [6, -3, 1], [6, -3, 1])?;
|
||||
stone(c, [6, -1, 1], [6, -1, 1])?;
|
||||
let hook = |c: &PieceContext<'_>, facing: &str| {
|
||||
c.state_with("tripwire_hook", &[("facing", facing), ("attached", "true")])
|
||||
};
|
||||
let wire = |c: &PieceContext<'_>, a: &str, b: &str| {
|
||||
c.state_with("tripwire", &[(a, "true"), (b, "true"), ("attached", "true")])
|
||||
};
|
||||
let redstone = |c: &PieceContext<'_>, sides: &[(&str, &str)]| c.state_with("redstone_wire", sides);
|
||||
f.place(c, hook(c, "east"), 1, -3, 8)?;
|
||||
f.place(c, hook(c, "west"), 4, -3, 8)?;
|
||||
f.place(c, wire(c, "east", "west"), 2, -3, 8)?;
|
||||
f.place(c, wire(c, "east", "west"), 3, -3, 8)?;
|
||||
let ns = redstone(c, &[("north", "side"), ("south", "side")]);
|
||||
for z in (2..=7).rev() {
|
||||
f.place(c, ns, 5, -3, z)?;
|
||||
}
|
||||
f.place(c, redstone(c, &[("north", "side"), ("west", "side")]), 5, -3, 1)?;
|
||||
f.place(c, redstone(c, &[("east", "side"), ("west", "side")]), 4, -3, 1)?;
|
||||
f.place(c, mossy, 3, -3, 1)?;
|
||||
let dispenser = "minecraft:chests/jungle_temple_dispenser";
|
||||
if !self.placed.lock().unwrap()[2] {
|
||||
let placed = f.create_dispenser(c, 3, -2, 1, Direction::North, dispenser)?;
|
||||
self.placed.lock().unwrap()[2] = placed;
|
||||
}
|
||||
f.place(c, c.state_with("vine", &[("south", "true")]), 3, -2, 2)?;
|
||||
f.place(c, hook(c, "north"), 7, -3, 1)?;
|
||||
f.place(c, hook(c, "south"), 7, -3, 5)?;
|
||||
for z in 2..=4 {
|
||||
f.place(c, wire(c, "north", "south"), 7, -3, z)?;
|
||||
}
|
||||
f.place(c, redstone(c, &[("east", "side"), ("west", "side")]), 8, -3, 6)?;
|
||||
f.place(c, redstone(c, &[("west", "side"), ("south", "side")]), 9, -3, 6)?;
|
||||
f.place(c, redstone(c, &[("north", "side"), ("south", "up")]), 9, -3, 5)?;
|
||||
f.place(c, mossy, 9, -3, 4)?;
|
||||
f.place(c, ns, 9, -2, 4)?;
|
||||
if !self.placed.lock().unwrap()[3] {
|
||||
let placed = f.create_dispenser(c, 9, -2, 3, Direction::West, dispenser)?;
|
||||
self.placed.lock().unwrap()[3] = placed;
|
||||
}
|
||||
let vine_east = c.state_with("vine", &[("east", "true")]);
|
||||
f.place(c, vine_east, 8, -1, 3)?;
|
||||
f.place(c, vine_east, 8, -2, 3)?;
|
||||
if !self.placed.lock().unwrap()[0] {
|
||||
let placed = f.create_chest(c, 8, -3, 3, "minecraft:chests/jungle_temple")?;
|
||||
self.placed.lock().unwrap()[0] = placed;
|
||||
}
|
||||
for [x, y, z] in [
|
||||
[9, -3, 2],
|
||||
[8, -3, 1],
|
||||
[4, -3, 5],
|
||||
[5, -2, 5],
|
||||
[5, -1, 5],
|
||||
[6, -3, 5],
|
||||
[7, -2, 5],
|
||||
[7, -1, 5],
|
||||
[8, -3, 5],
|
||||
] {
|
||||
f.place(c, mossy, x, y, z)?;
|
||||
}
|
||||
stone(c, [9, -1, 1], [9, -1, 5])?;
|
||||
f.generate_box(c, [8, -3, 8], [10, -1, 10], air, air, false)?;
|
||||
let chiseled = c.state("chiseled_stone_bricks");
|
||||
let lever = c.state_with("lever", &[("facing", "north"), ("face", "wall")]);
|
||||
for x in 8..=10 {
|
||||
f.place(c, chiseled, x, -2, 11)?;
|
||||
}
|
||||
for x in 8..=10 {
|
||||
f.place(c, lever, x, -2, 12)?;
|
||||
}
|
||||
stone(c, [8, -3, 8], [8, -3, 10])?;
|
||||
stone(c, [10, -3, 8], [10, -3, 10])?;
|
||||
f.place(c, mossy, 10, -2, 9)?;
|
||||
f.place(c, ns, 8, -2, 9)?;
|
||||
f.place(c, ns, 8, -2, 10)?;
|
||||
f.place(
|
||||
c,
|
||||
redstone(
|
||||
c,
|
||||
&[("north", "side"), ("south", "side"), ("east", "side"), ("west", "side")],
|
||||
),
|
||||
10,
|
||||
-1,
|
||||
9,
|
||||
)?;
|
||||
f.place(c, c.state_with("sticky_piston", &[("facing", "up")]), 9, -2, 8)?;
|
||||
let piston_west = c.state_with("sticky_piston", &[("facing", "west")]);
|
||||
f.place(c, piston_west, 10, -2, 8)?;
|
||||
f.place(c, piston_west, 10, -1, 8)?;
|
||||
f.place(c, c.state_with("repeater", &[("facing", "north")]), 10, -2, 10)?;
|
||||
if !self.placed.lock().unwrap()[1] {
|
||||
let placed = f.create_chest(c, 9, -3, 10, "minecraft:chests/jungle_temple")?;
|
||||
self.placed.lock().unwrap()[1] = placed;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user