pumpkin-world(structure): add BuriedTreasureGenerator
This commit is contained in:
1 parent
71dd912eb1
commit
3407404e95
9 files changed
+136
-17
No files matched your search
@@ -109,11 +109,8 @@ impl BoundingBox {
|
||||
}
|
||||
|
||||
let move_positive = movement_on_axis.is_sign_positive();
|
||||
|
||||
let self_plane_const = self.get_side(move_positive).get_axis(axis);
|
||||
|
||||
let other_plane_const = other.get_side(!move_positive).get_axis(axis);
|
||||
|
||||
let collision_time = (other_plane_const - self_plane_const) / movement_on_axis;
|
||||
|
||||
if collision_time < 0.0 || collision_time >= max_time {
|
||||
|
||||
@@ -74,6 +74,10 @@ pub mod section_coords {
|
||||
coord >> 4
|
||||
}
|
||||
|
||||
pub fn get_offset_pos(chunk_coord: i32, offset: i32) -> i32 {
|
||||
section_to_block(chunk_coord) + offset
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn section_to_block<T: PrimInt>(coord: T) -> T {
|
||||
coord << 4
|
||||
|
||||
@@ -36,6 +36,8 @@ pub mod block_pos {
|
||||
pub mod chunk_pos {
|
||||
use pumpkin_util::math::vector2::Vector2;
|
||||
|
||||
use crate::generation::section_coords::get_offset_pos;
|
||||
|
||||
// A chunk outside of normal bounds
|
||||
pub const MARKER: u64 = packed(&Vector2::new(1875066, 1875066));
|
||||
|
||||
@@ -51,6 +53,22 @@ pub mod chunk_pos {
|
||||
((packed >> 32) & 4294967295u64) as i32
|
||||
}
|
||||
|
||||
pub fn get_offset_x(coord: i32, offset: i32) -> i32 {
|
||||
get_offset_pos(coord, offset)
|
||||
}
|
||||
|
||||
pub fn get_center_x(coord: i32) -> i32 {
|
||||
get_offset_x(coord, 8)
|
||||
}
|
||||
|
||||
pub fn get_center_z(coord: i32) -> i32 {
|
||||
get_offset_z(coord, 8)
|
||||
}
|
||||
|
||||
pub fn get_offset_z(coord: i32, offset: i32) -> i32 {
|
||||
get_offset_pos(coord, offset)
|
||||
}
|
||||
|
||||
pub const fn start_block_x(vec: &Vector2<i32>) -> i32 {
|
||||
vec.x << 4
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use serde::Deserialize;
|
||||
use crate::generation::structure::placement::StructurePlacement;
|
||||
|
||||
pub mod placement;
|
||||
pub mod structures;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct StructureSet {
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
use pumpkin_data::{Block, BlockDirection};
|
||||
use pumpkin_util::{
|
||||
HeightMap,
|
||||
math::{position::BlockPos, vector2::Vector2, vector3::Vector3},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ProtoChunk,
|
||||
generation::{
|
||||
height_limit::HeightLimitView,
|
||||
positions::chunk_pos::{get_center_x, get_center_z, get_offset_x, get_offset_z},
|
||||
structure::structures::{Structure, StructurePiecesCollector, StructurePosition},
|
||||
},
|
||||
};
|
||||
|
||||
pub struct BuriedTreasureGenerator {
|
||||
position: BlockPos,
|
||||
}
|
||||
|
||||
impl Structure for BuriedTreasureGenerator {
|
||||
fn get_structure_position(&self, chunk: &ProtoChunk) -> super::StructurePosition {
|
||||
let x = get_center_x(chunk.chunk_pos.x);
|
||||
let z = get_center_z(chunk.chunk_pos.y);
|
||||
let y = chunk.get_top_y(&HeightMap::OceanFloorWg, &Vector2::new(x, z));
|
||||
let generator = StructurePiecesCollector {
|
||||
pieces_positions: vec![BlockPos::new(
|
||||
get_offset_x(chunk.chunk_pos.x, 9),
|
||||
90,
|
||||
get_offset_z(chunk.chunk_pos.y, 9),
|
||||
)],
|
||||
};
|
||||
StructurePosition {
|
||||
position: BlockPos(Vector3::new(x, y, z)),
|
||||
generator,
|
||||
}
|
||||
}
|
||||
|
||||
fn generate(&self, chunk: &mut crate::ProtoChunk) {
|
||||
let y = chunk.get_top_y(
|
||||
&HeightMap::OceanFloorWg,
|
||||
&Vector2::new(self.position.0.x, self.position.0.z),
|
||||
);
|
||||
let mut pos = BlockPos::new(self.position.0.x, y, self.position.0.z);
|
||||
for _ in y..chunk.bottom_y() as i32 {
|
||||
let state = chunk.get_block_state(&pos.0);
|
||||
let down_raw_state = chunk.get_block_state(&pos.down().0);
|
||||
let down_block = down_raw_state.to_block();
|
||||
if down_block == &Block::SANDSTONE
|
||||
|| down_block == &Block::STONE
|
||||
|| down_block == &Block::ANDESITE
|
||||
|| down_block == &Block::GRANITE
|
||||
|| down_block == &Block::DIORITE
|
||||
{
|
||||
for dir in BlockDirection::all() {
|
||||
let pos = pos.offset(dir.to_offset());
|
||||
let dir_state = chunk.get_block_state(&pos.0);
|
||||
if !dir_state.to_state().is_air() && !Self::is_liquid(dir_state.to_block()) {
|
||||
continue;
|
||||
}
|
||||
let down_pos = pos.down();
|
||||
let down_state = chunk.get_block_state(&down_pos.0);
|
||||
if (down_state.to_state().is_air() || Self::is_liquid(down_state.to_block()))
|
||||
&& dir != BlockDirection::Up
|
||||
{
|
||||
chunk.set_block_state(&pos.0, down_raw_state.to_state());
|
||||
continue;
|
||||
}
|
||||
let state1 = if state.to_state().is_air() || Self::is_liquid(state.to_block()) {
|
||||
Block::SAND.default_state
|
||||
} else {
|
||||
state.to_state()
|
||||
};
|
||||
chunk.set_block_state(&pos.0, state1);
|
||||
}
|
||||
// TODO: add loot
|
||||
chunk.set_block_state(&pos.0, Block::CHEST.default_state);
|
||||
return;
|
||||
}
|
||||
pos = pos.down();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BuriedTreasureGenerator {
|
||||
fn is_liquid(block: &Block) -> bool {
|
||||
block == &Block::WATER || block == &Block::LAVA
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
use pumpkin_util::math::position::BlockPos;
|
||||
|
||||
use crate::ProtoChunk;
|
||||
|
||||
pub mod buried_treasure;
|
||||
|
||||
pub trait Structure {
|
||||
fn get_structure_position(&self, chunk: &ProtoChunk) -> StructurePosition;
|
||||
|
||||
fn generate(&self, chunk: &mut crate::ProtoChunk);
|
||||
}
|
||||
|
||||
pub struct StructurePosition {
|
||||
position: BlockPos,
|
||||
generator: StructurePiecesCollector,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct StructurePiecesCollector {
|
||||
pieces_positions: Vec<BlockPos>,
|
||||
}
|
||||
@@ -283,7 +283,7 @@ impl EntityBase for ItemEntity {
|
||||
if on_ground {
|
||||
let block_affecting_velo = entity.get_block_with_y_offset(0.999_999).await.1;
|
||||
|
||||
friction *= f64::from(block_affecting_velo.slipperiness);
|
||||
friction *= f64::from(block_affecting_velo.slipperiness) * 0.98;
|
||||
}
|
||||
|
||||
velo = velo.multiply(friction, 0.98, friction);
|
||||
|
||||
@@ -1130,10 +1130,10 @@ impl Entity {
|
||||
|
||||
let block = world.get_block(&self.block_pos.load()).await;
|
||||
|
||||
let m1 = block.velocity_multiplier;
|
||||
let multiplier = block.velocity_multiplier;
|
||||
|
||||
if m1 != 1f32 || block == &Block::WATER || block == &Block::BUBBLE_COLUMN {
|
||||
m1
|
||||
if multiplier != 1.0 || block == &Block::WATER || block == &Block::BUBBLE_COLUMN {
|
||||
multiplier
|
||||
} else {
|
||||
let (_pos, block, _state) = self.get_block_with_y_offset(0.500_001).await;
|
||||
|
||||
@@ -1166,10 +1166,7 @@ impl Entity {
|
||||
// Move by a delta, adjust for collisions, and send
|
||||
|
||||
// Does not send movement. That must be done separately
|
||||
|
||||
async fn move_entity(&self, caller: Arc<dyn EntityBase>, mut motion: Vector3<f64>) {
|
||||
// TODO: Player movement checking (anticheat)
|
||||
|
||||
if caller.get_player().is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -950,13 +950,9 @@ impl World {
|
||||
|
||||
pub fn check_outline<F>(
|
||||
bounding_box: &BoundingBox,
|
||||
|
||||
pos: BlockPos,
|
||||
|
||||
state: &BlockState,
|
||||
|
||||
use_outline_shape: bool,
|
||||
|
||||
mut using_outline_shape: F,
|
||||
) -> bool
|
||||
where
|
||||
@@ -969,7 +965,6 @@ impl World {
|
||||
}
|
||||
|
||||
let mut inside = false;
|
||||
|
||||
'shapes: for shape in state.get_block_outline_shapes().unwrap() {
|
||||
let outline_shape = shape.at_pos(pos);
|
||||
|
||||
@@ -1019,10 +1014,8 @@ impl World {
|
||||
}
|
||||
|
||||
// For adjusting movement
|
||||
|
||||
pub async fn get_block_collisions(
|
||||
self: &Arc<Self>,
|
||||
|
||||
bounding_box: BoundingBox,
|
||||
) -> (Vec<BoundingBox>, Vec<(usize, BlockPos)>) {
|
||||
let mut collisions = Vec::new();
|
||||
|
||||
Reference in new issue
Block a user