diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2026-01-13 10:51:45 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-13 10:51:45 -0600 |
| commit | b21ac946cafaacc9ee2478ea48ed9e72554f79ed (patch) | |
| tree | 4d05744b9801e94f5da6563d8fabddfb20d1c7b7 /azalea-protocol/src/common | |
| parent | d5fa5e32b37754b3b5c136e58821e48cd3b7c2ff (diff) | |
| download | azalea-drasl-b21ac946cafaacc9ee2478ea48ed9e72554f79ed.tar.xz | |
Merge AzaleaRead and AzaleaWrite (#305)
Diffstat (limited to 'azalea-protocol/src/common')
| -rw-r--r-- | azalea-protocol/src/common/client_information.rs | 9 | ||||
| -rw-r--r-- | azalea-protocol/src/common/movements.rs | 29 | ||||
| -rw-r--r-- | azalea-protocol/src/common/tags.rs | 12 |
3 files changed, 18 insertions, 32 deletions
diff --git a/azalea-protocol/src/common/client_information.rs b/azalea-protocol/src/common/client_information.rs index 189f1019..46202b45 100644 --- a/azalea-protocol/src/common/client_information.rs +++ b/azalea-protocol/src/common/client_information.rs @@ -1,6 +1,6 @@ use std::io::{self, Cursor}; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite}; +use azalea_buf::AzBuf; use azalea_core::bitset::FixedBitSet; use azalea_entity::HumanoidArm; @@ -94,7 +94,7 @@ impl Default for ModelCustomization { } } -impl AzaleaRead for ModelCustomization { +impl AzBuf for ModelCustomization { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> { let set = FixedBitSet::<7>::azalea_read(buf)?; Ok(Self { @@ -107,9 +107,6 @@ impl AzaleaRead for ModelCustomization { hat: set.index(6), }) } -} - -impl AzaleaWrite for ModelCustomization { fn azalea_write(&self, buf: &mut impl io::Write) -> io::Result<()> { let mut set = FixedBitSet::<7>::new(); if self.cape { @@ -141,7 +138,7 @@ impl AzaleaWrite for ModelCustomization { mod tests { use std::io::Cursor; - use azalea_buf::{AzaleaRead, AzaleaWrite}; + use azalea_buf::AzBuf; use super::*; diff --git a/azalea-protocol/src/common/movements.rs b/azalea-protocol/src/common/movements.rs index 82559f86..67cfb272 100644 --- a/azalea-protocol/src/common/movements.rs +++ b/azalea-protocol/src/common/movements.rs @@ -3,7 +3,7 @@ use std::{ ops::Add, }; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; +use azalea_buf::{AzBuf, BufReadError}; use azalea_core::{bitset::FixedBitSet, math, position::Vec3}; use azalea_entity::{LookDirection, Physics, Position}; @@ -91,7 +91,7 @@ fn apply_change<T: Add<Output = T>>(base: T, condition: bool, change: T) -> T { if condition { base + change } else { change } } -impl AzaleaRead for RelativeMovements { +impl AzBuf for RelativeMovements { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { // yes minecraft seriously wastes that many bits, smh let set = u32::azalea_read(buf)?; @@ -108,9 +108,6 @@ impl AzaleaRead for RelativeMovements { rotate_delta: set.index(8), }) } -} - -impl AzaleaWrite for RelativeMovements { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let mut set = FixedBitSet::<32>::new(); let mut set_bit = |index: usize, value: bool| { @@ -138,7 +135,16 @@ pub struct MoveFlags { pub on_ground: bool, pub horizontal_collision: bool, } -impl AzaleaWrite for MoveFlags { +impl AzBuf for MoveFlags { + fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let bitset = FixedBitSet::<8>::azalea_read(buf)?; + let on_ground = bitset.index(0); + let horizontal_collision = bitset.index(1); + Ok(Self { + on_ground, + horizontal_collision, + }) + } fn azalea_write(&self, buf: &mut impl io::Write) -> Result<(), io::Error> { let mut bitset = FixedBitSet::<8>::new(); if self.on_ground { @@ -151,14 +157,3 @@ impl AzaleaWrite for MoveFlags { Ok(()) } } -impl AzaleaRead for MoveFlags { - fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { - let bitset = FixedBitSet::<8>::azalea_read(buf)?; - let on_ground = bitset.index(0); - let horizontal_collision = bitset.index(1); - Ok(Self { - on_ground, - horizontal_collision, - }) - } -} diff --git a/azalea-protocol/src/common/tags.rs b/azalea-protocol/src/common/tags.rs index 3f9a2ef2..75c50ff5 100644 --- a/azalea-protocol/src/common/tags.rs +++ b/azalea-protocol/src/common/tags.rs @@ -3,7 +3,7 @@ use std::{ ops::Deref, }; -use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; +use azalea_buf::{AzBuf, AzBufVar, BufReadError}; use azalea_registry::identifier::Identifier; use indexmap::IndexMap; @@ -16,7 +16,7 @@ pub struct Tags { pub elements: Vec<i32>, } -impl AzaleaRead for TagMap { +impl AzBuf for TagMap { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let length = u32::azalea_read_var(buf)? as usize; let mut data = IndexMap::new(); @@ -32,9 +32,6 @@ impl AzaleaRead for TagMap { } Ok(TagMap(data)) } -} - -impl AzaleaWrite for TagMap { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { (self.len() as u32).azalea_write_var(buf)?; for (k, v) in &self.0 { @@ -44,15 +41,12 @@ impl AzaleaWrite for TagMap { Ok(()) } } -impl AzaleaRead for Tags { +impl AzBuf for Tags { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let name = Identifier::azalea_read(buf)?; let elements = Vec::<i32>::azalea_read_var(buf)?; Ok(Tags { name, elements }) } -} - -impl AzaleaWrite for Tags { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { self.name.azalea_write(buf)?; self.elements.azalea_write_var(buf)?; |
