From 3407404e95b64f5942c7d62b4984664f9eaa4055 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev Date: Thu, 14 Aug 2025 23:35:38 +0200 Subject: [PATCH] pumpkin-world(structure): add BuriedTreasureGenerator --- pumpkin-util/src/math/boundingbox.rs | 3 - pumpkin-world/src/generation/mod.rs | 4 + pumpkin-world/src/generation/positions.rs | 18 ++++ pumpkin-world/src/generation/structure/mod.rs | 1 + .../structure/structures/buried_treasure.rs | 88 +++++++++++++++++++ .../generation/structure/structures/mod.rs | 21 +++++ pumpkin/src/entity/item.rs | 2 +- pumpkin/src/entity/mod.rs | 9 +- pumpkin/src/world/mod.rs | 7 -- 9 files changed, 136 insertions(+), 17 deletions(-) create mode 100644 pumpkin-world/src/generation/structure/structures/buried_treasure.rs create mode 100644 pumpkin-world/src/generation/structure/structures/mod.rs diff --git a/pumpkin-util/src/math/boundingbox.rs b/pumpkin-util/src/math/boundingbox.rs index 2a97ed122..6604ba737 100644 --- a/pumpkin-util/src/math/boundingbox.rs +++ b/pumpkin-util/src/math/boundingbox.rs @@ -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 { diff --git a/pumpkin-world/src/generation/mod.rs b/pumpkin-world/src/generation/mod.rs index fd6015708..a240311d7 100644 --- a/pumpkin-world/src/generation/mod.rs +++ b/pumpkin-world/src/generation/mod.rs @@ -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(coord: T) -> T { coord << 4 diff --git a/pumpkin-world/src/generation/positions.rs b/pumpkin-world/src/generation/positions.rs index 683f14831..0ed761307 100644 --- a/pumpkin-world/src/generation/positions.rs +++ b/pumpkin-world/src/generation/positions.rs @@ -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 { vec.x << 4 } diff --git a/pumpkin-world/src/generation/structure/mod.rs b/pumpkin-world/src/generation/structure/mod.rs index d85252d40..881d9b380 100644 --- a/pumpkin-world/src/generation/structure/mod.rs +++ b/pumpkin-world/src/generation/structure/mod.rs @@ -6,6 +6,7 @@ use serde::Deserialize; use crate::generation::structure::placement::StructurePlacement; pub mod placement; +pub mod structures; #[derive(Deserialize)] pub struct StructureSet { diff --git a/pumpkin-world/src/generation/structure/structures/buried_treasure.rs b/pumpkin-world/src/generation/structure/structures/buried_treasure.rs new file mode 100644 index 000000000..4746aaf3f --- /dev/null +++ b/pumpkin-world/src/generation/structure/structures/buried_treasure.rs @@ -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 + } +} diff --git a/pumpkin-world/src/generation/structure/structures/mod.rs b/pumpkin-world/src/generation/structure/structures/mod.rs new file mode 100644 index 000000000..41a7d49d9 --- /dev/null +++ b/pumpkin-world/src/generation/structure/structures/mod.rs @@ -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, +} diff --git a/pumpkin/src/entity/item.rs b/pumpkin/src/entity/item.rs index 5ba4bce3e..6828a3362 100644 --- a/pumpkin/src/entity/item.rs +++ b/pumpkin/src/entity/item.rs @@ -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); diff --git a/pumpkin/src/entity/mod.rs b/pumpkin/src/entity/mod.rs index 4b720e1eb..ce7a50bd1 100644 --- a/pumpkin/src/entity/mod.rs +++ b/pumpkin/src/entity/mod.rs @@ -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, mut motion: Vector3) { - // TODO: Player movement checking (anticheat) - if caller.get_player().is_some() { return; } diff --git a/pumpkin/src/world/mod.rs b/pumpkin/src/world/mod.rs index 1c2c9b435..37716c53c 100644 --- a/pumpkin/src/world/mod.rs +++ b/pumpkin/src/world/mod.rs @@ -950,13 +950,9 @@ impl World { pub fn check_outline( 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, - bounding_box: BoundingBox, ) -> (Vec, Vec<(usize, BlockPos)>) { let mut collisions = Vec::new();