aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src/position.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2026-01-13 10:51:45 -0600
committerGitHub <noreply@github.com>2026-01-13 10:51:45 -0600
commitb21ac946cafaacc9ee2478ea48ed9e72554f79ed (patch)
tree4d05744b9801e94f5da6563d8fabddfb20d1c7b7 /azalea-core/src/position.rs
parentd5fa5e32b37754b3b5c136e58821e48cd3b7c2ff (diff)
downloadazalea-drasl-b21ac946cafaacc9ee2478ea48ed9e72554f79ed.tar.xz
Merge AzaleaRead and AzaleaWrite (#305)
Diffstat (limited to 'azalea-core/src/position.rs')
-rw-r--r--azalea-core/src/position.rs47
1 files changed, 18 insertions, 29 deletions
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index 6da037ff..3f2a724f 100644
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -12,7 +12,7 @@ use std::{
str::FromStr,
};
-use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError};
+use azalea_buf::{AzBuf, BufReadError};
use azalea_registry::identifier::Identifier;
#[cfg(feature = "serde")]
use serde::Serializer;
@@ -584,13 +584,11 @@ impl From<u64> for ChunkPos {
}
}
}
-impl AzaleaRead for ChunkPos {
+impl AzBuf for ChunkPos {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let long = u64::azalea_read(buf)?;
Ok(ChunkPos::from(long))
}
-}
-impl AzaleaWrite for ChunkPos {
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
u64::from(*self).azalea_write(buf)?;
Ok(())
@@ -986,7 +984,7 @@ const PACKED_Z_MASK: u64 = (1 << PACKED_Z_LENGTH) - 1;
const Z_OFFSET: u64 = PACKED_Y_LENGTH;
const X_OFFSET: u64 = PACKED_Y_LENGTH + PACKED_Z_LENGTH;
-impl AzaleaRead for BlockPos {
+impl AzBuf for BlockPos {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let val = i64::azalea_read(buf)?;
let x = (val << (64 - X_OFFSET - PACKED_X_LENGTH) >> (64 - PACKED_X_LENGTH)) as i32;
@@ -994,18 +992,31 @@ impl AzaleaRead for BlockPos {
let z = (val << (64 - Z_OFFSET - PACKED_Z_LENGTH) >> (64 - PACKED_Z_LENGTH)) as i32;
Ok(BlockPos { x, y, z })
}
+ fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
+ let mut val: u64 = 0;
+ val |= ((self.x as u64) & PACKED_X_MASK) << X_OFFSET;
+ val |= (self.y as u64) & PACKED_Y_MASK;
+ val |= ((self.z as u64) & PACKED_Z_MASK) << Z_OFFSET;
+ val.azalea_write(buf)
+ }
}
-impl AzaleaRead for GlobalPos {
+impl AzBuf for GlobalPos {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
Ok(GlobalPos {
dimension: Identifier::azalea_read(buf)?,
pos: BlockPos::azalea_read(buf)?,
})
}
+ fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
+ Identifier::azalea_write(&self.dimension, buf)?;
+ BlockPos::azalea_write(&self.pos, buf)?;
+
+ Ok(())
+ }
}
-impl AzaleaRead for ChunkSectionPos {
+impl AzBuf for ChunkSectionPos {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let long = i64::azalea_read(buf)?;
Ok(ChunkSectionPos {
@@ -1014,28 +1025,6 @@ impl AzaleaRead for ChunkSectionPos {
z: (long << 22 >> 42) as i32,
})
}
-}
-
-impl AzaleaWrite for BlockPos {
- fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
- let mut val: u64 = 0;
- val |= ((self.x as u64) & PACKED_X_MASK) << X_OFFSET;
- val |= (self.y as u64) & PACKED_Y_MASK;
- val |= ((self.z as u64) & PACKED_Z_MASK) << Z_OFFSET;
- val.azalea_write(buf)
- }
-}
-
-impl AzaleaWrite for GlobalPos {
- fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
- Identifier::azalea_write(&self.dimension, buf)?;
- BlockPos::azalea_write(&self.pos, buf)?;
-
- Ok(())
- }
-}
-
-impl AzaleaWrite for ChunkSectionPos {
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
let long = (((self.x & 0x3FFFFF) as i64) << 42)
| (self.y & 0xFFFFF) as i64