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 /azalea-core/src/position.rs | |
| parent | 7f7b979125fb03cf4f9b5d9dbcb15a836b7a7b84 (diff) | |
| download | azalea-drasl-e84893b07a65ebca8d4027b386d3dfd87bcfd009.tar.xz | |
Fix issues with entity pos conversion to block pos
Diffstat (limited to 'azalea-core/src/position.rs')
| -rw-r--r-- | azalea-core/src/position.rs | 27 |
1 files changed, 19 insertions, 8 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)); } } |
