feat: partially implement Stronghold
also fixed some bugs
This commit is contained in:
1 parent
f36baa6f44
commit
a44a5babe3
36 files changed
+4597
-770
No files matched your search
@@ -0,0 +1,124 @@
|
||||
use pumpkin_data::Block;
|
||||
use pumpkin_util::{
|
||||
BlockDirection,
|
||||
math::block_box::BlockBox,
|
||||
random::{RandomGenerator, RandomImpl},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ProtoChunk,
|
||||
generation::structure::{
|
||||
piece::StructurePieceType,
|
||||
structures::{
|
||||
StructurePiece, StructurePieceBase, StructurePiecesCollector,
|
||||
stronghold::{EntranceType, StoneBrickRandomizer, StrongholdPiece},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RightTurnPiece {
|
||||
pub piece: StrongholdPiece,
|
||||
}
|
||||
|
||||
impl RightTurnPiece {
|
||||
pub fn create(
|
||||
collector: &mut StructurePiecesCollector,
|
||||
random: &mut impl RandomImpl,
|
||||
x: i32,
|
||||
y: i32,
|
||||
z: i32,
|
||||
orientation: BlockDirection,
|
||||
chain_length: u32,
|
||||
) -> Option<Box<dyn StructurePieceBase>> {
|
||||
// 5x5x5 box
|
||||
let bounding_box = BlockBox::rotated(x, y, z, -1, -1, 0, 5, 5, 5, &orientation);
|
||||
|
||||
if !StrongholdPiece::is_in_bounds(&bounding_box)
|
||||
|| collector.get_intersecting(&bounding_box).is_some()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut piece = StrongholdPiece::new(
|
||||
StructurePieceType::StrongholdRightTurn,
|
||||
chain_length,
|
||||
bounding_box,
|
||||
);
|
||||
piece.piece.set_facing(Some(orientation));
|
||||
piece.entry_door = EntranceType::get_random(random);
|
||||
|
||||
Some(Box::new(Self { piece }))
|
||||
}
|
||||
}
|
||||
|
||||
impl StructurePieceBase for RightTurnPiece {
|
||||
fn get_structure_piece(&self) -> &StructurePiece {
|
||||
&self.piece.piece
|
||||
}
|
||||
|
||||
fn get_structure_piece_mut(&mut self) -> &mut StructurePiece {
|
||||
&mut self.piece.piece
|
||||
}
|
||||
|
||||
fn fill_openings(
|
||||
&self,
|
||||
start: &StructurePiece,
|
||||
random: &mut RandomGenerator,
|
||||
collector: &mut StructurePiecesCollector,
|
||||
pieces_to_process: &mut Vec<Box<dyn StructurePieceBase>>,
|
||||
) {
|
||||
let facing = self.piece.piece.facing.unwrap_or(BlockDirection::North);
|
||||
|
||||
// For a Right Turn, we swap the logic from the Left Turn:
|
||||
// If facing North/East, we go "South-East", otherwise "North-West"
|
||||
if facing == BlockDirection::North || facing == BlockDirection::East {
|
||||
self.piece
|
||||
.fill_se_opening(start, collector, random, 1, 1, pieces_to_process);
|
||||
} else {
|
||||
self.piece
|
||||
.fill_nw_opening(start, collector, random, 1, 1, pieces_to_process);
|
||||
}
|
||||
}
|
||||
|
||||
fn place(&mut self, chunk: &mut ProtoChunk, random: &mut RandomGenerator, _seed: i64) {
|
||||
let randomizer = StoneBrickRandomizer;
|
||||
let box_limit = self.piece.piece.bounding_box;
|
||||
let p = &self.piece;
|
||||
let inner = &p.piece;
|
||||
|
||||
// 1. 5x5x5 Outline (Using randomizer)
|
||||
// Note: Use your existing fill_outline_random for this part
|
||||
inner.fill_outline_random(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
4,
|
||||
4,
|
||||
4,
|
||||
&randomizer,
|
||||
chunk,
|
||||
true,
|
||||
random,
|
||||
&box_limit,
|
||||
);
|
||||
|
||||
// 2. Entrance (Z=0)
|
||||
p.generate_entrance(chunk, &box_limit, self.piece.entry_door, 1, 1, 0);
|
||||
|
||||
// 3. Exit logic based on Facing
|
||||
let air = Block::AIR.default_state;
|
||||
let facing = inner.facing.unwrap_or(BlockDirection::North);
|
||||
|
||||
if facing == BlockDirection::North || facing == BlockDirection::East {
|
||||
// Exit on X=4 wall
|
||||
inner.fill_with_outline(chunk, &box_limit, false, 4, 1, 1, 4, 3, 3, air, air);
|
||||
} else {
|
||||
inner.fill_with_outline(chunk, &box_limit, false, 0, 1, 1, 0, 3, 3, air, air);
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_box(&self) -> Box<dyn StructurePieceBase> {
|
||||
Box::new((*self).clone())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user