diff options
| author | mat <github@matdoes.dev> | 2022-06-19 13:42:01 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-06-19 13:42:01 -0500 |
| commit | e84893b07a65ebca8d4027b386d3dfd87bcfd009 (patch) | |
| tree | bad178c83b543a3ebf9221d4431ce0d740c0c264 | |
| parent | 7f7b979125fb03cf4f9b5d9dbcb15a836b7a7b84 (diff) | |
| download | azalea-drasl-e84893b07a65ebca8d4027b386d3dfd87bcfd009.tar.xz | |
Fix issues with entity pos conversion to block pos
| -rw-r--r-- | azalea-core/src/position.rs | 27 | ||||
| -rw-r--r-- | azalea-world/src/chunk.rs | 16 | ||||
| -rw-r--r-- | bot/src/main.rs | 4 |
3 files changed, 36 insertions, 11 deletions
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index 43881f1c..7b2c01da 100644 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -2,7 +2,7 @@ use std::ops::Rem; use crate::resource_location::ResourceLocation; -#[derive(Clone, Copy, Debug, Default)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct BlockPos { pub x: i32, pub y: i32, @@ -157,9 +157,9 @@ pub struct EntityPos { impl From<&EntityPos> for BlockPos { fn from(pos: &EntityPos) -> Self { BlockPos { - x: pos.x as i32, - y: pos.y as i32, - z: pos.z as i32, + x: pos.x.floor() as i32, + y: pos.y.floor() as i32, + z: pos.z.floor() as i32, } } } @@ -189,13 +189,24 @@ mod tests { } #[test] + fn test_from_entity_pos_to_block_pos() { + let entity_pos = EntityPos { + x: 31.5, + y: 80.0, + z: -16.1, + }; + let block_pos = BlockPos::from(&entity_pos); + assert_eq!(block_pos, BlockPos::new(31, 80, -17)); + } + + #[test] fn test_from_entity_pos_to_chunk_pos() { let entity_pos = EntityPos { - x: 33.5, - y: 77.0, - z: -19.6, + x: 31.5, + y: 80.0, + z: -16.1, }; let chunk_pos = ChunkPos::from(&entity_pos); - assert_eq!(chunk_pos, ChunkPos::new(2, -2)); + assert_eq!(chunk_pos, ChunkPos::new(1, -2)); } } diff --git a/azalea-world/src/chunk.rs b/azalea-world/src/chunk.rs index cbf77b20..5de39e52 100644 --- a/azalea-world/src/chunk.rs +++ b/azalea-world/src/chunk.rs @@ -4,6 +4,7 @@ use crate::World; use azalea_block::BlockState; use azalea_core::{BlockPos, ChunkBlockPos, ChunkPos, ChunkSectionBlockPos}; use azalea_protocol::mc_buf::{McBufReadable, McBufWritable}; +use std::fmt::Debug; use std::{ io::{Read, Write}, ops::{Index, IndexMut}, @@ -12,7 +13,6 @@ use std::{ const SECTION_HEIGHT: u32 = 16; -#[derive(Debug)] pub struct ChunkStorage { pub view_center: ChunkPos, chunk_radius: u32, @@ -151,6 +151,20 @@ impl McBufWritable for Chunk { } } +impl Debug for ChunkStorage { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("ChunkStorage") + .field("view_center", &self.view_center) + .field("chunk_radius", &self.chunk_radius) + .field("view_range", &self.view_range) + .field("height", &self.height) + .field("min_y", &self.min_y) + // .field("chunks", &self.chunks) + .field("chunks", &format_args!("{} items", self.chunks.len())) + .finish() + } +} + #[derive(Clone, Debug)] pub struct Section { pub block_count: u16, diff --git a/bot/src/main.rs b/bot/src/main.rs index 10283e90..e8ff5f95 100644 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -5,7 +5,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { println!("Hello, world!"); // let address = "95.111.249.143:10000"; - let address = "localhost:52909"; + let address = "localhost:61146"; // let response = azalea_client::ping::ping_server(&address.try_into().unwrap()) // .await // .unwrap(); @@ -22,7 +22,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { Event::Chat(_p) => { let state = client.state.lock().unwrap(); let world = state.world.as_ref().unwrap(); - println!("{:?}", world); + println!("{:#?}", world); // world.get_block_state(state.player.entity.pos); // println!("{}", p.message.to_ansi(None)); // if p.message.to_ansi(None) == "<py5> ok" { |
