rename WorldPosition

This commit is contained in:
Alexander Medvedev 2025-01-12 16:45:22 +01:00
parent 6415f697e5
commit 23dbb72bbe
41 changed files with 229 additions and 217 deletions

View File

@ -57,6 +57,8 @@ and customizable experience. It prioritizes performance and player enjoyment whi
- [x] Scoreboard - [x] Scoreboard
- [x] World Borders - [x] World Borders
- [x] World Saving - [x] World Saving
- [ ] Redstone
- [ ] Liquid Physics
- Player - Player
- [x] Player Skins - [x] Player Skins
- [x] Player Client brand - [x] Player Client brand

View File

@ -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,
}

View File

@ -1,3 +1,4 @@
use chunk::ChunkConfig;
use log::warn; use log::warn;
use logging::LoggingConfig; use logging::LoggingConfig;
use pumpkin_util::{Difficulty, GameMode, PermissionLvl}; use pumpkin_util::{Difficulty, GameMode, PermissionLvl};
@ -26,6 +27,7 @@ pub use server_links::ServerLinksConfig;
mod commands; mod commands;
pub mod chunk;
pub mod op; pub mod op;
mod pvp; mod pvp;
mod server_links; mod server_links;
@ -50,6 +52,7 @@ pub static BASIC_CONFIG: LazyLock<BasicConfiguration> = LazyLock::new(BasicConfi
pub struct AdvancedConfiguration { pub struct AdvancedConfiguration {
pub logging: LoggingConfig, pub logging: LoggingConfig,
pub resource_pack: ResourcePackConfig, pub resource_pack: ResourcePackConfig,
pub chunk: ChunkConfig,
pub networking: NetworkingConfig, pub networking: NetworkingConfig,
pub commands: CommandsConfig, pub commands: CommandsConfig,
pub pvp: PVPConfig, pub pvp: PVPConfig,

View File

@ -4,8 +4,6 @@ use serde::{Deserialize, Serialize};
#[serde(default)] #[serde(default)]
pub struct LoggingConfig { pub struct LoggingConfig {
pub enabled: bool, pub enabled: bool,
pub level: LevelFilter,
pub env: bool,
pub threads: bool, pub threads: bool,
pub color: bool, pub color: bool,
pub timestamp: bool, pub timestamp: bool,
@ -15,24 +13,9 @@ impl Default for LoggingConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {
enabled: true, enabled: true,
level: Default::default(),
env: false,
threads: true, threads: true,
color: true, color: true,
timestamp: 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,
}

View File

@ -1,7 +1,7 @@
use crate::crafting::check_if_matches_crafting; use crate::crafting::check_if_matches_crafting;
use crate::Container; use crate::Container;
use pumpkin_data::screen::WindowType; 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::block::block_registry::Block;
use pumpkin_world::item::ItemStack; use pumpkin_world::item::ItemStack;
use std::sync::Arc; use std::sync::Arc;
@ -12,7 +12,7 @@ pub struct OpenContainer {
// TODO: should this be uuid? // TODO: should this be uuid?
players: Vec<i32>, players: Vec<i32>,
container: Arc<Mutex<Box<dyn Container>>>, container: Arc<Mutex<Box<dyn Container>>>,
location: Option<WorldPosition>, location: Option<BlockPos>,
block: Option<Block>, block: Option<Block>,
} }
@ -46,7 +46,7 @@ impl OpenContainer {
pub fn new_empty_container<C: Container + Default + 'static>( pub fn new_empty_container<C: Container + Default + 'static>(
player_id: i32, player_id: i32,
location: Option<WorldPosition>, location: Option<BlockPos>,
block: Option<Block>, block: Option<Block>,
) -> Self { ) -> Self {
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 { if let Some(location) = self.location {
location == try_position location == try_position
} else { } else {
@ -81,11 +81,11 @@ impl OpenContainer {
self.players.len() self.players.len()
} }
pub fn get_location(&self) -> Option<WorldPosition> { pub fn get_location(&self) -> Option<BlockPos> {
self.location self.location
} }
pub async fn set_location(&mut self, location: Option<WorldPosition>) { pub async fn set_location(&mut self, location: Option<BlockPos>) {
self.location = location; self.location = location;
} }

View File

@ -1,5 +1,5 @@
use pumpkin_data::packet::clientbound::PLAY_BLOCK_DESTRUCTION; 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 pumpkin_macros::client_packet;
use serde::Serialize; use serde::Serialize;
@ -10,12 +10,12 @@ use crate::VarInt;
#[client_packet(PLAY_BLOCK_DESTRUCTION)] #[client_packet(PLAY_BLOCK_DESTRUCTION)]
pub struct CSetBlockDestroyStage { pub struct CSetBlockDestroyStage {
entity_id: VarInt, entity_id: VarInt,
location: WorldPosition, location: BlockPos,
destroy_stage: u8, destroy_stage: u8,
} }
impl CSetBlockDestroyStage { 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 { Self {
entity_id, entity_id,
location, location,

View File

@ -1,5 +1,5 @@
use pumpkin_data::packet::clientbound::PLAY_BLOCK_EVENT; 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 pumpkin_macros::client_packet;
use serde::Serialize; use serde::Serialize;
@ -9,7 +9,7 @@ use crate::VarInt;
#[derive(Serialize)] #[derive(Serialize)]
#[client_packet(PLAY_BLOCK_EVENT)] #[client_packet(PLAY_BLOCK_EVENT)]
pub struct CBlockAction<'a> { pub struct CBlockAction<'a> {
location: &'a WorldPosition, location: &'a BlockPos,
action_id: u8, action_id: u8,
action_parameter: u8, action_parameter: u8,
block_type: VarInt, block_type: VarInt,
@ -17,7 +17,7 @@ pub struct CBlockAction<'a> {
impl<'a> CBlockAction<'a> { impl<'a> CBlockAction<'a> {
pub fn new( pub fn new(
location: &'a WorldPosition, location: &'a BlockPos,
action_id: u8, action_id: u8,
action_parameter: u8, action_parameter: u8,
block_type: VarInt, block_type: VarInt,

View File

@ -1,5 +1,5 @@
use pumpkin_data::packet::clientbound::PLAY_BLOCK_UPDATE; 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 pumpkin_macros::client_packet;
use serde::Serialize; use serde::Serialize;
@ -9,12 +9,12 @@ use crate::VarInt;
#[derive(Serialize)] #[derive(Serialize)]
#[client_packet(PLAY_BLOCK_UPDATE)] #[client_packet(PLAY_BLOCK_UPDATE)]
pub struct CBlockUpdate<'a> { pub struct CBlockUpdate<'a> {
location: &'a WorldPosition, location: &'a BlockPos,
block_id: VarInt, block_id: VarInt,
} }
impl<'a> CBlockUpdate<'a> { 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 } Self { location, block_id }
} }
} }

View File

@ -1,24 +1,19 @@
use pumpkin_data::packet::clientbound::PLAY_LEVEL_EVENT; use pumpkin_data::packet::clientbound::PLAY_LEVEL_EVENT;
use pumpkin_macros::client_packet; use pumpkin_macros::client_packet;
use pumpkin_util::math::position::WorldPosition; use pumpkin_util::math::position::BlockPos;
use serde::Serialize; use serde::Serialize;
#[derive(Serialize)] #[derive(Serialize)]
#[client_packet(PLAY_LEVEL_EVENT)] #[client_packet(PLAY_LEVEL_EVENT)]
pub struct CLevelEvent { pub struct CLevelEvent {
event: i32, event: i32,
location: WorldPosition, location: BlockPos,
data: i32, data: i32,
disable_relative_volume: bool, disable_relative_volume: bool,
} }
impl CLevelEvent { impl CLevelEvent {
pub fn new( pub fn new(event: i32, location: BlockPos, data: i32, disable_relative_volume: bool) -> Self {
event: i32,
location: WorldPosition,
data: i32,
disable_relative_volume: bool,
) -> Self {
Self { Self {
event, event,
location, location,

View File

@ -1,5 +1,5 @@
use pumpkin_data::packet::clientbound::PLAY_LOGIN; 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 pumpkin_macros::client_packet;
use serde::Serialize; use serde::Serialize;
@ -27,7 +27,7 @@ pub struct CLogin<'a> {
previous_gamemode: i8, previous_gamemode: i8,
debug: bool, debug: bool,
is_flat: bool, is_flat: bool,
death_dimension_name: Option<(Identifier, WorldPosition)>, death_dimension_name: Option<(Identifier, BlockPos)>,
portal_cooldown: VarInt, portal_cooldown: VarInt,
sealevel: VarInt, sealevel: VarInt,
enforce_secure_chat: bool, enforce_secure_chat: bool,
@ -52,7 +52,7 @@ impl<'a> CLogin<'a> {
previous_gamemode: i8, previous_gamemode: i8,
debug: bool, debug: bool,
is_flat: bool, is_flat: bool,
death_dimension_name: Option<(Identifier, WorldPosition)>, death_dimension_name: Option<(Identifier, BlockPos)>,
portal_cooldown: VarInt, portal_cooldown: VarInt,
sealevel: VarInt, sealevel: VarInt,
enforce_secure_chat: bool, enforce_secure_chat: bool,

View File

@ -1,6 +1,6 @@
use pumpkin_data::packet::clientbound::PLAY_RESPAWN; use pumpkin_data::packet::clientbound::PLAY_RESPAWN;
use pumpkin_macros::client_packet; use pumpkin_macros::client_packet;
use pumpkin_util::math::position::WorldPosition; use pumpkin_util::math::position::BlockPos;
use serde::Serialize; use serde::Serialize;
use crate::{codec::identifier::Identifier, VarInt}; use crate::{codec::identifier::Identifier, VarInt};
@ -15,7 +15,7 @@ pub struct CRespawn {
previous_gamemode: i8, previous_gamemode: i8,
debug: bool, debug: bool,
is_flat: bool, is_flat: bool,
death_dimension_name: Option<(Identifier, WorldPosition)>, death_dimension_name: Option<(Identifier, BlockPos)>,
portal_cooldown: VarInt, portal_cooldown: VarInt,
sealevel: VarInt, sealevel: VarInt,
data_kept: u8, data_kept: u8,
@ -31,7 +31,7 @@ impl CRespawn {
previous_gamemode: i8, previous_gamemode: i8,
debug: bool, debug: bool,
is_flat: bool, is_flat: bool,
death_dimension_name: Option<(Identifier, WorldPosition)>, death_dimension_name: Option<(Identifier, BlockPos)>,
portal_cooldown: VarInt, portal_cooldown: VarInt,
sealevel: VarInt, sealevel: VarInt,
data_kept: u8, data_kept: u8,

View File

@ -1,5 +1,5 @@
use pumpkin_data::packet::clientbound::PLAY_LEVEL_EVENT; 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 pumpkin_macros::client_packet;
use serde::Serialize; use serde::Serialize;
@ -8,7 +8,7 @@ use serde::Serialize;
#[client_packet(PLAY_LEVEL_EVENT)] #[client_packet(PLAY_LEVEL_EVENT)]
pub struct CWorldEvent<'a> { pub struct CWorldEvent<'a> {
event: i32, event: i32,
location: &'a WorldPosition, location: &'a BlockPos,
data: i32, data: i32,
disable_relative_volume: bool, disable_relative_volume: bool,
} }
@ -16,7 +16,7 @@ pub struct CWorldEvent<'a> {
impl<'a> CWorldEvent<'a> { impl<'a> CWorldEvent<'a> {
pub fn new( pub fn new(
event: i32, event: i32,
location: &'a WorldPosition, location: &'a BlockPos,
data: i32, data: i32,
disable_relative_volume: bool, disable_relative_volume: bool,
) -> Self { ) -> Self {

View File

@ -1,12 +1,12 @@
use pumpkin_data::packet::serverbound::{PLAY_PICK_ITEM_FROM_BLOCK, PLAY_PICK_ITEM_FROM_ENTITY}; use pumpkin_data::packet::serverbound::{PLAY_PICK_ITEM_FROM_BLOCK, PLAY_PICK_ITEM_FROM_ENTITY};
use pumpkin_macros::server_packet; use pumpkin_macros::server_packet;
use pumpkin_util::math::position::WorldPosition; use pumpkin_util::math::position::BlockPos;
use serde::Deserialize; use serde::Deserialize;
#[derive(Deserialize)] #[derive(Deserialize)]
#[server_packet(PLAY_PICK_ITEM_FROM_BLOCK)] #[server_packet(PLAY_PICK_ITEM_FROM_BLOCK)]
pub struct SPickItemFromBlock { pub struct SPickItemFromBlock {
pub pos: WorldPosition, pub pos: BlockPos,
pub include_data: bool, pub include_data: bool,
} }

View File

@ -1,6 +1,6 @@
use pumpkin_data::packet::serverbound::PLAY_PLAYER_ACTION; use pumpkin_data::packet::serverbound::PLAY_PLAYER_ACTION;
use pumpkin_macros::server_packet; use pumpkin_macros::server_packet;
use pumpkin_util::math::position::WorldPosition; use pumpkin_util::math::position::BlockPos;
use crate::VarInt; use crate::VarInt;
@ -8,7 +8,7 @@ use crate::VarInt;
#[server_packet(PLAY_PLAYER_ACTION)] #[server_packet(PLAY_PLAYER_ACTION)]
pub struct SPlayerAction { pub struct SPlayerAction {
pub status: VarInt, pub status: VarInt,
pub location: WorldPosition, pub location: BlockPos,
pub face: u8, pub face: u8,
pub sequence: VarInt, pub sequence: VarInt,
} }

View File

@ -1,6 +1,6 @@
use pumpkin_data::packet::serverbound::PLAY_USE_ITEM_ON; use pumpkin_data::packet::serverbound::PLAY_USE_ITEM_ON;
use pumpkin_macros::server_packet; 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 serde::Deserialize;
use crate::VarInt; use crate::VarInt;
@ -9,7 +9,7 @@ use crate::VarInt;
#[server_packet(PLAY_USE_ITEM_ON)] #[server_packet(PLAY_USE_ITEM_ON)]
pub struct SUseItemOn { pub struct SUseItemOn {
pub hand: VarInt, pub hand: VarInt,
pub location: WorldPosition, pub location: BlockPos,
pub face: VarInt, pub face: VarInt,
pub cursor_pos: Vector3<f32>, pub cursor_pos: Vector3<f32>,
pub inside_block: bool, pub inside_block: bool,

View File

@ -1,4 +1,4 @@
use super::{position::WorldPosition, vector3::Vector3}; use super::{position::BlockPos, vector3::Vector3};
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub struct BoundingBox { 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; let position = position.0;
Self { Self {
min_x: position.x as f64, min_x: position.x as f64,

View File

@ -7,9 +7,9 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
/// Aka Block Position /// Aka Block Position
pub struct WorldPosition(pub Vector3<i32>); pub struct BlockPos(pub Vector3<i32>);
impl WorldPosition { impl BlockPos {
pub fn chunk_and_chunk_relative_position(&self) -> (Vector2<i32>, Vector3<i32>) { pub fn chunk_and_chunk_relative_position(&self) -> (Vector2<i32>, Vector3<i32>) {
let (z_chunk, z_rem) = self.0.z.div_rem_euclid(&16); let (z_chunk, z_rem) = self.0.z.div_rem_euclid(&16);
let (x_chunk, x_rem) = self.0.x.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) (chunk_coordinate, relative)
} }
} }
impl Serialize for WorldPosition { impl Serialize for BlockPos {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where
S: serde::Serializer, 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<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where where
D: serde::Deserializer<'de>, D: serde::Deserializer<'de>,
{ {
struct Visitor; struct Visitor;
impl serde::de::Visitor<'_> for Visitor { impl serde::de::Visitor<'_> for Visitor {
type Value = WorldPosition; type Value = BlockPos;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("An i64 int") formatter.write_str("An i64 int")
} }
@ -55,7 +55,7 @@ impl<'de> Deserialize<'de> for WorldPosition {
where where
E: serde::de::Error, E: serde::de::Error,
{ {
Ok(WorldPosition(Vector3 { Ok(BlockPos(Vector3 {
x: (v >> 38) as i32, x: (v >> 38) as i32,
y: (v << 52 >> 52) as i32, y: (v << 52 >> 52) as i32,
z: (v << 26 >> 38) 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 { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}, {}, {}", self.0.x, self.0.y, self.0.z) write!(f, "{}, {}, {}", self.0.x, self.0.y, self.0.z)
} }

View File

@ -2,6 +2,7 @@ use bytes::*;
use fastnbt::LongArray; use fastnbt::LongArray;
use flate2::bufread::{GzDecoder, GzEncoder, ZlibDecoder, ZlibEncoder}; use flate2::bufread::{GzDecoder, GzEncoder, ZlibDecoder, ZlibEncoder};
use indexmap::IndexMap; use indexmap::IndexMap;
use pumpkin_config::ADVANCED_CONFIG;
use pumpkin_util::math::ceil_log2; use pumpkin_util::math::ceil_log2;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use std::{ use std::{
@ -38,6 +39,18 @@ pub enum Compression {
Custom = 127, Custom = 127,
} }
impl From<pumpkin_config::chunk::Compression> 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 { impl Compression {
/// Returns Ok when a compression is found otherwise an Err /// Returns Ok when a compression is found otherwise an Err
#[allow(clippy::result_unit_err)] #[allow(clippy::result_unit_err)]
@ -241,9 +254,17 @@ impl ChunkWriter for AnvilChunkFormat {
.map_err(|err| ChunkWritingError::ChunkSerializingError(err.to_string()))?; .map_err(|err| ChunkWritingError::ChunkSerializingError(err.to_string()))?;
// Compress chunk data // Compress chunk data
let compression = Compression::ZLib; let compression: Compression = ADVANCED_CONFIG
.chunk
.compression
.compression_algorithm
.clone()
.into();
let compressed_data = compression let compressed_data = compression
.compress_data(&raw_bytes, 6) .compress_data(
&raw_bytes,
ADVANCED_CONFIG.chunk.compression.compression_level,
)
.map_err(ChunkWritingError::Compression)?; .map_err(ChunkWritingError::Compression)?;
// Length of compressed data + compression type // Length of compressed data + compression type

View File

@ -14,13 +14,13 @@ use serde::{Deserialize, Serialize};
pub struct Height(pub i16); pub struct Height(pub i16);
impl Height { impl Height {
pub fn from_absolute(height: u16) -> Self { pub const fn from_absolute(height: u16) -> Self {
(height as i16 - WORLD_LOWEST_Y.abs()).into() Self(height as i16 - WORLD_LOWEST_Y.abs())
} }
/// Absolute height ranges from `0..WORLD_HEIGHT` /// Absolute height ranges from `0..WORLD_HEIGHT`
/// instead of `WORLD_LOWEST_Y..WORLD_MAX_Y` /// 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 (self.0 + WORLD_LOWEST_Y.abs()) as u16
} }
} }

View File

@ -61,7 +61,7 @@ impl Cylindrical {
let min_leg = rel_x.min(rel_z) as i64; let min_leg = rel_x.min(rel_z) as i64;
let hyp_sqr = max_leg * max_leg + min_leg * min_leg; 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 /// Returns an iterator of all chunks within this cylinder

View File

@ -2,7 +2,7 @@ use crate::block::pumpkin_block::{BlockMetadata, PumpkinBlock};
use crate::entity::player::Player; use crate::entity::player::Player;
use crate::server::Server; use crate::server::Server;
use pumpkin_inventory::OpenContainer; 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::block::block_registry::Block;
use pumpkin_world::item::item_registry::Item; use pumpkin_world::item::item_registry::Item;
use std::collections::HashMap; use std::collections::HashMap;
@ -29,7 +29,7 @@ impl BlockManager {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
) { ) {
let pumpkin_block = self.get_pumpkin_block(block); let pumpkin_block = self.get_pumpkin_block(block);
@ -42,7 +42,7 @@ impl BlockManager {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
item: &Item, item: &Item,
server: &Server, server: &Server,
) -> BlockActionResult { ) -> BlockActionResult {
@ -59,7 +59,7 @@ impl BlockManager {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
) { ) {
let pumpkin_block = self.get_pumpkin_block(block); let pumpkin_block = self.get_pumpkin_block(block);
@ -74,7 +74,7 @@ impl BlockManager {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
) { ) {
let pumpkin_block = self.get_pumpkin_block(block); let pumpkin_block = self.get_pumpkin_block(block);
@ -89,7 +89,7 @@ impl BlockManager {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
container: &mut OpenContainer, container: &mut OpenContainer,
) { ) {

View File

@ -3,7 +3,7 @@ use pumpkin_data::{screen::WindowType, sound::Sound};
use pumpkin_inventory::{Chest, OpenContainer}; use pumpkin_inventory::{Chest, OpenContainer};
use pumpkin_macros::pumpkin_block; use pumpkin_macros::pumpkin_block;
use pumpkin_protocol::{client::play::CBlockAction, codec::var_int::VarInt}; 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::{ use pumpkin_world::{
block::block_registry::{get_block, Block}, block::block_registry::{get_block, Block},
item::item_registry::Item, item::item_registry::Item,
@ -30,7 +30,7 @@ impl PumpkinBlock for ChestBlock {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
_location: WorldPosition, _location: BlockPos,
server: &Server, server: &Server,
) { ) {
self.open_chest_block(block, player, _location, server) self.open_chest_block(block, player, _location, server)
@ -41,7 +41,7 @@ impl PumpkinBlock for ChestBlock {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
_location: WorldPosition, _location: BlockPos,
_item: &Item, _item: &Item,
server: &Server, server: &Server,
) -> BlockActionResult { ) -> BlockActionResult {
@ -54,7 +54,7 @@ impl PumpkinBlock for ChestBlock {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
) { ) {
super::standard_on_broken_with_container(block, player, location, server).await; super::standard_on_broken_with_container(block, player, location, server).await;
@ -64,7 +64,7 @@ impl PumpkinBlock for ChestBlock {
&self, &self,
_block: &Block, _block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
container: &mut OpenContainer, container: &mut OpenContainer,
) { ) {
@ -80,7 +80,7 @@ impl ChestBlock {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
) { ) {
// TODO: shouldn't Chest and window type be constrained together to avoid errors? // TODO: shouldn't Chest and window type be constrained together to avoid errors?
@ -106,7 +106,7 @@ impl ChestBlock {
&self, &self,
container: &OpenContainer, container: &OpenContainer,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
state: ChestState, state: ChestState,
) { ) {

View File

@ -6,7 +6,7 @@ use async_trait::async_trait;
use pumpkin_data::screen::WindowType; use pumpkin_data::screen::WindowType;
use pumpkin_inventory::{CraftingTable, OpenContainer}; use pumpkin_inventory::{CraftingTable, OpenContainer};
use pumpkin_macros::pumpkin_block; 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}; use pumpkin_world::{block::block_registry::Block, item::item_registry::Item};
#[pumpkin_block("minecraft:crafting_table")] #[pumpkin_block("minecraft:crafting_table")]
@ -18,7 +18,7 @@ impl PumpkinBlock for CraftingTableBlock {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
_location: WorldPosition, _location: BlockPos,
server: &Server, server: &Server,
) { ) {
self.open_crafting_screen(block, player, _location, server) self.open_crafting_screen(block, player, _location, server)
@ -29,7 +29,7 @@ impl PumpkinBlock for CraftingTableBlock {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
_location: WorldPosition, _location: BlockPos,
_item: &Item, _item: &Item,
server: &Server, server: &Server,
) -> BlockActionResult { ) -> BlockActionResult {
@ -42,7 +42,7 @@ impl PumpkinBlock for CraftingTableBlock {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
) { ) {
super::standard_on_broken_with_container(block, player, location, server).await; super::standard_on_broken_with_container(block, player, location, server).await;
@ -52,7 +52,7 @@ impl PumpkinBlock for CraftingTableBlock {
&self, &self,
_block: &Block, _block: &Block,
player: &Player, player: &Player,
_location: WorldPosition, _location: BlockPos,
_server: &Server, _server: &Server,
container: &mut OpenContainer, container: &mut OpenContainer,
) { ) {
@ -76,7 +76,7 @@ impl CraftingTableBlock {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
) { ) {
super::standard_open_container_unique::<CraftingTable>( super::standard_open_container_unique::<CraftingTable>(

View File

@ -4,7 +4,7 @@ use async_trait::async_trait;
use pumpkin_data::screen::WindowType; use pumpkin_data::screen::WindowType;
use pumpkin_inventory::Furnace; use pumpkin_inventory::Furnace;
use pumpkin_macros::pumpkin_block; 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::block::block_registry::Block;
use pumpkin_world::item::item_registry::Item; use pumpkin_world::item::item_registry::Item;
@ -19,7 +19,7 @@ impl PumpkinBlock for FurnaceBlock {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
_location: WorldPosition, _location: BlockPos,
server: &Server, server: &Server,
) { ) {
self.open_furnace_screen(block, player, _location, server) self.open_furnace_screen(block, player, _location, server)
@ -30,7 +30,7 @@ impl PumpkinBlock for FurnaceBlock {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
_location: WorldPosition, _location: BlockPos,
_item: &Item, _item: &Item,
server: &Server, server: &Server,
) -> BlockActionResult { ) -> BlockActionResult {
@ -43,7 +43,7 @@ impl PumpkinBlock for FurnaceBlock {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
) { ) {
super::standard_on_broken_with_container(block, player, location, server).await; super::standard_on_broken_with_container(block, player, location, server).await;
@ -55,7 +55,7 @@ impl FurnaceBlock {
&self, &self,
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
) { ) {
super::standard_open_container::<Furnace>( super::standard_open_container::<Furnace>(

View File

@ -5,7 +5,7 @@ use crate::server::Server;
use async_trait::async_trait; use async_trait::async_trait;
use pumpkin_macros::pumpkin_block; use pumpkin_macros::pumpkin_block;
use pumpkin_registry::SYNCED_REGISTRIES; 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::block::block_registry::Block;
use pumpkin_world::item::item_registry::Item; use pumpkin_world::item::item_registry::Item;
@ -18,7 +18,7 @@ impl PumpkinBlock for JukeboxBlock {
&self, &self,
_block: &Block, _block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
_server: &Server, _server: &Server,
) { ) {
// For now just stop the music at this position // For now just stop the music at this position
@ -31,7 +31,7 @@ impl PumpkinBlock for JukeboxBlock {
&self, &self,
_block: &Block, _block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
item: &Item, item: &Item,
_server: &Server, _server: &Server,
) -> BlockActionResult { ) -> BlockActionResult {
@ -61,7 +61,7 @@ impl PumpkinBlock for JukeboxBlock {
&self, &self,
_block: &Block, _block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
_server: &Server, _server: &Server,
) { ) {
// For now just stop the music at this position // For now just stop the music at this position

View File

@ -1,6 +1,6 @@
use pumpkin_data::screen::WindowType; use pumpkin_data::screen::WindowType;
use pumpkin_inventory::{Container, OpenContainer}; 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 pumpkin_world::block::block_registry::Block;
use crate::{entity::player::Player, server::Server}; use crate::{entity::player::Player, server::Server};
@ -15,7 +15,7 @@ pub(crate) mod jukebox;
pub async fn standard_on_broken_with_container( pub async fn standard_on_broken_with_container(
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
) { ) {
// TODO: drop all items and back to players inventory if in motion // 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<C: Container + Default + 'static>( pub async fn standard_open_container<C: Container + Default + 'static>(
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
window_type: WindowType, window_type: WindowType,
) { ) {
@ -66,7 +66,7 @@ pub async fn standard_open_container<C: Container + Default + 'static>(
pub async fn standard_open_container_unique<C: Container + Default + 'static>( pub async fn standard_open_container_unique<C: Container + Default + 'static>(
block: &Block, block: &Block,
player: &Player, player: &Player,
location: WorldPosition, location: BlockPos,
server: &Server, server: &Server,
window_type: WindowType, window_type: WindowType,
) { ) {

View File

@ -3,7 +3,7 @@ use crate::entity::player::Player;
use crate::server::Server; use crate::server::Server;
use async_trait::async_trait; use async_trait::async_trait;
use pumpkin_inventory::OpenContainer; 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::block::block_registry::Block;
use pumpkin_world::item::item_registry::Item; use pumpkin_world::item::item_registry::Item;
@ -21,7 +21,7 @@ pub trait PumpkinBlock: Send + Sync {
&self, &self,
_block: &Block, _block: &Block,
_player: &Player, _player: &Player,
_location: WorldPosition, _location: BlockPos,
_server: &Server, _server: &Server,
) { ) {
} }
@ -29,7 +29,7 @@ pub trait PumpkinBlock: Send + Sync {
&self, &self,
_block: &Block, _block: &Block,
_player: &Player, _player: &Player,
_location: WorldPosition, _location: BlockPos,
_item: &Item, _item: &Item,
_server: &Server, _server: &Server,
) -> BlockActionResult { ) -> BlockActionResult {
@ -40,7 +40,7 @@ pub trait PumpkinBlock: Send + Sync {
&self, &self,
_block: &Block, _block: &Block,
_player: &Player, _player: &Player,
_location: WorldPosition, _location: BlockPos,
_server: &Server, _server: &Server,
) { ) {
} }
@ -49,7 +49,7 @@ pub trait PumpkinBlock: Send + Sync {
&self, &self,
_block: &Block, _block: &Block,
_player: &Player, _player: &Player,
_location: WorldPosition, _location: BlockPos,
_server: &Server, _server: &Server,
) { ) {
} }
@ -58,7 +58,7 @@ pub trait PumpkinBlock: Send + Sync {
&self, &self,
_block: &Block, _block: &Block,
_player: &Player, _player: &Player,
_location: WorldPosition, _location: BlockPos,
_server: &Server, _server: &Server,
_container: &mut OpenContainer, _container: &mut OpenContainer,
) { ) {

View File

@ -2,7 +2,7 @@ use async_trait::async_trait;
use pumpkin_protocol::client::play::{ use pumpkin_protocol::client::play::{
CommandSuggestion, ProtoCmdArgParser, ProtoCmdArgSuggestionType, CommandSuggestion, ProtoCmdArgParser, ProtoCmdArgSuggestionType,
}; };
use pumpkin_util::math::position::WorldPosition; use pumpkin_util::math::position::BlockPos;
use pumpkin_util::math::vector3::Vector3; use pumpkin_util::math::vector3::Vector3;
use crate::command::dispatcher::CommandError; use crate::command::dispatcher::CommandError;
@ -67,8 +67,8 @@ impl MaybeRelativeBlockPos {
)) ))
} }
fn try_to_absolute(self, origin: Option<Vector3<f64>>) -> Option<WorldPosition> { fn try_to_absolute(self, origin: Option<Vector3<f64>>) -> Option<BlockPos> {
Some(WorldPosition(Vector3::new( Some(BlockPos(Vector3::new(
self.0.into_absolute(origin.map(|o| o.x))?, self.0.into_absolute(origin.map(|o| o.x))?,
self.1.into_absolute(origin.map(|o| o.y))?, self.1.into_absolute(origin.map(|o| o.y))?,
self.2.into_absolute(origin.map(|o| o.z))?, self.2.into_absolute(origin.map(|o| o.z))?,
@ -83,7 +83,7 @@ impl DefaultNameArgConsumer for BlockPosArgumentConsumer {
} }
impl<'a> FindArg<'a> for BlockPosArgumentConsumer { impl<'a> FindArg<'a> for BlockPosArgumentConsumer {
type Data = WorldPosition; type Data = BlockPos;
fn find_arg(args: &'a super::ConsumedArgs, name: &str) -> Result<Self::Data, CommandError> { fn find_arg(args: &'a super::ConsumedArgs, name: &str) -> Result<Self::Data, CommandError> {
match args.get(name) { match args.get(name) {

View File

@ -7,7 +7,7 @@ use pumpkin_protocol::client::play::{
}; };
use pumpkin_util::text::TextComponent; use pumpkin_util::text::TextComponent;
use pumpkin_util::{ use pumpkin_util::{
math::{position::WorldPosition, vector2::Vector2, vector3::Vector3}, math::{position::BlockPos, vector2::Vector2, vector3::Vector3},
GameMode, GameMode,
}; };
@ -77,7 +77,7 @@ pub(crate) enum Arg<'a> {
Entities(Vec<Arc<Player>>), Entities(Vec<Arc<Player>>),
Entity(Arc<Player>), Entity(Arc<Player>),
Players(Vec<Arc<Player>>), Players(Vec<Arc<Player>>),
BlockPos(WorldPosition), BlockPos(BlockPos),
Pos3D(Vector3<f64>), Pos3D(Vector3<f64>),
Pos2D(Vector2<f64>), Pos2D(Vector2<f64>),
Rotation(f32, f32), Rotation(f32, f32),

View File

@ -6,7 +6,7 @@ use crate::command::tree_builder::{argument, literal};
use crate::command::{CommandError, CommandExecutor, CommandSender}; use crate::command::{CommandError, CommandExecutor, CommandSender};
use async_trait::async_trait; 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::math::vector3::Vector3;
use pumpkin_util::text::TextComponent; use pumpkin_util::text::TextComponent;
@ -66,9 +66,9 @@ impl CommandExecutor for SetblockExecutor {
for x in start_x..=end_x { for x in start_x..=end_x {
for y in start_y..=end_y { for y in start_y..=end_y {
for z in start_z..=end_z { for z in start_z..=end_z {
let block_position = WorldPosition(Vector3 { x, y, z }); let block_position = BlockPos(Vector3 { x, y, z });
world.break_block(block_position, None).await; world.break_block(&block_position, None).await;
world.set_block_state(block_position, block_state_id).await; world.set_block_state(&block_position, block_state_id).await;
placed_blocks += 1; placed_blocks += 1;
} }
} }
@ -78,8 +78,8 @@ impl CommandExecutor for SetblockExecutor {
for x in start_x..=end_x { for x in start_x..=end_x {
for y in start_y..=end_y { for y in start_y..=end_y {
for z in start_z..=end_z { for z in start_z..=end_z {
let block_position = WorldPosition(Vector3 { x, y, z }); let block_position = BlockPos(Vector3 { x, y, z });
world.set_block_state(block_position, block_state_id).await; world.set_block_state(&block_position, block_state_id).await;
placed_blocks += 1; placed_blocks += 1;
} }
} }
@ -89,10 +89,10 @@ impl CommandExecutor for SetblockExecutor {
for x in start_x..=end_x { for x in start_x..=end_x {
for y in start_y..=end_y { for y in start_y..=end_y {
for z in start_z..=end_z { for z in start_z..=end_z {
let block_position = WorldPosition(Vector3 { x, y, z }); let block_position = BlockPos(Vector3 { x, y, z });
match world.get_block_state(block_position).await { match world.get_block_state(&block_position).await {
Ok(old_state) if old_state.air => { 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; placed_blocks += 1;
} }
_ => {} _ => {}
@ -105,7 +105,7 @@ impl CommandExecutor for SetblockExecutor {
for x in start_x..=end_x { for x in start_x..=end_x {
for y in start_y..=end_y { for y in start_y..=end_y {
for z in start_z..=end_z { 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 let is_edge = x == start_x
|| x == end_x || x == end_x
|| y == start_y || y == start_y
@ -113,9 +113,9 @@ impl CommandExecutor for SetblockExecutor {
|| z == start_z || z == start_z
|| z == end_z; || z == end_z;
if is_edge { if is_edge {
world.set_block_state(block_position, block_state_id).await; world.set_block_state(&block_position, block_state_id).await;
} else { } else {
world.set_block_state(block_position, 0).await; world.set_block_state(&block_position, 0).await;
} }
placed_blocks += 1; placed_blocks += 1;
} }
@ -126,7 +126,7 @@ impl CommandExecutor for SetblockExecutor {
for x in start_x..=end_x { for x in start_x..=end_x {
for y in start_y..=end_y { for y in start_y..=end_y {
for z in start_z..=end_z { 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 let is_edge = x == start_x
|| x == end_x || x == end_x
|| y == start_y || y == start_y
@ -134,7 +134,7 @@ impl CommandExecutor for SetblockExecutor {
|| z == start_z || z == start_z
|| z == end_z; || z == end_z;
if is_edge { 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; placed_blocks += 1;
} }
} }

View File

@ -47,17 +47,17 @@ impl CommandExecutor for SetblockExecutor {
let success = match mode { let success = match mode {
Mode::Destroy => { Mode::Destroy => {
world.break_block(pos, None).await; world.break_block(&pos, None).await;
world.set_block_state(pos, block_state_id).await; world.set_block_state(&pos, block_state_id).await;
true true
} }
Mode::Replace => { Mode::Replace => {
world.set_block_state(pos, block_state_id).await; world.set_block_state(&pos, block_state_id).await;
true 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 => { 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 true
} }
Ok(_) => false, Ok(_) => false,

View File

@ -45,6 +45,7 @@ impl Navigator {
goal.current_progress.y, goal.current_progress.y,
goal.current_progress.z + z, goal.current_progress.z + z,
); );
let node = Node::new(potential_pos); let node = Node::new(potential_pos);
let cost = node.get_expense(goal.destination); let cost = node.get_expense(goal.destination);

View File

@ -46,11 +46,14 @@ pub async fn from_type(
position: Vector3<f64>, position: Vector3<f64>,
world: &Arc<World>, world: &Arc<World>,
) -> (Arc<MobEntity>, Uuid) { ) -> (Arc<MobEntity>, Uuid) {
let entity = server.add_mob_entity(entity_type, position, world).await;
#[expect(clippy::single_match)]
match entity_type { match entity_type {
EntityType::Zombie => Zombie::make(server, position, world).await, EntityType::Zombie => Zombie::make(&entity.0).await,
// TODO // TODO
_ => server.add_mob_entity(entity_type, position, world).await, _ => (),
} }
entity
} }
impl MobEntity { impl MobEntity {

View File

@ -1,30 +1,12 @@
use std::sync::Arc; use crate::entity::ai::goal::{look_at_entity::LookAtEntityGoal, target_goal::TargetGoal};
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 super::MobEntity; use super::MobEntity;
pub struct Zombie; pub struct Zombie;
impl Zombie { impl Zombie {
pub async fn make( pub async fn make(mob: &MobEntity) {
server: &Server, mob.goal(LookAtEntityGoal::new(8.0)).await;
position: Vector3<f64>, mob.goal(TargetGoal::new(16.0)).await;
world: &Arc<World>,
) -> (Arc<MobEntity>, 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)
} }
} }

View File

@ -10,7 +10,7 @@ use pumpkin_protocol::{
use pumpkin_util::math::{ use pumpkin_util::math::{
boundingbox::{BoundingBox, BoundingBoxSize}, boundingbox::{BoundingBox, BoundingBoxSize},
get_section_cord, get_section_cord,
position::WorldPosition, position::BlockPos,
vector2::Vector2, vector2::Vector2,
vector3::Vector3, vector3::Vector3,
wrap_degrees, wrap_degrees,
@ -39,7 +39,7 @@ pub struct Entity {
/// The entity's current position in the world /// The entity's current position in the world
pub pos: AtomicCell<Vector3<f64>>, pub pos: AtomicCell<Vector3<f64>>,
/// The entity's position rounded to the nearest block coordinates /// The entity's position rounded to the nearest block coordinates
pub block_pos: AtomicCell<WorldPosition>, pub block_pos: AtomicCell<BlockPos>,
/// The chunk coordinates of the entity's current position /// The chunk coordinates of the entity's current position
pub chunk_pos: AtomicCell<Vector2<i32>>, pub chunk_pos: AtomicCell<Vector2<i32>>,
/// Indicates whether the entity is sneaking /// Indicates whether the entity is sneaking
@ -90,7 +90,7 @@ impl Entity {
entity_type, entity_type,
on_ground: AtomicBool::new(false), on_ground: AtomicBool::new(false),
pos: AtomicCell::new(position), 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)), chunk_pos: AtomicCell::new(Vector2::new(floor_x, floor_z)),
sneaking: AtomicBool::new(false), sneaking: AtomicBool::new(false),
world, world,
@ -133,7 +133,7 @@ impl Entity {
|| floor_z != block_pos_vec.z || floor_z != block_pos_vec.z
{ {
let new_block_pos = Vector3::new(floor_x, floor_y, floor_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(); let chunk_pos = self.chunk_pos.load();
if get_section_cord(floor_x) != chunk_pos.x if get_section_cord(floor_x) != chunk_pos.x

View File

@ -41,7 +41,7 @@ use pumpkin_protocol::{
use pumpkin_util::{ use pumpkin_util::{
math::{ math::{
boundingbox::{BoundingBox, BoundingBoxSize}, boundingbox::{BoundingBox, BoundingBoxSize},
position::WorldPosition, position::BlockPos,
vector2::Vector2, vector2::Vector2,
vector3::Vector3, 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 d = self.block_interaction_range() + additional_range;
let box_pos = BoundingBox::from_block(pos); let box_pos = BoundingBox::from_block(pos);
let entity_pos = self.living_entity.entity.pos.load(); let entity_pos = self.living_entity.entity.pos.load();

View File

@ -85,30 +85,18 @@ fn init_logger() {
logger = logger.without_timestamps(); 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_colors(ADVANCED_CONFIG.logging.color);
logger = logger.with_threads(ADVANCED_CONFIG.logging.threads); logger = logger.with_threads(ADVANCED_CONFIG.logging.threads);
if ADVANCED_CONFIG.logging.env { logger = logger.env();
logger = logger.env();
}
logger.init().unwrap(); 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 CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
const GIT_VERSION: &str = env!("GIT_VERSION"); const GIT_VERSION: &str = env!("GIT_VERSION");

View File

@ -35,7 +35,7 @@ use pumpkin_protocol::{
SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSwingArm, SUseItemOn, Status, 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::{ use pumpkin_util::{
math::{vector3::Vector3, wrap_degrees}, math::{vector3::Vector3, wrap_degrees},
text::TextComponent, text::TextComponent,
@ -356,7 +356,7 @@ impl Player {
return; 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; return;
}; };
@ -736,9 +736,9 @@ impl Player {
// Block break & block break sound // Block break & block break sound
let entity = &self.living_entity.entity; let entity = &self.living_entity.entity;
let world = &entity.world; 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 { if let Ok(block) = block {
server server
@ -774,9 +774,9 @@ impl Player {
// Block break & block break sound // Block break & block break sound
let entity = &self.living_entity.entity; let entity = &self.living_entity.entity;
let world = &entity.world; 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 { if let Ok(block) = block {
server server
@ -861,7 +861,7 @@ impl Player {
if let Some(item_stack) = item_slot { if let Some(item_stack) = item_slot {
// check if block is interactive // check if block is interactive
if let Some(item) = get_item_by_id(item_stack.item_id) { 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 let result = server
.block_manager .block_manager
.on_use_with_item(block, self, location, item, server) .on_use_with_item(block, self, location, item, server)
@ -1032,12 +1032,12 @@ impl Player {
&self, &self,
item_t: String, item_t: String,
server: &Server, server: &Server,
location: WorldPosition, location: BlockPos,
face: &BlockFace, face: &BlockFace,
) -> Result<bool, Box<dyn PumpkinError>> { ) -> Result<bool, Box<dyn PumpkinError>> {
// checks if spawn egg has a corresponding entity name // checks if spawn egg has a corresponding entity name
if let Some(spawn_item_id) = get_entity_id(&item_t) { 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 // align position like Vanilla does
let pos = Vector3::new( let pos = Vector3::new(
f64::from(world_pos.0.x) + 0.5, f64::from(world_pos.0.x) + 0.5,
@ -1088,20 +1088,20 @@ impl Player {
block: Block, block: Block,
server: &Server, server: &Server,
use_item_on: SUseItemOn, use_item_on: SUseItemOn,
location: WorldPosition, location: BlockPos,
face: &BlockFace, face: &BlockFace,
) -> Result<bool, Box<dyn PumpkinError>> { ) -> Result<bool, Box<dyn PumpkinError>> {
let entity = &self.living_entity.entity; let entity = &self.living_entity.entity;
let world = &entity.world; let world = &entity.world;
let clicked_world_pos = WorldPosition(location.0); let clicked_world_pos = BlockPos(location.0);
let clicked_block_state = world.get_block_state(clicked_world_pos).await?; let clicked_block_state = world.get_block_state(&clicked_world_pos).await?;
let world_pos = if clicked_block_state.replaceable { let world_pos = if clicked_block_state.replaceable {
clicked_world_pos clicked_world_pos
} else { } else {
let world_pos = WorldPosition(location.0 + face.to_offset()); let world_pos = BlockPos(location.0 + face.to_offset());
let previous_block_state = world.get_block_state(world_pos).await?; let previous_block_state = world.get_block_state(&world_pos).await?;
if !previous_block_state.replaceable { if !previous_block_state.replaceable {
return Ok(true); return Ok(true);
@ -1128,7 +1128,7 @@ impl Player {
} }
if !intersects { if !intersects {
world world
.set_block_state(world_pos, block.default_state_id) .set_block_state(&world_pos, block.default_state_id)
.await; .await;
server server
.block_manager .block_manager

View File

@ -9,7 +9,7 @@ use pumpkin_protocol::client::login::CEncryptionRequest;
use pumpkin_protocol::{client::config::CPluginMessage, ClientPacket}; use pumpkin_protocol::{client::config::CPluginMessage, ClientPacket};
use pumpkin_registry::{DimensionType, Registry}; use pumpkin_registry::{DimensionType, Registry};
use pumpkin_util::math::boundingbox::{BoundingBox, BoundingBoxSize}; 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::vector2::Vector2;
use pumpkin_util::math::vector3::Vector3; use pumpkin_util::math::vector3::Vector3;
use pumpkin_util::GameMode; 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 /// 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. /// blocks, the output will return a random result.
pub async fn get_container_id(&self, location: WorldPosition, block: Block) -> Option<u32> { pub async fn get_container_id(&self, location: BlockPos, block: Block) -> Option<u32> {
let open_containers = self.open_containers.read().await; let open_containers = self.open_containers.read().await;
// TODO: do better than brute force // TODO: do better than brute force
for (id, container) in open_containers.iter() { for (id, container) in open_containers.iter() {
@ -292,7 +292,7 @@ impl Server {
pub async fn get_all_container_ids( pub async fn get_all_container_ids(
&self, &self,
location: WorldPosition, location: BlockPos,
block: Block, block: Block,
) -> Option<Vec<u32>> { ) -> Option<Vec<u32>> {
let open_containers = self.open_containers.read().await; let open_containers = self.open_containers.read().await;

View File

@ -30,7 +30,7 @@ use pumpkin_protocol::{
}; };
use pumpkin_registry::DimensionType; use pumpkin_registry::DimensionType;
use pumpkin_util::math::vector2::Vector2; 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_util::text::{color::NamedColor, TextComponent};
use pumpkin_world::chunk::ChunkData; use pumpkin_world::chunk::ChunkData;
use pumpkin_world::level::Level; use pumpkin_world::level::Level;
@ -181,7 +181,7 @@ impl World {
.await; .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( let new_vec = Vector3::new(
f64::from(position.0.x) + 0.5, f64::from(position.0.x) + 0.5,
f64::from(position.0.y) + 0.5, f64::from(position.0.y) + 0.5,
@ -191,12 +191,12 @@ impl World {
.await; .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)) self.broadcast_packet_all(&CLevelEvent::new(1010, position, record_id, false))
.await; .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)) self.broadcast_packet_all(&CLevelEvent::new(1011, position, 0, false))
.await; .await;
} }
@ -223,8 +223,8 @@ impl World {
/// Gets the y position of the first non air block from the top down /// Gets the y position of the first non air block from the top down
pub async fn get_top_block(&self, position: Vector2<i32>) -> i32 { pub async fn get_top_block(&self, position: Vector2<i32>) -> i32 {
for y in (-64..=319).rev() { for y in (-64..=319).rev() {
let pos = WorldPosition(Vector3::new(position.x, y, position.z)); let pos = BlockPos(Vector3::new(position.x, y, position.z));
let block = self.get_block_state(pos).await; let block = self.get_block_state(&pos).await;
if let Ok(block) = block { if let Ok(block) = block {
if block.air { if block.air {
continue; continue;
@ -441,7 +441,7 @@ impl World {
pub async fn respawn_player(&self, player: &Arc<Player>, alive: bool) { pub async fn respawn_player(&self, player: &Arc<Player>, alive: bool) {
let last_pos = player.living_entity.last_pos.load(); let last_pos = player.living_entity.last_pos.load();
let death_dimension = player.world().dimension_type.name(); 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.x.round() as i32,
last_pos.y.round() as i32, last_pos.y.round() as i32,
last_pos.z.round() as i32, last_pos.z.round() as i32,
@ -663,10 +663,7 @@ impl World {
/// # Arguments /// # Arguments
/// ///
/// * `position`: The position the function will check. /// * `position`: The position the function will check.
pub async fn get_players_by_pos( pub async fn get_players_by_pos(&self, position: BlockPos) -> HashMap<uuid::Uuid, Arc<Player>> {
&self,
position: WorldPosition,
) -> HashMap<uuid::Uuid, Arc<Player>> {
self.current_players self.current_players
.lock() .lock()
.await .await
@ -828,7 +825,7 @@ impl World {
} }
/// Sets a block /// 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(); let (chunk_coordinate, relative_coordinates) = position.chunk_and_chunk_relative_position();
// Since we divide by 16 remnant can never exceed u8 // Since we divide by 16 remnant can never exceed u8
@ -843,7 +840,7 @@ impl World {
.set_block(relative, block_state_id); .set_block(relative, block_state_id);
self.broadcast_packet_all(&CBlockUpdate::new( self.broadcast_packet_all(&CBlockUpdate::new(
&position, position,
i32::from(block_state_id).into(), i32::from(block_state_id).into(),
)) ))
.await; .await;
@ -883,12 +880,12 @@ impl World {
chunk 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 broken_block_state_id = self.set_block_state(position, 0).await;
let particles_packet = CWorldEvent::new( let particles_packet = CWorldEvent::new(
WorldEvent::BlockBroken as i32, WorldEvent::BlockBroken as i32,
&position, position,
broken_block_state_id.into(), broken_block_state_id.into(),
false, false,
); );
@ -902,7 +899,7 @@ impl World {
} }
} }
pub async fn get_block_state_id(&self, position: WorldPosition) -> Result<u16, GetBlockError> { pub async fn get_block_state_id(&self, position: &BlockPos) -> Result<u16, GetBlockError> {
let (chunk, relative) = position.chunk_and_chunk_relative_position(); let (chunk, relative) = position.chunk_and_chunk_relative_position();
let relative = ChunkRelativeBlockCoordinates::from(relative); let relative = ChunkRelativeBlockCoordinates::from(relative);
let chunk = self.receive_chunk(chunk).await; 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 /// Gets the Block from the Block Registry, Returns None if the Block has not been found
pub async fn get_block( pub async fn get_block(
&self, &self,
position: WorldPosition, position: &BlockPos,
) -> Result<&pumpkin_world::block::block_registry::Block, GetBlockError> { ) -> Result<&pumpkin_world::block::block_registry::Block, GetBlockError> {
let id = self.get_block_state_id(position).await?; let id = self.get_block_state_id(position).await?;
get_block_by_state_id(id).ok_or(GetBlockError::InvalidBlockId) 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 /// Gets the Block state from the Block Registry, Returns None if the Block state has not been found
pub async fn get_block_state( pub async fn get_block_state(
&self, &self,
position: WorldPosition, position: &BlockPos,
) -> Result<&pumpkin_world::block::block_registry::State, GetBlockError> { ) -> Result<&pumpkin_world::block::block_registry::State, GetBlockError> {
let id = self.get_block_state_id(position).await?; let id = self.get_block_state_id(position).await?;
get_state_by_state_id(id).ok_or(GetBlockError::InvalidBlockId) 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 /// 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( pub async fn get_block_and_block_state(
&self, &self,
position: WorldPosition, position: &BlockPos,
) -> Result< ) -> Result<
( (
&pumpkin_world::block::block_registry::Block, &pumpkin_world::block::block_registry::Block,

View File

@ -3,7 +3,7 @@ use std::{num::NonZeroU8, sync::Arc};
use pumpkin_config::BASIC_CONFIG; use pumpkin_config::BASIC_CONFIG;
use pumpkin_protocol::client::play::{CCenterChunk, CUnloadChunk}; use pumpkin_protocol::client::play::{CCenterChunk, CUnloadChunk};
use pumpkin_util::{ use pumpkin_util::{
math::{get_section_cord, position::WorldPosition, vector3::Vector3}, math::{get_section_cord, position::BlockPos, vector3::Vector3},
GameMode, GameMode,
}; };
use pumpkin_world::cylindrical_chunk_iterator::Cylindrical; use pumpkin_world::cylindrical_chunk_iterator::Cylindrical;
@ -111,7 +111,7 @@ pub async fn update_position(player: &Arc<Player>) {
} }
#[must_use] #[must_use]
pub const fn chunk_section_from_pos(block_pos: &WorldPosition) -> Vector3<i32> { pub const fn chunk_section_from_pos(block_pos: &BlockPos) -> Vector3<i32> {
let block_pos = block_pos.0; let block_pos = block_pos.0;
Vector3::new( Vector3::new(
get_section_cord(block_pos.x), get_section_cord(block_pos.x),