1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

Fix issues with entity pos conversion to block pos

This commit is contained in:
mat 2022-06-19 13:42:01 -05:00
parent 7f7b979125
commit e84893b07a
3 changed files with 36 additions and 11 deletions

View file

@ -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,
}
}
}
@ -188,14 +188,25 @@ mod tests {
assert_eq!(chunk_block_pos, ChunkBlockPos::new(5, 78, 14));
}
#[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));
}
}

View file

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

View file

@ -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" {