diff --git a/README.md b/README.md index 11339e04..354a243e 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ and customizable experience. It prioritizes performance and player enjoyment whi - [x] Scoreboard - [x] World Borders - [x] World Saving + - [ ] Redstone + - [ ] Liquid Physics - Player - [x] Player Skins - [x] Player Client brand diff --git a/pumpkin-config/src/chunk.rs b/pumpkin-config/src/chunk.rs new file mode 100644 index 00000000..edc09560 --- /dev/null +++ b/pumpkin-config/src/chunk.rs @@ -0,0 +1,37 @@ +use std::str; + +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize, Serialize, Default)] +#[serde(default)] +pub struct ChunkConfig { + pub compression: ChunkCompression, +} + +#[derive(Deserialize, Serialize)] +pub struct ChunkCompression { + pub compression_algorithm: Compression, + pub compression_level: u32, +} + +impl Default for ChunkCompression { + fn default() -> Self { + Self { + compression_algorithm: Compression::LZ4, + compression_level: 6, + } + } +} + +#[derive(Deserialize, Serialize, Clone)] +#[repr(u8)] +pub enum Compression { + /// GZip Compression + GZip, + /// ZLib Compression + ZLib, + /// LZ4 Compression (since 24w04a) + LZ4, + /// Custom compression algorithm (since 24w05a) + Custom, +} diff --git a/pumpkin-config/src/lib.rs b/pumpkin-config/src/lib.rs index 24f10e6c..04804ae0 100644 --- a/pumpkin-config/src/lib.rs +++ b/pumpkin-config/src/lib.rs @@ -1,3 +1,4 @@ +use chunk::ChunkConfig; use log::warn; use logging::LoggingConfig; use pumpkin_util::{Difficulty, GameMode, PermissionLvl}; @@ -26,6 +27,7 @@ pub use server_links::ServerLinksConfig; mod commands; +pub mod chunk; pub mod op; mod pvp; mod server_links; @@ -50,6 +52,7 @@ pub static BASIC_CONFIG: LazyLock = LazyLock::new(BasicConfi pub struct AdvancedConfiguration { pub logging: LoggingConfig, pub resource_pack: ResourcePackConfig, + pub chunk: ChunkConfig, pub networking: NetworkingConfig, pub commands: CommandsConfig, pub pvp: PVPConfig, diff --git a/pumpkin-config/src/logging.rs b/pumpkin-config/src/logging.rs index 21386e6e..06402692 100644 --- a/pumpkin-config/src/logging.rs +++ b/pumpkin-config/src/logging.rs @@ -4,8 +4,6 @@ use serde::{Deserialize, Serialize}; #[serde(default)] pub struct LoggingConfig { pub enabled: bool, - pub level: LevelFilter, - pub env: bool, pub threads: bool, pub color: bool, pub timestamp: bool, @@ -15,24 +13,9 @@ impl Default for LoggingConfig { fn default() -> Self { Self { enabled: true, - level: Default::default(), - env: false, threads: true, color: true, timestamp: true, } } } - -#[derive( - Deserialize, Serialize, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, -)] -pub enum LevelFilter { - Off, - Error, - Warn, - #[default] - Info, - Debug, - Trace, -} diff --git a/pumpkin-inventory/src/open_container.rs b/pumpkin-inventory/src/open_container.rs index 1659c9d4..70d9242f 100644 --- a/pumpkin-inventory/src/open_container.rs +++ b/pumpkin-inventory/src/open_container.rs @@ -1,7 +1,7 @@ use crate::crafting::check_if_matches_crafting; use crate::Container; use pumpkin_data::screen::WindowType; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_world::block::block_registry::Block; use pumpkin_world::item::ItemStack; use std::sync::Arc; @@ -12,7 +12,7 @@ pub struct OpenContainer { // TODO: should this be uuid? players: Vec, container: Arc>>, - location: Option, + location: Option, block: Option, } @@ -46,7 +46,7 @@ impl OpenContainer { pub fn new_empty_container( player_id: i32, - location: Option, + location: Option, block: Option, ) -> Self { Self { @@ -57,7 +57,7 @@ impl OpenContainer { } } - pub fn is_location(&self, try_position: WorldPosition) -> bool { + pub fn is_location(&self, try_position: BlockPos) -> bool { if let Some(location) = self.location { location == try_position } else { @@ -81,11 +81,11 @@ impl OpenContainer { self.players.len() } - pub fn get_location(&self) -> Option { + pub fn get_location(&self) -> Option { self.location } - pub async fn set_location(&mut self, location: Option) { + pub async fn set_location(&mut self, location: Option) { self.location = location; } diff --git a/pumpkin-protocol/src/client/play/c_block_destroy_stage.rs b/pumpkin-protocol/src/client/play/c_block_destroy_stage.rs index 10379410..3763b6f1 100644 --- a/pumpkin-protocol/src/client/play/c_block_destroy_stage.rs +++ b/pumpkin-protocol/src/client/play/c_block_destroy_stage.rs @@ -1,5 +1,5 @@ use pumpkin_data::packet::clientbound::PLAY_BLOCK_DESTRUCTION; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_macros::client_packet; use serde::Serialize; @@ -10,12 +10,12 @@ use crate::VarInt; #[client_packet(PLAY_BLOCK_DESTRUCTION)] pub struct CSetBlockDestroyStage { entity_id: VarInt, - location: WorldPosition, + location: BlockPos, destroy_stage: u8, } impl CSetBlockDestroyStage { - pub fn new(entity_id: VarInt, location: WorldPosition, destroy_stage: u8) -> Self { + pub fn new(entity_id: VarInt, location: BlockPos, destroy_stage: u8) -> Self { Self { entity_id, location, diff --git a/pumpkin-protocol/src/client/play/c_block_event.rs b/pumpkin-protocol/src/client/play/c_block_event.rs index fc193119..30e0f969 100644 --- a/pumpkin-protocol/src/client/play/c_block_event.rs +++ b/pumpkin-protocol/src/client/play/c_block_event.rs @@ -1,5 +1,5 @@ use pumpkin_data::packet::clientbound::PLAY_BLOCK_EVENT; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_macros::client_packet; use serde::Serialize; @@ -9,7 +9,7 @@ use crate::VarInt; #[derive(Serialize)] #[client_packet(PLAY_BLOCK_EVENT)] pub struct CBlockAction<'a> { - location: &'a WorldPosition, + location: &'a BlockPos, action_id: u8, action_parameter: u8, block_type: VarInt, @@ -17,7 +17,7 @@ pub struct CBlockAction<'a> { impl<'a> CBlockAction<'a> { pub fn new( - location: &'a WorldPosition, + location: &'a BlockPos, action_id: u8, action_parameter: u8, block_type: VarInt, diff --git a/pumpkin-protocol/src/client/play/c_block_update.rs b/pumpkin-protocol/src/client/play/c_block_update.rs index 37ecf3b8..ddc06742 100644 --- a/pumpkin-protocol/src/client/play/c_block_update.rs +++ b/pumpkin-protocol/src/client/play/c_block_update.rs @@ -1,5 +1,5 @@ use pumpkin_data::packet::clientbound::PLAY_BLOCK_UPDATE; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_macros::client_packet; use serde::Serialize; @@ -9,12 +9,12 @@ use crate::VarInt; #[derive(Serialize)] #[client_packet(PLAY_BLOCK_UPDATE)] pub struct CBlockUpdate<'a> { - location: &'a WorldPosition, + location: &'a BlockPos, block_id: VarInt, } impl<'a> CBlockUpdate<'a> { - pub fn new(location: &'a WorldPosition, block_id: VarInt) -> Self { + pub fn new(location: &'a BlockPos, block_id: VarInt) -> Self { Self { location, block_id } } } diff --git a/pumpkin-protocol/src/client/play/c_level_event.rs b/pumpkin-protocol/src/client/play/c_level_event.rs index fabc681f..9276dc8b 100644 --- a/pumpkin-protocol/src/client/play/c_level_event.rs +++ b/pumpkin-protocol/src/client/play/c_level_event.rs @@ -1,24 +1,19 @@ use pumpkin_data::packet::clientbound::PLAY_LEVEL_EVENT; use pumpkin_macros::client_packet; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use serde::Serialize; #[derive(Serialize)] #[client_packet(PLAY_LEVEL_EVENT)] pub struct CLevelEvent { event: i32, - location: WorldPosition, + location: BlockPos, data: i32, disable_relative_volume: bool, } impl CLevelEvent { - pub fn new( - event: i32, - location: WorldPosition, - data: i32, - disable_relative_volume: bool, - ) -> Self { + pub fn new(event: i32, location: BlockPos, data: i32, disable_relative_volume: bool) -> Self { Self { event, location, diff --git a/pumpkin-protocol/src/client/play/c_login.rs b/pumpkin-protocol/src/client/play/c_login.rs index d2685663..f32a06b8 100644 --- a/pumpkin-protocol/src/client/play/c_login.rs +++ b/pumpkin-protocol/src/client/play/c_login.rs @@ -1,5 +1,5 @@ use pumpkin_data::packet::clientbound::PLAY_LOGIN; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_macros::client_packet; use serde::Serialize; @@ -27,7 +27,7 @@ pub struct CLogin<'a> { previous_gamemode: i8, debug: bool, is_flat: bool, - death_dimension_name: Option<(Identifier, WorldPosition)>, + death_dimension_name: Option<(Identifier, BlockPos)>, portal_cooldown: VarInt, sealevel: VarInt, enforce_secure_chat: bool, @@ -52,7 +52,7 @@ impl<'a> CLogin<'a> { previous_gamemode: i8, debug: bool, is_flat: bool, - death_dimension_name: Option<(Identifier, WorldPosition)>, + death_dimension_name: Option<(Identifier, BlockPos)>, portal_cooldown: VarInt, sealevel: VarInt, enforce_secure_chat: bool, diff --git a/pumpkin-protocol/src/client/play/c_respawn.rs b/pumpkin-protocol/src/client/play/c_respawn.rs index d2aad300..66cf233e 100644 --- a/pumpkin-protocol/src/client/play/c_respawn.rs +++ b/pumpkin-protocol/src/client/play/c_respawn.rs @@ -1,6 +1,6 @@ use pumpkin_data::packet::clientbound::PLAY_RESPAWN; use pumpkin_macros::client_packet; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use serde::Serialize; use crate::{codec::identifier::Identifier, VarInt}; @@ -15,7 +15,7 @@ pub struct CRespawn { previous_gamemode: i8, debug: bool, is_flat: bool, - death_dimension_name: Option<(Identifier, WorldPosition)>, + death_dimension_name: Option<(Identifier, BlockPos)>, portal_cooldown: VarInt, sealevel: VarInt, data_kept: u8, @@ -31,7 +31,7 @@ impl CRespawn { previous_gamemode: i8, debug: bool, is_flat: bool, - death_dimension_name: Option<(Identifier, WorldPosition)>, + death_dimension_name: Option<(Identifier, BlockPos)>, portal_cooldown: VarInt, sealevel: VarInt, data_kept: u8, diff --git a/pumpkin-protocol/src/client/play/c_worldevent.rs b/pumpkin-protocol/src/client/play/c_worldevent.rs index eec64d7c..c708bc9a 100644 --- a/pumpkin-protocol/src/client/play/c_worldevent.rs +++ b/pumpkin-protocol/src/client/play/c_worldevent.rs @@ -1,5 +1,5 @@ use pumpkin_data::packet::clientbound::PLAY_LEVEL_EVENT; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_macros::client_packet; use serde::Serialize; @@ -8,7 +8,7 @@ use serde::Serialize; #[client_packet(PLAY_LEVEL_EVENT)] pub struct CWorldEvent<'a> { event: i32, - location: &'a WorldPosition, + location: &'a BlockPos, data: i32, disable_relative_volume: bool, } @@ -16,7 +16,7 @@ pub struct CWorldEvent<'a> { impl<'a> CWorldEvent<'a> { pub fn new( event: i32, - location: &'a WorldPosition, + location: &'a BlockPos, data: i32, disable_relative_volume: bool, ) -> Self { diff --git a/pumpkin-protocol/src/server/play/s_pick_item.rs b/pumpkin-protocol/src/server/play/s_pick_item.rs index 52c69979..99a12177 100644 --- a/pumpkin-protocol/src/server/play/s_pick_item.rs +++ b/pumpkin-protocol/src/server/play/s_pick_item.rs @@ -1,12 +1,12 @@ use pumpkin_data::packet::serverbound::{PLAY_PICK_ITEM_FROM_BLOCK, PLAY_PICK_ITEM_FROM_ENTITY}; use pumpkin_macros::server_packet; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use serde::Deserialize; #[derive(Deserialize)] #[server_packet(PLAY_PICK_ITEM_FROM_BLOCK)] pub struct SPickItemFromBlock { - pub pos: WorldPosition, + pub pos: BlockPos, pub include_data: bool, } diff --git a/pumpkin-protocol/src/server/play/s_player_action.rs b/pumpkin-protocol/src/server/play/s_player_action.rs index 90f31a0a..1a233f89 100644 --- a/pumpkin-protocol/src/server/play/s_player_action.rs +++ b/pumpkin-protocol/src/server/play/s_player_action.rs @@ -1,6 +1,6 @@ use pumpkin_data::packet::serverbound::PLAY_PLAYER_ACTION; use pumpkin_macros::server_packet; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use crate::VarInt; @@ -8,7 +8,7 @@ use crate::VarInt; #[server_packet(PLAY_PLAYER_ACTION)] pub struct SPlayerAction { pub status: VarInt, - pub location: WorldPosition, + pub location: BlockPos, pub face: u8, pub sequence: VarInt, } diff --git a/pumpkin-protocol/src/server/play/s_use_item_on.rs b/pumpkin-protocol/src/server/play/s_use_item_on.rs index f3e3e95a..d0d01588 100644 --- a/pumpkin-protocol/src/server/play/s_use_item_on.rs +++ b/pumpkin-protocol/src/server/play/s_use_item_on.rs @@ -1,6 +1,6 @@ use pumpkin_data::packet::serverbound::PLAY_USE_ITEM_ON; use pumpkin_macros::server_packet; -use pumpkin_util::math::{position::WorldPosition, vector3::Vector3}; +use pumpkin_util::math::{position::BlockPos, vector3::Vector3}; use serde::Deserialize; use crate::VarInt; @@ -9,7 +9,7 @@ use crate::VarInt; #[server_packet(PLAY_USE_ITEM_ON)] pub struct SUseItemOn { pub hand: VarInt, - pub location: WorldPosition, + pub location: BlockPos, pub face: VarInt, pub cursor_pos: Vector3, pub inside_block: bool, diff --git a/pumpkin-util/src/math/boundingbox.rs b/pumpkin-util/src/math/boundingbox.rs index d9ad58d8..31848ae9 100644 --- a/pumpkin-util/src/math/boundingbox.rs +++ b/pumpkin-util/src/math/boundingbox.rs @@ -1,4 +1,4 @@ -use super::{position::WorldPosition, vector3::Vector3}; +use super::{position::BlockPos, vector3::Vector3}; #[derive(Clone, Copy)] pub struct BoundingBox { @@ -38,7 +38,7 @@ impl BoundingBox { } } - pub fn from_block(position: &WorldPosition) -> Self { + pub fn from_block(position: &BlockPos) -> Self { let position = position.0; Self { min_x: position.x as f64, diff --git a/pumpkin-util/src/math/position.rs b/pumpkin-util/src/math/position.rs index a3b82cbe..0bd9a478 100644 --- a/pumpkin-util/src/math/position.rs +++ b/pumpkin-util/src/math/position.rs @@ -7,9 +7,9 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Copy, PartialEq, Eq)] /// Aka Block Position -pub struct WorldPosition(pub Vector3); +pub struct BlockPos(pub Vector3); -impl WorldPosition { +impl BlockPos { pub fn chunk_and_chunk_relative_position(&self) -> (Vector2, Vector3) { let (z_chunk, z_rem) = self.0.z.div_rem_euclid(&16); let (x_chunk, x_rem) = self.0.x.div_rem_euclid(&16); @@ -28,7 +28,7 @@ impl WorldPosition { (chunk_coordinate, relative) } } -impl Serialize for WorldPosition { +impl Serialize for BlockPos { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, @@ -40,14 +40,14 @@ impl Serialize for WorldPosition { } } -impl<'de> Deserialize<'de> for WorldPosition { +impl<'de> Deserialize<'de> for BlockPos { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { struct Visitor; impl serde::de::Visitor<'_> for Visitor { - type Value = WorldPosition; + type Value = BlockPos; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { formatter.write_str("An i64 int") } @@ -55,7 +55,7 @@ impl<'de> Deserialize<'de> for WorldPosition { where E: serde::de::Error, { - Ok(WorldPosition(Vector3 { + Ok(BlockPos(Vector3 { x: (v >> 38) as i32, y: (v << 52 >> 52) as i32, z: (v << 26 >> 38) as i32, @@ -66,7 +66,7 @@ impl<'de> Deserialize<'de> for WorldPosition { } } -impl fmt::Display for WorldPosition { +impl fmt::Display for BlockPos { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}, {}, {}", self.0.x, self.0.y, self.0.z) } diff --git a/pumpkin-world/src/chunk/anvil.rs b/pumpkin-world/src/chunk/anvil.rs index ad2a3c25..66898f09 100644 --- a/pumpkin-world/src/chunk/anvil.rs +++ b/pumpkin-world/src/chunk/anvil.rs @@ -2,6 +2,7 @@ use bytes::*; use fastnbt::LongArray; use flate2::bufread::{GzDecoder, GzEncoder, ZlibDecoder, ZlibEncoder}; use indexmap::IndexMap; +use pumpkin_config::ADVANCED_CONFIG; use pumpkin_util::math::ceil_log2; use std::time::{SystemTime, UNIX_EPOCH}; use std::{ @@ -38,6 +39,18 @@ pub enum Compression { Custom = 127, } +impl From for Compression { + fn from(value: pumpkin_config::chunk::Compression) -> Self { + // :c + match value { + pumpkin_config::chunk::Compression::GZip => Self::GZip, + pumpkin_config::chunk::Compression::ZLib => Self::ZLib, + pumpkin_config::chunk::Compression::LZ4 => Self::LZ4, + pumpkin_config::chunk::Compression::Custom => Self::Custom, + } + } +} + impl Compression { /// Returns Ok when a compression is found otherwise an Err #[allow(clippy::result_unit_err)] @@ -241,9 +254,17 @@ impl ChunkWriter for AnvilChunkFormat { .map_err(|err| ChunkWritingError::ChunkSerializingError(err.to_string()))?; // Compress chunk data - let compression = Compression::ZLib; + let compression: Compression = ADVANCED_CONFIG + .chunk + .compression + .compression_algorithm + .clone() + .into(); let compressed_data = compression - .compress_data(&raw_bytes, 6) + .compress_data( + &raw_bytes, + ADVANCED_CONFIG.chunk.compression.compression_level, + ) .map_err(ChunkWritingError::Compression)?; // Length of compressed data + compression type diff --git a/pumpkin-world/src/coordinates.rs b/pumpkin-world/src/coordinates.rs index 74f3c4bb..d8be245e 100644 --- a/pumpkin-world/src/coordinates.rs +++ b/pumpkin-world/src/coordinates.rs @@ -14,13 +14,13 @@ use serde::{Deserialize, Serialize}; pub struct Height(pub i16); impl Height { - pub fn from_absolute(height: u16) -> Self { - (height as i16 - WORLD_LOWEST_Y.abs()).into() + pub const fn from_absolute(height: u16) -> Self { + Self(height as i16 - WORLD_LOWEST_Y.abs()) } /// Absolute height ranges from `0..WORLD_HEIGHT` /// instead of `WORLD_LOWEST_Y..WORLD_MAX_Y` - pub fn get_absolute(self) -> u16 { + pub const fn get_absolute(self) -> u16 { (self.0 + WORLD_LOWEST_Y.abs()) as u16 } } diff --git a/pumpkin-world/src/cylindrical_chunk_iterator.rs b/pumpkin-world/src/cylindrical_chunk_iterator.rs index c588e86f..035cd3f1 100644 --- a/pumpkin-world/src/cylindrical_chunk_iterator.rs +++ b/pumpkin-world/src/cylindrical_chunk_iterator.rs @@ -61,7 +61,7 @@ impl Cylindrical { let min_leg = rel_x.min(rel_z) as i64; let hyp_sqr = max_leg * max_leg + min_leg * min_leg; - hyp_sqr < (self.view_distance.get() as i64 * self.view_distance.get() as i64) + hyp_sqr < (self.view_distance.saturating_mul(self.view_distance).get() as i64) } /// Returns an iterator of all chunks within this cylinder diff --git a/pumpkin/src/block/block_manager.rs b/pumpkin/src/block/block_manager.rs index b3034c04..fd62bc58 100644 --- a/pumpkin/src/block/block_manager.rs +++ b/pumpkin/src/block/block_manager.rs @@ -2,7 +2,7 @@ use crate::block::pumpkin_block::{BlockMetadata, PumpkinBlock}; use crate::entity::player::Player; use crate::server::Server; use pumpkin_inventory::OpenContainer; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_world::block::block_registry::Block; use pumpkin_world::item::item_registry::Item; use std::collections::HashMap; @@ -29,7 +29,7 @@ impl BlockManager { &self, block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, ) { let pumpkin_block = self.get_pumpkin_block(block); @@ -42,7 +42,7 @@ impl BlockManager { &self, block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, item: &Item, server: &Server, ) -> BlockActionResult { @@ -59,7 +59,7 @@ impl BlockManager { &self, block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, ) { let pumpkin_block = self.get_pumpkin_block(block); @@ -74,7 +74,7 @@ impl BlockManager { &self, block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, ) { let pumpkin_block = self.get_pumpkin_block(block); @@ -89,7 +89,7 @@ impl BlockManager { &self, block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, container: &mut OpenContainer, ) { diff --git a/pumpkin/src/block/blocks/chest.rs b/pumpkin/src/block/blocks/chest.rs index dafe4343..9a4c5452 100644 --- a/pumpkin/src/block/blocks/chest.rs +++ b/pumpkin/src/block/blocks/chest.rs @@ -3,7 +3,7 @@ use pumpkin_data::{screen::WindowType, sound::Sound}; use pumpkin_inventory::{Chest, OpenContainer}; use pumpkin_macros::pumpkin_block; use pumpkin_protocol::{client::play::CBlockAction, codec::var_int::VarInt}; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_world::{ block::block_registry::{get_block, Block}, item::item_registry::Item, @@ -30,7 +30,7 @@ impl PumpkinBlock for ChestBlock { &self, block: &Block, player: &Player, - _location: WorldPosition, + _location: BlockPos, server: &Server, ) { self.open_chest_block(block, player, _location, server) @@ -41,7 +41,7 @@ impl PumpkinBlock for ChestBlock { &self, block: &Block, player: &Player, - _location: WorldPosition, + _location: BlockPos, _item: &Item, server: &Server, ) -> BlockActionResult { @@ -54,7 +54,7 @@ impl PumpkinBlock for ChestBlock { &self, block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, ) { super::standard_on_broken_with_container(block, player, location, server).await; @@ -64,7 +64,7 @@ impl PumpkinBlock for ChestBlock { &self, _block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, container: &mut OpenContainer, ) { @@ -80,7 +80,7 @@ impl ChestBlock { &self, block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, ) { // TODO: shouldn't Chest and window type be constrained together to avoid errors? @@ -106,7 +106,7 @@ impl ChestBlock { &self, container: &OpenContainer, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, state: ChestState, ) { diff --git a/pumpkin/src/block/blocks/crafting_table.rs b/pumpkin/src/block/blocks/crafting_table.rs index bb216212..236442dd 100644 --- a/pumpkin/src/block/blocks/crafting_table.rs +++ b/pumpkin/src/block/blocks/crafting_table.rs @@ -6,7 +6,7 @@ use async_trait::async_trait; use pumpkin_data::screen::WindowType; use pumpkin_inventory::{CraftingTable, OpenContainer}; use pumpkin_macros::pumpkin_block; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_world::{block::block_registry::Block, item::item_registry::Item}; #[pumpkin_block("minecraft:crafting_table")] @@ -18,7 +18,7 @@ impl PumpkinBlock for CraftingTableBlock { &self, block: &Block, player: &Player, - _location: WorldPosition, + _location: BlockPos, server: &Server, ) { self.open_crafting_screen(block, player, _location, server) @@ -29,7 +29,7 @@ impl PumpkinBlock for CraftingTableBlock { &self, block: &Block, player: &Player, - _location: WorldPosition, + _location: BlockPos, _item: &Item, server: &Server, ) -> BlockActionResult { @@ -42,7 +42,7 @@ impl PumpkinBlock for CraftingTableBlock { &self, block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, ) { super::standard_on_broken_with_container(block, player, location, server).await; @@ -52,7 +52,7 @@ impl PumpkinBlock for CraftingTableBlock { &self, _block: &Block, player: &Player, - _location: WorldPosition, + _location: BlockPos, _server: &Server, container: &mut OpenContainer, ) { @@ -76,7 +76,7 @@ impl CraftingTableBlock { &self, block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, ) { super::standard_open_container_unique::( diff --git a/pumpkin/src/block/blocks/furnace.rs b/pumpkin/src/block/blocks/furnace.rs index d8f06f3e..7014c1aa 100644 --- a/pumpkin/src/block/blocks/furnace.rs +++ b/pumpkin/src/block/blocks/furnace.rs @@ -4,7 +4,7 @@ use async_trait::async_trait; use pumpkin_data::screen::WindowType; use pumpkin_inventory::Furnace; use pumpkin_macros::pumpkin_block; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_world::block::block_registry::Block; use pumpkin_world::item::item_registry::Item; @@ -19,7 +19,7 @@ impl PumpkinBlock for FurnaceBlock { &self, block: &Block, player: &Player, - _location: WorldPosition, + _location: BlockPos, server: &Server, ) { self.open_furnace_screen(block, player, _location, server) @@ -30,7 +30,7 @@ impl PumpkinBlock for FurnaceBlock { &self, block: &Block, player: &Player, - _location: WorldPosition, + _location: BlockPos, _item: &Item, server: &Server, ) -> BlockActionResult { @@ -43,7 +43,7 @@ impl PumpkinBlock for FurnaceBlock { &self, block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, ) { super::standard_on_broken_with_container(block, player, location, server).await; @@ -55,7 +55,7 @@ impl FurnaceBlock { &self, block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, ) { super::standard_open_container::( diff --git a/pumpkin/src/block/blocks/jukebox.rs b/pumpkin/src/block/blocks/jukebox.rs index 4588c4dc..b013ca38 100644 --- a/pumpkin/src/block/blocks/jukebox.rs +++ b/pumpkin/src/block/blocks/jukebox.rs @@ -5,7 +5,7 @@ use crate::server::Server; use async_trait::async_trait; use pumpkin_macros::pumpkin_block; use pumpkin_registry::SYNCED_REGISTRIES; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_world::block::block_registry::Block; use pumpkin_world::item::item_registry::Item; @@ -18,7 +18,7 @@ impl PumpkinBlock for JukeboxBlock { &self, _block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, _server: &Server, ) { // For now just stop the music at this position @@ -31,7 +31,7 @@ impl PumpkinBlock for JukeboxBlock { &self, _block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, item: &Item, _server: &Server, ) -> BlockActionResult { @@ -61,7 +61,7 @@ impl PumpkinBlock for JukeboxBlock { &self, _block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, _server: &Server, ) { // For now just stop the music at this position diff --git a/pumpkin/src/block/blocks/mod.rs b/pumpkin/src/block/blocks/mod.rs index 272482d9..8ac11597 100644 --- a/pumpkin/src/block/blocks/mod.rs +++ b/pumpkin/src/block/blocks/mod.rs @@ -1,6 +1,6 @@ use pumpkin_data::screen::WindowType; use pumpkin_inventory::{Container, OpenContainer}; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_world::block::block_registry::Block; use crate::{entity::player::Player, server::Server}; @@ -15,7 +15,7 @@ pub(crate) mod jukebox; pub async fn standard_on_broken_with_container( block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, ) { // TODO: drop all items and back to players inventory if in motion @@ -38,7 +38,7 @@ pub async fn standard_on_broken_with_container( pub async fn standard_open_container( block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, window_type: WindowType, ) { @@ -66,7 +66,7 @@ pub async fn standard_open_container( pub async fn standard_open_container_unique( block: &Block, player: &Player, - location: WorldPosition, + location: BlockPos, server: &Server, window_type: WindowType, ) { diff --git a/pumpkin/src/block/pumpkin_block.rs b/pumpkin/src/block/pumpkin_block.rs index 364875ba..afe30455 100644 --- a/pumpkin/src/block/pumpkin_block.rs +++ b/pumpkin/src/block/pumpkin_block.rs @@ -3,7 +3,7 @@ use crate::entity::player::Player; use crate::server::Server; use async_trait::async_trait; use pumpkin_inventory::OpenContainer; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_world::block::block_registry::Block; use pumpkin_world::item::item_registry::Item; @@ -21,7 +21,7 @@ pub trait PumpkinBlock: Send + Sync { &self, _block: &Block, _player: &Player, - _location: WorldPosition, + _location: BlockPos, _server: &Server, ) { } @@ -29,7 +29,7 @@ pub trait PumpkinBlock: Send + Sync { &self, _block: &Block, _player: &Player, - _location: WorldPosition, + _location: BlockPos, _item: &Item, _server: &Server, ) -> BlockActionResult { @@ -40,7 +40,7 @@ pub trait PumpkinBlock: Send + Sync { &self, _block: &Block, _player: &Player, - _location: WorldPosition, + _location: BlockPos, _server: &Server, ) { } @@ -49,7 +49,7 @@ pub trait PumpkinBlock: Send + Sync { &self, _block: &Block, _player: &Player, - _location: WorldPosition, + _location: BlockPos, _server: &Server, ) { } @@ -58,7 +58,7 @@ pub trait PumpkinBlock: Send + Sync { &self, _block: &Block, _player: &Player, - _location: WorldPosition, + _location: BlockPos, _server: &Server, _container: &mut OpenContainer, ) { diff --git a/pumpkin/src/command/args/arg_position_block.rs b/pumpkin/src/command/args/arg_position_block.rs index f692dc8d..6d1b9966 100644 --- a/pumpkin/src/command/args/arg_position_block.rs +++ b/pumpkin/src/command/args/arg_position_block.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use pumpkin_protocol::client::play::{ CommandSuggestion, ProtoCmdArgParser, ProtoCmdArgSuggestionType, }; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_util::math::vector3::Vector3; use crate::command::dispatcher::CommandError; @@ -67,8 +67,8 @@ impl MaybeRelativeBlockPos { )) } - fn try_to_absolute(self, origin: Option>) -> Option { - Some(WorldPosition(Vector3::new( + fn try_to_absolute(self, origin: Option>) -> Option { + Some(BlockPos(Vector3::new( self.0.into_absolute(origin.map(|o| o.x))?, self.1.into_absolute(origin.map(|o| o.y))?, self.2.into_absolute(origin.map(|o| o.z))?, @@ -83,7 +83,7 @@ impl DefaultNameArgConsumer for BlockPosArgumentConsumer { } impl<'a> FindArg<'a> for BlockPosArgumentConsumer { - type Data = WorldPosition; + type Data = BlockPos; fn find_arg(args: &'a super::ConsumedArgs, name: &str) -> Result { match args.get(name) { diff --git a/pumpkin/src/command/args/mod.rs b/pumpkin/src/command/args/mod.rs index 8cc7e2d4..4a0fedf4 100644 --- a/pumpkin/src/command/args/mod.rs +++ b/pumpkin/src/command/args/mod.rs @@ -7,7 +7,7 @@ use pumpkin_protocol::client::play::{ }; use pumpkin_util::text::TextComponent; use pumpkin_util::{ - math::{position::WorldPosition, vector2::Vector2, vector3::Vector3}, + math::{position::BlockPos, vector2::Vector2, vector3::Vector3}, GameMode, }; @@ -77,7 +77,7 @@ pub(crate) enum Arg<'a> { Entities(Vec>), Entity(Arc), Players(Vec>), - BlockPos(WorldPosition), + BlockPos(BlockPos), Pos3D(Vector3), Pos2D(Vector2), Rotation(f32, f32), diff --git a/pumpkin/src/command/commands/cmd_fill.rs b/pumpkin/src/command/commands/cmd_fill.rs index cb84ff90..ec77cff9 100644 --- a/pumpkin/src/command/commands/cmd_fill.rs +++ b/pumpkin/src/command/commands/cmd_fill.rs @@ -6,7 +6,7 @@ use crate::command::tree_builder::{argument, literal}; use crate::command::{CommandError, CommandExecutor, CommandSender}; use async_trait::async_trait; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_util::math::vector3::Vector3; use pumpkin_util::text::TextComponent; @@ -66,9 +66,9 @@ impl CommandExecutor for SetblockExecutor { for x in start_x..=end_x { for y in start_y..=end_y { for z in start_z..=end_z { - let block_position = WorldPosition(Vector3 { x, y, z }); - world.break_block(block_position, None).await; - world.set_block_state(block_position, block_state_id).await; + let block_position = BlockPos(Vector3 { x, y, z }); + world.break_block(&block_position, None).await; + world.set_block_state(&block_position, block_state_id).await; placed_blocks += 1; } } @@ -78,8 +78,8 @@ impl CommandExecutor for SetblockExecutor { for x in start_x..=end_x { for y in start_y..=end_y { for z in start_z..=end_z { - let block_position = WorldPosition(Vector3 { x, y, z }); - world.set_block_state(block_position, block_state_id).await; + let block_position = BlockPos(Vector3 { x, y, z }); + world.set_block_state(&block_position, block_state_id).await; placed_blocks += 1; } } @@ -89,10 +89,10 @@ impl CommandExecutor for SetblockExecutor { for x in start_x..=end_x { for y in start_y..=end_y { for z in start_z..=end_z { - let block_position = WorldPosition(Vector3 { x, y, z }); - match world.get_block_state(block_position).await { + let block_position = BlockPos(Vector3 { x, y, z }); + match world.get_block_state(&block_position).await { Ok(old_state) if old_state.air => { - world.set_block_state(block_position, block_state_id).await; + world.set_block_state(&block_position, block_state_id).await; placed_blocks += 1; } _ => {} @@ -105,7 +105,7 @@ impl CommandExecutor for SetblockExecutor { for x in start_x..=end_x { for y in start_y..=end_y { for z in start_z..=end_z { - let block_position = WorldPosition(Vector3::new(x, y, z)); + let block_position = BlockPos(Vector3::new(x, y, z)); let is_edge = x == start_x || x == end_x || y == start_y @@ -113,9 +113,9 @@ impl CommandExecutor for SetblockExecutor { || z == start_z || z == end_z; if is_edge { - world.set_block_state(block_position, block_state_id).await; + world.set_block_state(&block_position, block_state_id).await; } else { - world.set_block_state(block_position, 0).await; + world.set_block_state(&block_position, 0).await; } placed_blocks += 1; } @@ -126,7 +126,7 @@ impl CommandExecutor for SetblockExecutor { for x in start_x..=end_x { for y in start_y..=end_y { for z in start_z..=end_z { - let block_position = WorldPosition(Vector3::new(x, y, z)); + let block_position = BlockPos(Vector3::new(x, y, z)); let is_edge = x == start_x || x == end_x || y == start_y @@ -134,7 +134,7 @@ impl CommandExecutor for SetblockExecutor { || z == start_z || z == end_z; if is_edge { - world.set_block_state(block_position, block_state_id).await; + world.set_block_state(&block_position, block_state_id).await; placed_blocks += 1; } } diff --git a/pumpkin/src/command/commands/cmd_setblock.rs b/pumpkin/src/command/commands/cmd_setblock.rs index af85af36..cf93abe2 100644 --- a/pumpkin/src/command/commands/cmd_setblock.rs +++ b/pumpkin/src/command/commands/cmd_setblock.rs @@ -47,17 +47,17 @@ impl CommandExecutor for SetblockExecutor { let success = match mode { Mode::Destroy => { - world.break_block(pos, None).await; - world.set_block_state(pos, block_state_id).await; + world.break_block(&pos, None).await; + world.set_block_state(&pos, block_state_id).await; true } Mode::Replace => { - world.set_block_state(pos, block_state_id).await; + world.set_block_state(&pos, block_state_id).await; true } - Mode::Keep => match world.get_block_state(pos).await { + Mode::Keep => match world.get_block_state(&pos).await { Ok(old_state) if old_state.air => { - world.set_block_state(pos, block_state_id).await; + world.set_block_state(&pos, block_state_id).await; true } Ok(_) => false, diff --git a/pumpkin/src/entity/ai/path/mod.rs b/pumpkin/src/entity/ai/path/mod.rs index 7804869d..f0c656c2 100644 --- a/pumpkin/src/entity/ai/path/mod.rs +++ b/pumpkin/src/entity/ai/path/mod.rs @@ -45,6 +45,7 @@ impl Navigator { goal.current_progress.y, goal.current_progress.z + z, ); + let node = Node::new(potential_pos); let cost = node.get_expense(goal.destination); diff --git a/pumpkin/src/entity/mob/mod.rs b/pumpkin/src/entity/mob/mod.rs index d10e6b2f..994cebf1 100644 --- a/pumpkin/src/entity/mob/mod.rs +++ b/pumpkin/src/entity/mob/mod.rs @@ -46,11 +46,14 @@ pub async fn from_type( position: Vector3, world: &Arc, ) -> (Arc, Uuid) { + let entity = server.add_mob_entity(entity_type, position, world).await; + #[expect(clippy::single_match)] match entity_type { - EntityType::Zombie => Zombie::make(server, position, world).await, + EntityType::Zombie => Zombie::make(&entity.0).await, // TODO - _ => server.add_mob_entity(entity_type, position, world).await, + _ => (), } + entity } impl MobEntity { diff --git a/pumpkin/src/entity/mob/zombie.rs b/pumpkin/src/entity/mob/zombie.rs index edb3cd0d..814860e3 100644 --- a/pumpkin/src/entity/mob/zombie.rs +++ b/pumpkin/src/entity/mob/zombie.rs @@ -1,30 +1,12 @@ -use std::sync::Arc; - -use pumpkin_data::entity::EntityType; -use pumpkin_util::math::vector3::Vector3; -use uuid::Uuid; - -use crate::{ - entity::ai::goal::{look_at_entity::LookAtEntityGoal, target_goal::TargetGoal}, - server::Server, - world::World, -}; +use crate::entity::ai::goal::{look_at_entity::LookAtEntityGoal, target_goal::TargetGoal}; use super::MobEntity; pub struct Zombie; impl Zombie { - pub async fn make( - server: &Server, - position: Vector3, - world: &Arc, - ) -> (Arc, Uuid) { - let (zombie_entity, uuid) = server - .add_mob_entity(EntityType::Zombie, position, world) - .await; - zombie_entity.goal(LookAtEntityGoal::new(8.0)).await; - zombie_entity.goal(TargetGoal::new(16.0)).await; - (zombie_entity, uuid) + pub async fn make(mob: &MobEntity) { + mob.goal(LookAtEntityGoal::new(8.0)).await; + mob.goal(TargetGoal::new(16.0)).await; } } diff --git a/pumpkin/src/entity/mod.rs b/pumpkin/src/entity/mod.rs index a46facac..7bd41595 100644 --- a/pumpkin/src/entity/mod.rs +++ b/pumpkin/src/entity/mod.rs @@ -10,7 +10,7 @@ use pumpkin_protocol::{ use pumpkin_util::math::{ boundingbox::{BoundingBox, BoundingBoxSize}, get_section_cord, - position::WorldPosition, + position::BlockPos, vector2::Vector2, vector3::Vector3, wrap_degrees, @@ -39,7 +39,7 @@ pub struct Entity { /// The entity's current position in the world pub pos: AtomicCell>, /// The entity's position rounded to the nearest block coordinates - pub block_pos: AtomicCell, + pub block_pos: AtomicCell, /// The chunk coordinates of the entity's current position pub chunk_pos: AtomicCell>, /// Indicates whether the entity is sneaking @@ -90,7 +90,7 @@ impl Entity { entity_type, on_ground: AtomicBool::new(false), pos: AtomicCell::new(position), - block_pos: AtomicCell::new(WorldPosition(Vector3::new(floor_x, floor_y, floor_z))), + block_pos: AtomicCell::new(BlockPos(Vector3::new(floor_x, floor_y, floor_z))), chunk_pos: AtomicCell::new(Vector2::new(floor_x, floor_z)), sneaking: AtomicBool::new(false), world, @@ -133,7 +133,7 @@ impl Entity { || floor_z != block_pos_vec.z { let new_block_pos = Vector3::new(floor_x, floor_y, floor_z); - self.block_pos.store(WorldPosition(new_block_pos)); + self.block_pos.store(BlockPos(new_block_pos)); let chunk_pos = self.chunk_pos.load(); if get_section_cord(floor_x) != chunk_pos.x diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index f7bbf1e4..1515de8c 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -41,7 +41,7 @@ use pumpkin_protocol::{ use pumpkin_util::{ math::{ boundingbox::{BoundingBox, BoundingBoxSize}, - position::WorldPosition, + position::BlockPos, vector2::Vector2, vector3::Vector3, }, @@ -533,7 +533,7 @@ impl Player { } } - pub fn can_interact_with_block_at(&self, pos: &WorldPosition, additional_range: f64) -> bool { + pub fn can_interact_with_block_at(&self, pos: &BlockPos, additional_range: f64) -> bool { let d = self.block_interaction_range() + additional_range; let box_pos = BoundingBox::from_block(pos); let entity_pos = self.living_entity.entity.pos.load(); diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 5e5dfe8b..f232cd54 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -85,30 +85,18 @@ fn init_logger() { logger = logger.without_timestamps(); } - logger = logger.with_level(convert_logger_filter(ADVANCED_CONFIG.logging.level)); + // default + logger = logger.with_level(LevelFilter::Info); logger = logger.with_colors(ADVANCED_CONFIG.logging.color); logger = logger.with_threads(ADVANCED_CONFIG.logging.threads); - if ADVANCED_CONFIG.logging.env { - logger = logger.env(); - } + logger = logger.env(); logger.init().unwrap(); } } -const fn convert_logger_filter(level: pumpkin_config::logging::LevelFilter) -> LevelFilter { - match level { - pumpkin_config::logging::LevelFilter::Off => LevelFilter::Off, - pumpkin_config::logging::LevelFilter::Error => LevelFilter::Error, - pumpkin_config::logging::LevelFilter::Warn => LevelFilter::Warn, - pumpkin_config::logging::LevelFilter::Info => LevelFilter::Info, - pumpkin_config::logging::LevelFilter::Debug => LevelFilter::Debug, - pumpkin_config::logging::LevelFilter::Trace => LevelFilter::Trace, - } -} - const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION"); const GIT_VERSION: &str = env!("GIT_VERSION"); diff --git a/pumpkin/src/net/packet/play.rs b/pumpkin/src/net/packet/play.rs index 0dba0406..3d47d6ca 100644 --- a/pumpkin/src/net/packet/play.rs +++ b/pumpkin/src/net/packet/play.rs @@ -35,7 +35,7 @@ use pumpkin_protocol::{ SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSwingArm, SUseItemOn, Status, }, }; -use pumpkin_util::math::{boundingbox::BoundingBox, position::WorldPosition}; +use pumpkin_util::math::{boundingbox::BoundingBox, position::BlockPos}; use pumpkin_util::{ math::{vector3::Vector3, wrap_degrees}, text::TextComponent, @@ -356,7 +356,7 @@ impl Player { return; } - let Ok(block) = self.world().get_block(pick_item.pos).await else { + let Ok(block) = self.world().get_block(&pick_item.pos).await else { return; }; @@ -736,9 +736,9 @@ impl Player { // Block break & block break sound let entity = &self.living_entity.entity; let world = &entity.world; - let block = world.get_block(location).await; + let block = world.get_block(&location).await; - world.break_block(location, Some(self)).await; + world.break_block(&location, Some(self)).await; if let Ok(block) = block { server @@ -774,9 +774,9 @@ impl Player { // Block break & block break sound let entity = &self.living_entity.entity; let world = &entity.world; - let block = world.get_block(location).await; + let block = world.get_block(&location).await; - world.break_block(location, Some(self)).await; + world.break_block(&location, Some(self)).await; if let Ok(block) = block { server @@ -861,7 +861,7 @@ impl Player { if let Some(item_stack) = item_slot { // check if block is interactive if let Some(item) = get_item_by_id(item_stack.item_id) { - if let Ok(block) = world.get_block(location).await { + if let Ok(block) = world.get_block(&location).await { let result = server .block_manager .on_use_with_item(block, self, location, item, server) @@ -1032,12 +1032,12 @@ impl Player { &self, item_t: String, server: &Server, - location: WorldPosition, + location: BlockPos, face: &BlockFace, ) -> Result> { // checks if spawn egg has a corresponding entity name if let Some(spawn_item_id) = get_entity_id(&item_t) { - let world_pos = WorldPosition(location.0 + face.to_offset()); + let world_pos = BlockPos(location.0 + face.to_offset()); // align position like Vanilla does let pos = Vector3::new( f64::from(world_pos.0.x) + 0.5, @@ -1088,20 +1088,20 @@ impl Player { block: Block, server: &Server, use_item_on: SUseItemOn, - location: WorldPosition, + location: BlockPos, face: &BlockFace, ) -> Result> { let entity = &self.living_entity.entity; let world = &entity.world; - let clicked_world_pos = WorldPosition(location.0); - let clicked_block_state = world.get_block_state(clicked_world_pos).await?; + let clicked_world_pos = BlockPos(location.0); + let clicked_block_state = world.get_block_state(&clicked_world_pos).await?; let world_pos = if clicked_block_state.replaceable { clicked_world_pos } else { - let world_pos = WorldPosition(location.0 + face.to_offset()); - let previous_block_state = world.get_block_state(world_pos).await?; + let world_pos = BlockPos(location.0 + face.to_offset()); + let previous_block_state = world.get_block_state(&world_pos).await?; if !previous_block_state.replaceable { return Ok(true); @@ -1128,7 +1128,7 @@ impl Player { } if !intersects { world - .set_block_state(world_pos, block.default_state_id) + .set_block_state(&world_pos, block.default_state_id) .await; server .block_manager diff --git a/pumpkin/src/server/mod.rs b/pumpkin/src/server/mod.rs index bf5e846c..bae6f9da 100644 --- a/pumpkin/src/server/mod.rs +++ b/pumpkin/src/server/mod.rs @@ -9,7 +9,7 @@ use pumpkin_protocol::client::login::CEncryptionRequest; use pumpkin_protocol::{client::config::CPluginMessage, ClientPacket}; use pumpkin_registry::{DimensionType, Registry}; use pumpkin_util::math::boundingbox::{BoundingBox, BoundingBoxSize}; -use pumpkin_util::math::position::WorldPosition; +use pumpkin_util::math::position::BlockPos; use pumpkin_util::math::vector2::Vector2; use pumpkin_util::math::vector3::Vector3; use pumpkin_util::GameMode; @@ -271,7 +271,7 @@ impl Server { /// Returns the first id with a matching location and block type. If this is used with unique /// blocks, the output will return a random result. - pub async fn get_container_id(&self, location: WorldPosition, block: Block) -> Option { + pub async fn get_container_id(&self, location: BlockPos, block: Block) -> Option { let open_containers = self.open_containers.read().await; // TODO: do better than brute force for (id, container) in open_containers.iter() { @@ -292,7 +292,7 @@ impl Server { pub async fn get_all_container_ids( &self, - location: WorldPosition, + location: BlockPos, block: Block, ) -> Option> { let open_containers = self.open_containers.read().await; diff --git a/pumpkin/src/world/mod.rs b/pumpkin/src/world/mod.rs index 00af5aee..432b9693 100644 --- a/pumpkin/src/world/mod.rs +++ b/pumpkin/src/world/mod.rs @@ -30,7 +30,7 @@ use pumpkin_protocol::{ }; use pumpkin_registry::DimensionType; use pumpkin_util::math::vector2::Vector2; -use pumpkin_util::math::{position::WorldPosition, vector3::Vector3}; +use pumpkin_util::math::{position::BlockPos, vector3::Vector3}; use pumpkin_util::text::{color::NamedColor, TextComponent}; use pumpkin_world::chunk::ChunkData; use pumpkin_world::level::Level; @@ -181,7 +181,7 @@ impl World { .await; } - pub async fn play_block_sound(&self, sound: Sound, position: WorldPosition) { + pub async fn play_block_sound(&self, sound: Sound, position: BlockPos) { let new_vec = Vector3::new( f64::from(position.0.x) + 0.5, f64::from(position.0.y) + 0.5, @@ -191,12 +191,12 @@ impl World { .await; } - pub async fn play_record(&self, record_id: i32, position: WorldPosition) { + pub async fn play_record(&self, record_id: i32, position: BlockPos) { self.broadcast_packet_all(&CLevelEvent::new(1010, position, record_id, false)) .await; } - pub async fn stop_record(&self, position: WorldPosition) { + pub async fn stop_record(&self, position: BlockPos) { self.broadcast_packet_all(&CLevelEvent::new(1011, position, 0, false)) .await; } @@ -223,8 +223,8 @@ impl World { /// Gets the y position of the first non air block from the top down pub async fn get_top_block(&self, position: Vector2) -> i32 { for y in (-64..=319).rev() { - let pos = WorldPosition(Vector3::new(position.x, y, position.z)); - let block = self.get_block_state(pos).await; + let pos = BlockPos(Vector3::new(position.x, y, position.z)); + let block = self.get_block_state(&pos).await; if let Ok(block) = block { if block.air { continue; @@ -441,7 +441,7 @@ impl World { pub async fn respawn_player(&self, player: &Arc, alive: bool) { let last_pos = player.living_entity.last_pos.load(); let death_dimension = player.world().dimension_type.name(); - let death_location = WorldPosition(Vector3::new( + let death_location = BlockPos(Vector3::new( last_pos.x.round() as i32, last_pos.y.round() as i32, last_pos.z.round() as i32, @@ -663,10 +663,7 @@ impl World { /// # Arguments /// /// * `position`: The position the function will check. - pub async fn get_players_by_pos( - &self, - position: WorldPosition, - ) -> HashMap> { + pub async fn get_players_by_pos(&self, position: BlockPos) -> HashMap> { self.current_players .lock() .await @@ -828,7 +825,7 @@ impl World { } /// Sets a block - pub async fn set_block_state(&self, position: WorldPosition, block_state_id: u16) -> u16 { + pub async fn set_block_state(&self, position: &BlockPos, block_state_id: u16) -> u16 { let (chunk_coordinate, relative_coordinates) = position.chunk_and_chunk_relative_position(); // Since we divide by 16 remnant can never exceed u8 @@ -843,7 +840,7 @@ impl World { .set_block(relative, block_state_id); self.broadcast_packet_all(&CBlockUpdate::new( - &position, + position, i32::from(block_state_id).into(), )) .await; @@ -883,12 +880,12 @@ impl World { chunk } - pub async fn break_block(&self, position: WorldPosition, cause: Option<&Player>) { + pub async fn break_block(&self, position: &BlockPos, cause: Option<&Player>) { let broken_block_state_id = self.set_block_state(position, 0).await; let particles_packet = CWorldEvent::new( WorldEvent::BlockBroken as i32, - &position, + position, broken_block_state_id.into(), false, ); @@ -902,7 +899,7 @@ impl World { } } - pub async fn get_block_state_id(&self, position: WorldPosition) -> Result { + pub async fn get_block_state_id(&self, position: &BlockPos) -> Result { let (chunk, relative) = position.chunk_and_chunk_relative_position(); let relative = ChunkRelativeBlockCoordinates::from(relative); let chunk = self.receive_chunk(chunk).await; @@ -918,7 +915,7 @@ impl World { /// Gets the Block from the Block Registry, Returns None if the Block has not been found pub async fn get_block( &self, - position: WorldPosition, + position: &BlockPos, ) -> Result<&pumpkin_world::block::block_registry::Block, GetBlockError> { let id = self.get_block_state_id(position).await?; get_block_by_state_id(id).ok_or(GetBlockError::InvalidBlockId) @@ -927,7 +924,7 @@ impl World { /// Gets the Block state from the Block Registry, Returns None if the Block state has not been found pub async fn get_block_state( &self, - position: WorldPosition, + position: &BlockPos, ) -> Result<&pumpkin_world::block::block_registry::State, GetBlockError> { let id = self.get_block_state_id(position).await?; get_state_by_state_id(id).ok_or(GetBlockError::InvalidBlockId) @@ -936,7 +933,7 @@ impl World { /// Gets the Block + Block state from the Block Registry, Returns None if the Block state has not been found pub async fn get_block_and_block_state( &self, - position: WorldPosition, + position: &BlockPos, ) -> Result< ( &pumpkin_world::block::block_registry::Block, diff --git a/pumpkin/src/world/player_chunker.rs b/pumpkin/src/world/player_chunker.rs index 48cd326b..de7e3385 100644 --- a/pumpkin/src/world/player_chunker.rs +++ b/pumpkin/src/world/player_chunker.rs @@ -3,7 +3,7 @@ use std::{num::NonZeroU8, sync::Arc}; use pumpkin_config::BASIC_CONFIG; use pumpkin_protocol::client::play::{CCenterChunk, CUnloadChunk}; use pumpkin_util::{ - math::{get_section_cord, position::WorldPosition, vector3::Vector3}, + math::{get_section_cord, position::BlockPos, vector3::Vector3}, GameMode, }; use pumpkin_world::cylindrical_chunk_iterator::Cylindrical; @@ -111,7 +111,7 @@ pub async fn update_position(player: &Arc) { } #[must_use] -pub const fn chunk_section_from_pos(block_pos: &WorldPosition) -> Vector3 { +pub const fn chunk_section_from_pos(block_pos: &BlockPos) -> Vector3 { let block_pos = block_pos.0; Vector3::new( get_section_cord(block_pos.x),