feat: Structures

This commit is contained in:
Alexander Medvedev committed 2026-01-03 23:36:19 +01:00
1 parent 714e970292
commit 01d3be963d
13 files changed
+772 -483

No files matched your search

@@ -1,7 +1,11 @@
use pumpkin_data::Block;
use pumpkin_util::{
HeightMap,
math::{block_box::BlockBox, position::BlockPos, vector3::Vector3},
math::{
block_box::BlockBox,
position::BlockPos,
vector3::{Axis, Vector3},
},
};
use serde::Deserialize;
@@ -20,14 +24,17 @@ use crate::{
pub struct SwampHutGenerator;
impl StructureGenerator for SwampHutGenerator {
fn try_generate(&self, _seed: i64, chunk_x: i32, chunk_z: i32) -> Option<StructurePosition> {
fn get_structure_position(
&self,
_seed: i64,
chunk_x: i32,
chunk_z: i32,
) -> Option<StructurePosition> {
let x = get_center_x(chunk_x);
let z = get_center_z(chunk_z);
let box_min_x = x;
let box_min_z = z;
let bounding_box =
BlockBox::new(box_min_x, 60, box_min_z, box_min_x + 7, 80, box_min_z + 7);
// TODO: random axis
let bounding_box = BlockBox::create_box(x, 64, z, Axis::X, 7, 7, 9);
let mut collector = StructurePiecesCollector::default();
collector.add_piece(Box::new(SwampHutPiece { bounding_box }));
@@ -50,62 +57,148 @@ impl StructurePiece for SwampHutPiece {
}
fn place(&self, chunk: &mut ProtoChunk, _seed: i64) {
let origin_x = self.bounding_box.min.x;
let origin_z = self.bounding_box.min.z;
let min = self.bounding_box.min;
let origin_x = min.x;
let origin_z = min.z;
// Find surface height (approximate, usually slightly submerged in swamp)
let floor_y = chunk.get_top_y(&HeightMap::OceanFloorWg, origin_x + 3, origin_z + 3) + 3; // +3 to lift it up
// Vanilla uses adjustToAverageHeight.
let surface_y = chunk.get_top_y(&HeightMap::OceanFloorWg, origin_x + 3, origin_z + 3);
let origin_y = surface_y + 1;
let origin_y = floor_y;
let spruce_planks = &Block::SPRUCE_PLANKS.default_state;
let oak_log = &Block::OAK_LOG.default_state;
let oak_fence = &Block::OAK_FENCE.default_state;
let air = &Block::AIR.default_state;
let fill_rel = |min_x, min_y, min_z, max_x, max_y, max_z, block, c: &mut ProtoChunk| {
// 1. THE FLOOR
fill(
origin_x + 1,
origin_y + 1,
origin_z + 1,
origin_x + 5,
origin_y + 1,
origin_z + 7,
spruce_planks,
chunk,
);
// 2. THE CEILING
fill(
origin_x + 1,
origin_y + 4,
origin_z + 2,
origin_x + 5,
origin_y + 4,
origin_z + 7,
spruce_planks,
chunk,
);
// 3. THE ENTRANCE PLATFORM
fill(
origin_x + 2,
origin_y + 1,
origin_z,
origin_x + 4,
origin_y + 1,
origin_z,
spruce_planks,
chunk,
);
// Front Wall
fill(
origin_x + 2,
origin_y + 2,
origin_z + 2,
origin_x + 3,
origin_y + 3,
origin_z + 2,
spruce_planks,
chunk,
);
// Left Wall
fill(
origin_x + 1,
origin_y + 2,
origin_z + 3,
origin_x + 1,
origin_y + 3,
origin_z + 6,
spruce_planks,
chunk,
);
// Right Wall
fill(
origin_x + 5,
origin_y + 2,
origin_z + 3,
origin_x + 5,
origin_y + 3,
origin_z + 6,
spruce_planks,
chunk,
);
// Back Wall
fill(
origin_x + 2,
origin_y + 2,
origin_z + 7,
origin_x + 4,
origin_y + 3,
origin_z + 7,
spruce_planks,
chunk,
);
// 5. THE LOGS
let logs = [(1, 2), (5, 2), (1, 7), (5, 7)];
for (lx, lz) in logs {
fill(
origin_x + min_x,
origin_y + min_y,
origin_z + min_z,
origin_x + max_x,
origin_y + max_y,
origin_z + max_z,
block,
c,
)
};
let offset = |x, y, z| Vector3::new(origin_x + x, origin_y + y, origin_z + z);
// 1. Stilts (Logs downwards)
let spruce_log = &Block::SPRUCE_LOG.default_state;
let stilts = [(1, 1), (1, 6), (6, 1), (6, 6)];
for (sx, sz) in stilts {
fill_downwards(origin_x + sx, origin_y, origin_z + sz, spruce_log, chunk);
origin_x + lx,
origin_y,
origin_z + lz,
origin_x + lx,
origin_y + 3,
origin_z + lz,
oak_log,
chunk,
);
fill_downwards(origin_x + lx, origin_y - 1, origin_z + lz, oak_log, chunk);
}
// 2. Main Platform (Spruce Planks)
let spruce_planks = &Block::SPRUCE_PLANKS.default_state;
fill_rel(0, 0, 0, 7, 0, 7, spruce_planks, chunk);
// Placed at Y=2 (feet level) or Y=3 (eye level)
let y_floor = origin_y + 2;
let y_eye = origin_y + 3;
// 3. Walls
fill_rel(0, 1, 0, 7, 3, 0, spruce_planks, chunk); // North
fill_rel(0, 1, 7, 7, 3, 7, spruce_planks, chunk); // South
fill_rel(0, 1, 0, 0, 3, 7, spruce_planks, chunk); // West
fill_rel(7, 1, 0, 7, 3, 7, spruce_planks, chunk); // East
chunk.set_block_state(
&Vector3::new(origin_x + 3, y_floor, origin_z + 6),
Block::CRAFTING_TABLE.default_state,
);
chunk.set_block_state(
&Vector3::new(origin_x + 4, y_floor, origin_z + 6),
Block::CAULDRON.default_state,
);
chunk.set_block_state(
&Vector3::new(origin_x + 1, y_eye, origin_z + 5),
Block::POTTED_RED_MUSHROOM.default_state,
);
// 4. Roof (Simple block roof for now, stairs are complex without proper state orientation helpers)
fill_rel(0, 4, 0, 7, 4, 7, spruce_planks, chunk);
fill_rel(1, 5, 1, 6, 5, 6, spruce_planks, chunk);
// Fences & Gaps
chunk.set_block_state(&Vector3::new(origin_x + 2, y_eye, origin_z + 2), oak_fence); // Above the door
chunk.set_block_state(&Vector3::new(origin_x + 3, y_eye, origin_z + 7), oak_fence); // Back window
chunk.set_block_state(
&Vector3::new(origin_x + 1, y_floor, origin_z + 1),
oak_fence,
); // Balcony left
chunk.set_block_state(
&Vector3::new(origin_x + 5, y_floor, origin_z + 1),
oak_fence,
); // Balcony right
// 5. Windows/Air
fill_rel(1, 1, 1, 6, 3, 6, Block::AIR.default_state, chunk); // Clear inside
// 6. Interior Decorations
chunk.set_block_state(&offset(2, 1, 2), Block::CRAFTING_TABLE.default_state);
chunk.set_block_state(&offset(2, 1, 3), Block::CAULDRON.default_state);
// Note: Flower Pot usually requires block entity data or specific state, simplifying here
chunk.set_block_state(&offset(5, 1, 3), Block::POTTED_BLUE_ORCHID.default_state);
// Fence on balcony
chunk.set_block_state(&offset(3, 1, 0), Block::OAK_FENCE.default_state);
// Clear window air (Java: addBlock AIR at 1, 3, 4 and 5, 3, 4/5)
chunk.set_block_state(&Vector3::new(origin_x + 1, y_eye, origin_z + 4), air);
chunk.set_block_state(&Vector3::new(origin_x + 5, y_eye, origin_z + 4), air);
chunk.set_block_state(&Vector3::new(origin_x + 5, y_eye, origin_z + 5), air);
}
}