diff options
Diffstat (limited to 'azalea-core/src/position.rs')
| -rw-r--r-- | azalea-core/src/position.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index d47072d4..d408d817 100644 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -1,7 +1,7 @@ use crate::ResourceLocation; use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; use std::{ - io::{Read, Write}, + io::{Cursor, Write}, ops::{Add, Mul, Rem}, }; @@ -301,7 +301,7 @@ const Z_OFFSET: u64 = PACKED_Y_LENGTH; const X_OFFSET: u64 = PACKED_Y_LENGTH + PACKED_Z_LENGTH; impl McBufReadable for BlockPos { - fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let val = i64::read_from(buf)?; let x = (val << (64 - X_OFFSET - PACKED_X_LENGTH) >> (64 - PACKED_X_LENGTH)) as i32; let y = (val << (64 - PACKED_Y_LENGTH) >> (64 - PACKED_Y_LENGTH)) as i32; @@ -311,7 +311,7 @@ impl McBufReadable for BlockPos { } impl McBufReadable for GlobalPos { - fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { Ok(GlobalPos { dimension: ResourceLocation::read_from(buf)?, pos: BlockPos::read_from(buf)?, @@ -320,7 +320,7 @@ impl McBufReadable for GlobalPos { } impl McBufReadable for ChunkSectionPos { - fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let long = i64::read_from(buf)?; Ok(ChunkSectionPos { x: (long >> 42) as i32, @@ -361,8 +361,6 @@ impl McBufWritable for ChunkSectionPos { #[cfg(test)] mod tests { - use std::io::Cursor; - use super::*; #[test] @@ -403,10 +401,10 @@ mod tests { #[test] fn test_read_blockpos_from() { - let mut buf = Cursor::new(Vec::new()); + let mut buf = Vec::new(); 13743895338965u64.write_into(&mut buf).unwrap(); - buf.set_position(0); - let block_pos = BlockPos::read_from(&mut buf).unwrap(); + let buf = &mut &buf[..]; + let block_pos = BlockPos::read_from(buf).unwrap(); assert_eq!(block_pos, BlockPos::new(49, -43, -3)); } } |
