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 | |
| parent | d5fa5e32b37754b3b5c136e58821e48cd3b7c2ff (diff) | |
| download | azalea-drasl-b21ac946cafaacc9ee2478ea48ed9e72554f79ed.tar.xz | |
Merge AzaleaRead and AzaleaWrite (#305)
Diffstat (limited to 'azalea-protocol/src')
40 files changed, 164 insertions, 275 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)?; diff --git a/azalea-protocol/src/packets/game/c_boss_event.rs b/azalea-protocol/src/packets/game/c_boss_event.rs index 10cf30d4..19bd74a9 100644 --- a/azalea-protocol/src/packets/game/c_boss_event.rs +++ b/azalea-protocol/src/packets/game/c_boss_event.rs @@ -3,7 +3,7 @@ use std::{ io::{Cursor, Write}, }; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; +use azalea_buf::{AzBuf, AzBufVar, BufReadError}; use azalea_chat::FormattedText; use azalea_core::bitset::FixedBitSet; use azalea_protocol_macros::ClientboundGamePacket; @@ -25,7 +25,7 @@ pub enum Operation { UpdateProperties(Properties), } -impl AzaleaRead for Operation { +impl AzBuf for Operation { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let operation_id = u32::azalea_read_var(buf)?; Ok(match operation_id { @@ -42,9 +42,6 @@ impl AzaleaRead for Operation { } }) } -} - -impl AzaleaWrite for Operation { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { match self { Operation::Add(add) => { @@ -116,7 +113,7 @@ pub struct Properties { pub create_world_fog: bool, } -impl AzaleaRead for Properties { +impl AzBuf for Properties { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let set = FixedBitSet::<3>::azalea_read(buf)?; Ok(Self { @@ -125,9 +122,6 @@ impl AzaleaRead for Properties { create_world_fog: set.index(2), }) } -} - -impl AzaleaWrite for Properties { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let mut set = FixedBitSet::<3>::new(); if self.darken_screen { diff --git a/azalea-protocol/src/packets/game/c_command_suggestions.rs b/azalea-protocol/src/packets/game/c_command_suggestions.rs index a0036edf..09307ee1 100644 --- a/azalea-protocol/src/packets/game/c_command_suggestions.rs +++ b/azalea-protocol/src/packets/game/c_command_suggestions.rs @@ -14,7 +14,7 @@ mod tests { use std::io::Cursor; use azalea_brigadier::{context::StringRange, suggestion::Suggestion}; - use azalea_buf::{AzaleaRead, AzaleaWrite}; + use azalea_buf::AzBuf; use super::*; diff --git a/azalea-protocol/src/packets/game/c_commands.rs b/azalea-protocol/src/packets/game/c_commands.rs index f8d95ac9..12d47e53 100644 --- a/azalea-protocol/src/packets/game/c_commands.rs +++ b/azalea-protocol/src/packets/game/c_commands.rs @@ -1,6 +1,6 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; +use azalea_buf::{AzBuf, AzBufVar, BufReadError}; use azalea_core::bitset::FixedBitSet; use azalea_protocol_macros::ClientboundGamePacket; use azalea_registry::identifier::Identifier; @@ -46,7 +46,7 @@ impl<T: PartialEq> PartialEq for BrigadierNumber<T> { } } -impl<T: AzaleaRead> AzaleaRead for BrigadierNumber<T> { +impl<T: AzBuf> AzBuf for BrigadierNumber<T> { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let flags = FixedBitSet::<2>::azalea_read(buf)?; let min = if flags.index(0) { @@ -61,8 +61,6 @@ impl<T: AzaleaRead> AzaleaRead for BrigadierNumber<T> { }; Ok(BrigadierNumber { min, max }) } -} -impl<T: AzaleaWrite> AzaleaWrite for BrigadierNumber<T> { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let mut flags = FixedBitSet::<2>::new(); if self.min.is_some() { @@ -160,7 +158,7 @@ pub struct EntityParser { pub single: bool, pub players_only: bool, } -impl AzaleaRead for EntityParser { +impl AzBuf for EntityParser { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let flags = FixedBitSet::<2>::azalea_read(buf)?; Ok(EntityParser { @@ -168,8 +166,6 @@ impl AzaleaRead for EntityParser { players_only: flags.index(1), }) } -} -impl AzaleaWrite for EntityParser { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let mut flags = FixedBitSet::<2>::new(); if self.single { @@ -184,7 +180,7 @@ impl AzaleaWrite for EntityParser { } // TODO: BrigadierNodeStub should have more stuff -impl AzaleaRead for BrigadierNodeStub { +impl AzBuf for BrigadierNodeStub { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let flags = FixedBitSet::<8>::azalea_read(buf)?; if flags.index(6) || flags.index(7) { @@ -247,9 +243,6 @@ impl AzaleaRead for BrigadierNodeStub { }) } } -} - -impl AzaleaWrite for BrigadierNodeStub { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let mut flags = FixedBitSet::<4>::new(); if self.is_executable { diff --git a/azalea-protocol/src/packets/game/c_container_set_content.rs b/azalea-protocol/src/packets/game/c_container_set_content.rs index a97973ee..bb487b20 100644 --- a/azalea-protocol/src/packets/game/c_container_set_content.rs +++ b/azalea-protocol/src/packets/game/c_container_set_content.rs @@ -16,7 +16,7 @@ pub struct ClientboundContainerSetContent { mod tests { use std::io::Cursor; - use azalea_buf::AzaleaRead; + use azalea_buf::AzBuf; use super::ClientboundContainerSetContent; diff --git a/azalea-protocol/src/packets/game/c_damage_event.rs b/azalea-protocol/src/packets/game/c_damage_event.rs index 76ceb8ec..e24878d4 100644 --- a/azalea-protocol/src/packets/game/c_damage_event.rs +++ b/azalea-protocol/src/packets/game/c_damage_event.rs @@ -1,9 +1,8 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar}; -use azalea_core::position::Vec3; +use azalea_buf::{AzBuf, AzBufVar}; +use azalea_core::{entity_id::MinecraftEntityId, position::Vec3}; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundDamageEvent { @@ -18,15 +17,13 @@ pub struct ClientboundDamageEvent { #[derive(Clone, Debug, PartialEq)] pub struct OptionalEntityId(pub Option<u32>); -impl AzaleaRead for OptionalEntityId { +impl AzBuf for OptionalEntityId { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> { match u32::azalea_read_var(buf)? { 0 => Ok(OptionalEntityId(None)), id => Ok(OptionalEntityId(Some(id - 1))), } } -} -impl AzaleaWrite for OptionalEntityId { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { match self.0 { Some(id) => (id + 1).azalea_write_var(buf), diff --git a/azalea-protocol/src/packets/game/c_explode.rs b/azalea-protocol/src/packets/game/c_explode.rs index be86abb6..651c856d 100644 --- a/azalea-protocol/src/packets/game/c_explode.rs +++ b/azalea-protocol/src/packets/game/c_explode.rs @@ -1,4 +1,4 @@ -use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite}; +use azalea_buf::AzBuf; use azalea_core::position::Vec3; use azalea_entity::particle::Particle; use azalea_protocol_macros::ClientboundGamePacket; @@ -16,7 +16,7 @@ pub struct ClientboundExplode { } #[derive(AzBuf, Clone, Debug, PartialEq)] -pub struct Weighted<T: AzaleaRead + AzaleaWrite> { +pub struct Weighted<T: AzBuf> { pub value: T, #[var] pub weight: i32, diff --git a/azalea-protocol/src/packets/game/c_map_item_data.rs b/azalea-protocol/src/packets/game/c_map_item_data.rs index 2330ce07..2d93f0e1 100644 --- a/azalea-protocol/src/packets/game/c_map_item_data.rs +++ b/azalea-protocol/src/packets/game/c_map_item_data.rs @@ -1,6 +1,6 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite}; +use azalea_buf::AzBuf; use azalea_chat::FormattedText; use azalea_protocol_macros::ClientboundGamePacket; @@ -28,7 +28,7 @@ pub struct MapDecoration { #[derive(Clone, Debug, PartialEq)] pub struct OptionalMapPatch(pub Option<MapPatch>); -impl AzaleaRead for OptionalMapPatch { +impl AzBuf for OptionalMapPatch { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> { let pos = buf.position(); Ok(Self(if u8::azalea_read(buf)? == 0 { @@ -38,9 +38,6 @@ impl AzaleaRead for OptionalMapPatch { Some(MapPatch::azalea_read(buf)?) })) } -} - -impl AzaleaWrite for OptionalMapPatch { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { match &self.0 { None => 0u8.azalea_write(buf), diff --git a/azalea-protocol/src/packets/game/c_merchant_offers.rs b/azalea-protocol/src/packets/game/c_merchant_offers.rs index 957060b4..fb2de37a 100644 --- a/azalea-protocol/src/packets/game/c_merchant_offers.rs +++ b/azalea-protocol/src/packets/game/c_merchant_offers.rs @@ -5,7 +5,7 @@ use std::{ mem::ManuallyDrop, }; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; +use azalea_buf::{AzBuf, BufReadError}; use azalea_inventory::{ DataComponentPatch, ItemStack, ItemStackData, components::{self, DataComponentUnion}, @@ -107,14 +107,12 @@ impl TypedDataComponent { component_any.downcast_ref::<T>() } } -impl AzaleaRead for TypedDataComponent { +impl AzBuf for TypedDataComponent { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let kind = DataComponentKind::azalea_read(buf)?; let value = DataComponentUnion::azalea_read_as(kind, buf)?; Ok(Self { kind, value }) } -} -impl AzaleaWrite for TypedDataComponent { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { self.kind.azalea_write(buf)?; unsafe { self.value.azalea_write_as(self.kind, buf) } diff --git a/azalea-protocol/src/packets/game/c_player_abilities.rs b/azalea-protocol/src/packets/game/c_player_abilities.rs index 926f4f2f..ac856ca4 100644 --- a/azalea-protocol/src/packets/game/c_player_abilities.rs +++ b/azalea-protocol/src/packets/game/c_player_abilities.rs @@ -1,6 +1,6 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; +use azalea_buf::{AzBuf, BufReadError}; use azalea_core::bitset::FixedBitSet; use azalea_entity::PlayerAbilities; use azalea_protocol_macros::ClientboundGamePacket; @@ -21,7 +21,7 @@ pub struct PlayerAbilitiesFlags { pub instant_break: bool, } -impl AzaleaRead for PlayerAbilitiesFlags { +impl AzBuf for PlayerAbilitiesFlags { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let set = FixedBitSet::<4>::azalea_read(buf)?; Ok(PlayerAbilitiesFlags { @@ -31,9 +31,6 @@ impl AzaleaRead for PlayerAbilitiesFlags { instant_break: set.index(3), }) } -} - -impl AzaleaWrite for PlayerAbilitiesFlags { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let mut set = FixedBitSet::<4>::new(); if self.invulnerable { diff --git a/azalea-protocol/src/packets/game/c_player_chat.rs b/azalea-protocol/src/packets/game/c_player_chat.rs index a63ab56d..cfb08803 100644 --- a/azalea-protocol/src/packets/game/c_player_chat.rs +++ b/azalea-protocol/src/packets/game/c_player_chat.rs @@ -3,7 +3,7 @@ use std::{ sync::LazyLock, }; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; +use azalea_buf::{AzBuf, AzBufVar, BufReadError}; use azalea_chat::{ FormattedText, translatable_component::{PrimitiveOrComponent, TranslatableComponent}, @@ -180,7 +180,7 @@ impl ChatTypeBound { } } -impl AzaleaRead for PackedMessageSignature { +impl AzBuf for PackedMessageSignature { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let id = u32::azalea_read_var(buf)?; if id == 0 { @@ -191,8 +191,6 @@ impl AzaleaRead for PackedMessageSignature { Ok(PackedMessageSignature::Id(id - 1)) } } -} -impl AzaleaWrite for PackedMessageSignature { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { match self { PackedMessageSignature::Signature(full_signature) => { diff --git a/azalea-protocol/src/packets/game/c_player_info_update.rs b/azalea-protocol/src/packets/game/c_player_info_update.rs index 4a18233e..0bce5724 100644 --- a/azalea-protocol/src/packets/game/c_player_info_update.rs +++ b/azalea-protocol/src/packets/game/c_player_info_update.rs @@ -4,7 +4,7 @@ use std::{ }; use azalea_auth::game_profile::{GameProfile, GameProfileProperties}; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; +use azalea_buf::{AzBuf, AzBufVar, BufReadError}; use azalea_chat::FormattedText; use azalea_core::{bitset::FixedBitSet, game_type::GameMode}; use azalea_protocol_macros::ClientboundGamePacket; @@ -66,7 +66,7 @@ pub struct UpdateListOrderAction { pub list_order: i32, } -impl AzaleaRead for ClientboundPlayerInfoUpdate { +impl AzBuf for ClientboundPlayerInfoUpdate { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let actions = ActionEnumSet::azalea_read(buf)?; let mut entries = Vec::new(); @@ -116,9 +116,6 @@ impl AzaleaRead for ClientboundPlayerInfoUpdate { Ok(ClientboundPlayerInfoUpdate { actions, entries }) } -} - -impl AzaleaWrite for ClientboundPlayerInfoUpdate { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { self.actions.azalea_write(buf)?; @@ -181,7 +178,7 @@ pub struct ActionEnumSet { pub update_list_order: bool, } -impl AzaleaRead for ActionEnumSet { +impl AzBuf for ActionEnumSet { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let set = FixedBitSet::<7>::azalea_read(buf)?; Ok(ActionEnumSet { @@ -195,9 +192,6 @@ impl AzaleaRead for ActionEnumSet { update_list_order: set.index(7), }) } -} - -impl AzaleaWrite for ActionEnumSet { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let mut set = FixedBitSet::<7>::new(); if self.add_player { diff --git a/azalea-protocol/src/packets/game/c_section_blocks_update.rs b/azalea-protocol/src/packets/game/c_section_blocks_update.rs index 070d2a9e..8803e34a 100644 --- a/azalea-protocol/src/packets/game/c_section_blocks_update.rs +++ b/azalea-protocol/src/packets/game/c_section_blocks_update.rs @@ -1,7 +1,7 @@ use std::io::{self, Cursor, Write}; use azalea_block::BlockState; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; +use azalea_buf::{AzBuf, AzBufVar, BufReadError}; use azalea_core::position::{ChunkSectionBlockPos, ChunkSectionPos}; use azalea_protocol_macros::ClientboundGamePacket; @@ -17,7 +17,7 @@ pub struct BlockStateWithPosition { pub state: BlockState, } -impl AzaleaRead for BlockStateWithPosition { +impl AzBuf for BlockStateWithPosition { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let data = u64::azalea_read_var(buf)?; let position_part = data & 4095; @@ -31,9 +31,6 @@ impl AzaleaRead for BlockStateWithPosition { }; Ok(BlockStateWithPosition { pos, state }) } -} - -impl AzaleaWrite for BlockStateWithPosition { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let data = ((self.state.id() as u64) << 12) | ((u64::from(self.pos.x) << 8) | (u64::from(self.pos.z) << 4) | u64::from(self.pos.y)); diff --git a/azalea-protocol/src/packets/game/c_server_links.rs b/azalea-protocol/src/packets/game/c_server_links.rs index 75869492..433254d6 100644 --- a/azalea-protocol/src/packets/game/c_server_links.rs +++ b/azalea-protocol/src/packets/game/c_server_links.rs @@ -12,7 +12,7 @@ pub struct ClientboundServerLinks { mod tests { use std::io::Cursor; - use azalea_buf::AzaleaRead; + use azalea_buf::AzBuf; use super::*; diff --git a/azalea-protocol/src/packets/game/c_set_entity_data.rs b/azalea-protocol/src/packets/game/c_set_entity_data.rs index d9effc37..1b4b46cd 100644 --- a/azalea-protocol/src/packets/game/c_set_entity_data.rs +++ b/azalea-protocol/src/packets/game/c_set_entity_data.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; +use azalea_core::entity_id::MinecraftEntityId; use azalea_entity::EntityMetadataItems; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundSetEntityData { @@ -14,7 +14,7 @@ pub struct ClientboundSetEntityData { mod tests { use std::io::Cursor; - use azalea_buf::AzaleaRead; + use azalea_buf::AzBuf; use super::*; diff --git a/azalea-protocol/src/packets/game/c_set_equipment.rs b/azalea-protocol/src/packets/game/c_set_equipment.rs index 7d7ceac9..11ee8b3a 100644 --- a/azalea-protocol/src/packets/game/c_set_equipment.rs +++ b/azalea-protocol/src/packets/game/c_set_equipment.rs @@ -1,9 +1,9 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; +use azalea_buf::{AzBuf, BufReadError}; +use azalea_core::entity_id::MinecraftEntityId; use azalea_inventory::{ItemStack, components::EquipmentSlot}; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundSetEquipment { @@ -17,7 +17,7 @@ pub struct EquipmentSlots { pub slots: Vec<(EquipmentSlot, ItemStack)>, } -impl AzaleaRead for EquipmentSlots { +impl AzBuf for EquipmentSlots { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let mut slots = vec![]; @@ -38,8 +38,6 @@ impl AzaleaRead for EquipmentSlots { Ok(EquipmentSlots { slots }) } -} -impl AzaleaWrite for EquipmentSlots { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { for i in 0..self.slots.len() { let (equipment_slot, item) = &self.slots[i]; diff --git a/azalea-protocol/src/packets/game/c_set_objective.rs b/azalea-protocol/src/packets/game/c_set_objective.rs index dad4ccdf..237cd2ea 100644 --- a/azalea-protocol/src/packets/game/c_set_objective.rs +++ b/azalea-protocol/src/packets/game/c_set_objective.rs @@ -1,6 +1,6 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite}; +use azalea_buf::AzBuf; use azalea_chat::{FormattedText, numbers::NumberFormat}; use azalea_core::objectives::ObjectiveCriteria; use azalea_protocol_macros::ClientboundGamePacket; @@ -33,7 +33,7 @@ pub enum Method { }, } -impl AzaleaRead for Method { +impl AzBuf for Method { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> { let kind = MethodKind::azalea_read(buf)?; match kind { @@ -50,9 +50,6 @@ impl AzaleaRead for Method { }), } } -} - -impl AzaleaWrite for Method { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { match self { Method::Add { diff --git a/azalea-protocol/src/packets/game/c_set_player_team.rs b/azalea-protocol/src/packets/game/c_set_player_team.rs index e8c85886..a1105231 100644 --- a/azalea-protocol/src/packets/game/c_set_player_team.rs +++ b/azalea-protocol/src/packets/game/c_set_player_team.rs @@ -50,7 +50,7 @@ type PlayerList = Vec<String>; mod tests { use std::io::Cursor; - use azalea_buf::AzaleaRead; + use azalea_buf::AzBuf; use crate::packets::game::ClientboundSetPlayerTeam; diff --git a/azalea-protocol/src/packets/game/c_sound.rs b/azalea-protocol/src/packets/game/c_sound.rs index a380532c..e2a4f513 100644 --- a/azalea-protocol/src/packets/game/c_sound.rs +++ b/azalea-protocol/src/packets/game/c_sound.rs @@ -34,7 +34,7 @@ pub enum SoundSource { mod tests { use std::io::Cursor; - use azalea_buf::AzaleaRead; + use azalea_buf::AzBuf; use crate::packets::game::ClientboundSound; diff --git a/azalea-protocol/src/packets/game/c_stop_sound.rs b/azalea-protocol/src/packets/game/c_stop_sound.rs index 6225a759..0afba2c7 100644 --- a/azalea-protocol/src/packets/game/c_stop_sound.rs +++ b/azalea-protocol/src/packets/game/c_stop_sound.rs @@ -1,6 +1,6 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError}; +use azalea_buf::{AzBuf, BufReadError}; use azalea_core::bitset::FixedBitSet; use azalea_protocol_macros::ClientboundGamePacket; use azalea_registry::identifier::Identifier; @@ -13,7 +13,7 @@ pub struct ClientboundStopSound { pub name: Option<Identifier>, } -impl AzaleaRead for ClientboundStopSound { +impl AzBuf for ClientboundStopSound { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let set = FixedBitSet::<2>::azalea_read(buf)?; let source = if set.index(0) { @@ -29,9 +29,6 @@ impl AzaleaRead for ClientboundStopSound { Ok(Self { source, name }) } -} - -impl AzaleaWrite for ClientboundStopSound { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let mut set = FixedBitSet::<2>::new(); if self.source.is_some() { diff --git a/azalea-protocol/src/packets/game/c_system_chat.rs b/azalea-protocol/src/packets/game/c_system_chat.rs index 491825f4..a72c003e 100644 --- a/azalea-protocol/src/packets/game/c_system_chat.rs +++ b/azalea-protocol/src/packets/game/c_system_chat.rs @@ -12,7 +12,7 @@ pub struct ClientboundSystemChat { mod tests { use std::io::Cursor; - use azalea_buf::AzaleaRead; + use azalea_buf::AzBuf; use super::*; diff --git a/azalea-protocol/src/packets/game/c_tab_list.rs b/azalea-protocol/src/packets/game/c_tab_list.rs index 9a360dac..160c1a1e 100644 --- a/azalea-protocol/src/packets/game/c_tab_list.rs +++ b/azalea-protocol/src/packets/game/c_tab_list.rs @@ -12,7 +12,7 @@ pub struct ClientboundTabList { mod tests { use std::io::Cursor; - use azalea_buf::AzaleaRead; + use azalea_buf::AzBuf; use super::*; diff --git a/azalea-protocol/src/packets/game/c_update_advancements.rs b/azalea-protocol/src/packets/game/c_update_advancements.rs index 24baebc5..e4cc745a 100644 --- a/azalea-protocol/src/packets/game/c_update_advancements.rs +++ b/azalea-protocol/src/packets/game/c_update_advancements.rs @@ -3,7 +3,7 @@ use std::{ io::{self, Cursor, Write}, }; -use azalea_buf::{AzBuf, AzaleaWrite}; +use azalea_buf::AzBuf; use azalea_chat::FormattedText; use azalea_inventory::ItemStack; use azalea_protocol_macros::ClientboundGamePacket; @@ -40,7 +40,37 @@ pub struct DisplayInfo { pub y: f32, } -impl AzaleaWrite for DisplayInfo { +impl AzBuf for DisplayInfo { + fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> { + let title = AzBuf::azalea_read(buf)?; + let description = AzBuf::azalea_read(buf)?; + let icon = AzBuf::azalea_read(buf)?; + let frame = AzBuf::azalea_read(buf)?; + + let data = u32::azalea_read(buf)?; + let has_background = (data & 0b1) != 0; + let show_toast = (data & 0b10) != 0; + let hidden = (data & 0b100) != 0; + + let background = if has_background { + Some(Identifier::azalea_read(buf)?) + } else { + None + }; + let x = AzBuf::azalea_read(buf)?; + let y = AzBuf::azalea_read(buf)?; + Ok(DisplayInfo { + title, + description, + icon, + frame, + show_toast, + hidden, + background, + x, + y, + }) + } fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { self.title.azalea_write(buf)?; self.description.azalea_write(buf)?; @@ -67,38 +97,6 @@ impl AzaleaWrite for DisplayInfo { Ok(()) } } -impl azalea_buf::AzaleaRead for DisplayInfo { - fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> { - let title = azalea_buf::AzaleaRead::azalea_read(buf)?; - let description = azalea_buf::AzaleaRead::azalea_read(buf)?; - let icon = azalea_buf::AzaleaRead::azalea_read(buf)?; - let frame = azalea_buf::AzaleaRead::azalea_read(buf)?; - - let data = u32::azalea_read(buf)?; - let has_background = (data & 0b1) != 0; - let show_toast = (data & 0b10) != 0; - let hidden = (data & 0b100) != 0; - - let background = if has_background { - Some(Identifier::azalea_read(buf)?) - } else { - None - }; - let x = azalea_buf::AzaleaRead::azalea_read(buf)?; - let y = azalea_buf::AzaleaRead::azalea_read(buf)?; - Ok(DisplayInfo { - title, - description, - icon, - frame, - show_toast, - hidden, - background, - x, - y, - }) - } -} #[derive(AzBuf, Clone, Copy, Debug, PartialEq)] pub enum FrameType { @@ -122,7 +120,7 @@ pub struct AdvancementHolder { #[cfg(test)] mod tests { - use azalea_buf::{AzaleaRead, AzaleaWrite}; + use azalea_buf::AzBuf; use super::*; diff --git a/azalea-protocol/src/packets/game/c_waypoint.rs b/azalea-protocol/src/packets/game/c_waypoint.rs index 38a160e9..45f4ff6a 100644 --- a/azalea-protocol/src/packets/game/c_waypoint.rs +++ b/azalea-protocol/src/packets/game/c_waypoint.rs @@ -1,6 +1,6 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; +use azalea_buf::{AzBuf, BufReadError}; use azalea_core::{color::RgbColor, position::Vec3i}; use azalea_protocol_macros::ClientboundGamePacket; use azalea_registry::identifier::Identifier; @@ -37,7 +37,7 @@ pub struct WaypointIcon { pub style: Identifier, pub color: Option<RgbColor>, } -impl AzaleaWrite for WaypointIcon { +impl AzBuf for WaypointIcon { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> { self.style.azalea_write(buf)?; let color = self.color.map(|c| CompactRgbColor { @@ -48,8 +48,6 @@ impl AzaleaWrite for WaypointIcon { color.azalea_write(buf)?; Ok(()) } -} -impl AzaleaRead for WaypointIcon { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let style = Identifier::azalea_read(buf)?; let color = Option::<CompactRgbColor>::azalea_read(buf)?; diff --git a/azalea-protocol/src/packets/game/s_interact.rs b/azalea-protocol/src/packets/game/s_interact.rs index d368354f..bd04e09d 100644 --- a/azalea-protocol/src/packets/game/s_interact.rs +++ b/azalea-protocol/src/packets/game/s_interact.rs @@ -1,9 +1,11 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar}; -use azalea_core::position::Vec3; +use azalea_buf::{AzBuf, AzBufVar}; +use azalea_core::{ + entity_id::MinecraftEntityId, + position::{Vec3, Vec3f32}, +}; use azalea_protocol_macros::ServerboundGamePacket; -use azalea_core::entity_id::MinecraftEntityId; use crate::packets::BufReadError; @@ -28,29 +30,7 @@ pub enum ActionType { }, } -impl AzaleaWrite for ActionType { - fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { - match self { - ActionType::Interact { hand } => { - 0u32.azalea_write_var(buf)?; - hand.azalea_write(buf)?; - } - ActionType::Attack => { - 1u32.azalea_write_var(buf)?; - } - ActionType::InteractAt { location, hand } => { - 2u32.azalea_write_var(buf)?; - (location.x as f32).azalea_write(buf)?; - (location.y as f32).azalea_write(buf)?; - (location.z as f32).azalea_write(buf)?; - hand.azalea_write(buf)?; - } - } - Ok(()) - } -} - -impl AzaleaRead for ActionType { +impl AzBuf for ActionType { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let action_type = u32::azalea_read_var(buf)?; match action_type { @@ -60,16 +40,10 @@ impl AzaleaRead for ActionType { } 1 => Ok(ActionType::Attack), 2 => { - let x = f32::azalea_read(buf)?; - let y = f32::azalea_read(buf)?; - let z = f32::azalea_read(buf)?; + let pos = Vec3f32::azalea_read(buf)?; let hand = InteractionHand::azalea_read(buf)?; Ok(ActionType::InteractAt { - location: Vec3 { - x: f64::from(x), - y: f64::from(y), - z: f64::from(z), - }, + location: Vec3::from(pos), hand, }) } @@ -78,6 +52,25 @@ impl AzaleaRead for ActionType { }), } } + fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { + match self { + ActionType::Interact { hand } => { + 0u32.azalea_write_var(buf)?; + hand.azalea_write(buf)?; + } + ActionType::Attack => { + 1u32.azalea_write_var(buf)?; + } + ActionType::InteractAt { location, hand } => { + 2u32.azalea_write_var(buf)?; + (location.x as f32).azalea_write(buf)?; + (location.y as f32).azalea_write(buf)?; + (location.z as f32).azalea_write(buf)?; + hand.azalea_write(buf)?; + } + } + Ok(()) + } } #[derive(AzBuf, Clone, Copy, Debug, Default, PartialEq)] diff --git a/azalea-protocol/src/packets/game/s_player_abilities.rs b/azalea-protocol/src/packets/game/s_player_abilities.rs index 2eff36cb..59e9ab93 100644 --- a/azalea-protocol/src/packets/game/s_player_abilities.rs +++ b/azalea-protocol/src/packets/game/s_player_abilities.rs @@ -1,6 +1,6 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzaleaRead, AzaleaWrite}; +use azalea_buf::AzBuf; use azalea_core::bitset::FixedBitSet; use azalea_protocol_macros::ServerboundGamePacket; @@ -11,16 +11,13 @@ pub struct ServerboundPlayerAbilities { pub is_flying: bool, } -impl AzaleaRead for ServerboundPlayerAbilities { +impl AzBuf for ServerboundPlayerAbilities { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let set = FixedBitSet::<2>::azalea_read(buf)?; Ok(Self { is_flying: set.index(1), }) } -} - -impl AzaleaWrite for ServerboundPlayerAbilities { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let mut set = FixedBitSet::<2>::new(); if self.is_flying { diff --git a/azalea-protocol/src/packets/game/s_player_input.rs b/azalea-protocol/src/packets/game/s_player_input.rs index e92d6101..46ebbcf6 100644 --- a/azalea-protocol/src/packets/game/s_player_input.rs +++ b/azalea-protocol/src/packets/game/s_player_input.rs @@ -1,7 +1,6 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::BufReadError; -use azalea_buf::{AzaleaRead, AzaleaWrite}; +use azalea_buf::{AzBuf, BufReadError}; use azalea_core::bitset::FixedBitSet; use azalea_protocol_macros::ServerboundGamePacket; @@ -16,7 +15,7 @@ pub struct ServerboundPlayerInput { pub sprint: bool, } -impl AzaleaRead for ServerboundPlayerInput { +impl AzBuf for ServerboundPlayerInput { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let set = FixedBitSet::<7>::azalea_read(buf)?; Ok(Self { @@ -29,9 +28,6 @@ impl AzaleaRead for ServerboundPlayerInput { sprint: set.index(6), }) } -} - -impl AzaleaWrite for ServerboundPlayerInput { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let mut set = FixedBitSet::<7>::new(); if self.forward { diff --git a/azalea-protocol/src/packets/game/s_seen_advancements.rs b/azalea-protocol/src/packets/game/s_seen_advancements.rs index 7e001b7f..cdb12dd4 100644 --- a/azalea-protocol/src/packets/game/s_seen_advancements.rs +++ b/azalea-protocol/src/packets/game/s_seen_advancements.rs @@ -1,8 +1,8 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite}; -use azalea_registry::identifier::Identifier; +use azalea_buf::AzBuf; use azalea_protocol_macros::ServerboundGamePacket; +use azalea_registry::identifier::Identifier; use crate::packets::BufReadError; @@ -18,7 +18,7 @@ pub enum Action { ClosedScreen = 1, } -impl AzaleaRead for ServerboundSeenAdvancements { +impl AzBuf for ServerboundSeenAdvancements { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let action = Action::azalea_read(buf)?; let tab = if action == Action::OpenedTab { @@ -28,9 +28,6 @@ impl AzaleaRead for ServerboundSeenAdvancements { }; Ok(Self { action, tab }) } -} - -impl AzaleaWrite for ServerboundSeenAdvancements { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { self.action.azalea_write(buf)?; if let Some(tab) = &self.tab { diff --git a/azalea-protocol/src/packets/game/s_set_command_block.rs b/azalea-protocol/src/packets/game/s_set_command_block.rs index 17701171..771e8476 100644 --- a/azalea-protocol/src/packets/game/s_set_command_block.rs +++ b/azalea-protocol/src/packets/game/s_set_command_block.rs @@ -1,11 +1,9 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzBuf, AzaleaRead, BufReadError}; +use azalea_buf::{AzBuf, BufReadError}; use azalea_core::{bitset::FixedBitSet, position::BlockPos}; use azalea_protocol_macros::ServerboundGamePacket; -use crate::packets::AzaleaWrite; - #[derive(Clone, Debug, PartialEq, ServerboundGamePacket)] pub struct ServerboundSetCommandBlock { pub pos: BlockPos, @@ -24,7 +22,7 @@ pub enum Mode { Redstone = 2, } -impl AzaleaRead for ServerboundSetCommandBlock { +impl AzBuf for ServerboundSetCommandBlock { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let pos = BlockPos::azalea_read(buf)?; let command = String::azalea_read(buf)?; @@ -40,9 +38,6 @@ impl AzaleaRead for ServerboundSetCommandBlock { automatic: set.index(2), }) } -} - -impl AzaleaWrite for ServerboundSetCommandBlock { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { self.pos.azalea_write(buf)?; self.command.azalea_write(buf)?; diff --git a/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs b/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs index a19b8a82..9bd15ceb 100644 --- a/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs +++ b/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs @@ -3,13 +3,11 @@ use std::{ io::{Cursor, Write}, }; -use azalea_buf::{AzBuf, AzaleaRead}; +use azalea_buf::{AzBuf, BufReadError}; use azalea_core::position::BlockPos; use azalea_protocol_macros::ServerboundGamePacket; use azalea_registry::identifier::Identifier; -use crate::packets::{AzaleaWrite, BufReadError}; - #[derive(AzBuf, Clone, Debug, PartialEq, ServerboundGamePacket)] pub struct ServerboundSetJigsawBlock { pub pos: BlockPos, @@ -29,7 +27,7 @@ pub enum JointType { Aligned, } -impl AzaleaRead for JointType { +impl AzBuf for JointType { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let name = String::azalea_read(buf)?; match name.as_str() { @@ -38,9 +36,6 @@ impl AzaleaRead for JointType { _ => Err(BufReadError::UnexpectedStringEnumVariant { id: name }), } } -} - -impl AzaleaWrite for JointType { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { match self { JointType::Rollable => "rollable".to_owned().azalea_write(buf)?, diff --git a/azalea-protocol/src/packets/game/s_set_structure_block.rs b/azalea-protocol/src/packets/game/s_set_structure_block.rs index c4387b0f..d16e520c 100644 --- a/azalea-protocol/src/packets/game/s_set_structure_block.rs +++ b/azalea-protocol/src/packets/game/s_set_structure_block.rs @@ -1,6 +1,6 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite}; +use azalea_buf::AzBuf; use azalea_core::{bitset::FixedBitSet, position::BlockPos}; use azalea_protocol_macros::ServerboundGamePacket; @@ -70,7 +70,7 @@ pub struct Flags { pub show_bounding_box: bool, } -impl AzaleaRead for Flags { +impl AzBuf for Flags { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let set = FixedBitSet::<3>::azalea_read(buf)?; Ok(Self { @@ -79,9 +79,6 @@ impl AzaleaRead for Flags { show_bounding_box: set.index(2), }) } -} - -impl AzaleaWrite for Flags { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let mut set = FixedBitSet::<3>::new(); if self.ignore_entities { diff --git a/azalea-protocol/src/packets/game/s_use_item_on.rs b/azalea-protocol/src/packets/game/s_use_item_on.rs index 22d3c861..cf1866a5 100644 --- a/azalea-protocol/src/packets/game/s_use_item_on.rs +++ b/azalea-protocol/src/packets/game/s_use_item_on.rs @@ -1,10 +1,10 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; +use azalea_buf::{AzBuf, BufReadError}; use azalea_core::{ direction::Direction, hit_result::BlockHitResult, - position::{BlockPos, Vec3}, + position::{BlockPos, Vec3, Vec3f32}, }; use azalea_protocol_macros::ServerboundGamePacket; @@ -35,49 +35,38 @@ pub struct BlockHit { pub world_border: bool, } -impl AzaleaWrite for BlockHit { - fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { - self.block_pos.azalea_write(buf)?; - self.direction.azalea_write(buf)?; - f32::azalea_write( - &((self.location.x - f64::from(self.block_pos.x)) as f32), - buf, - )?; - f32::azalea_write( - &((self.location.y - f64::from(self.block_pos.y)) as f32), - buf, - )?; - f32::azalea_write( - &((self.location.z - f64::from(self.block_pos.z)) as f32), - buf, - )?; - self.inside.azalea_write(buf)?; - self.world_border.azalea_write(buf)?; - Ok(()) - } -} - -impl AzaleaRead for BlockHit { +impl AzBuf for BlockHit { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let block_pos = BlockPos::azalea_read(buf)?; let direction = Direction::azalea_read(buf)?; - let cursor_x = f32::azalea_read(buf)?; - let cursor_y = f32::azalea_read(buf)?; - let cursor_z = f32::azalea_read(buf)?; + let cursor = Vec3f32::azalea_read(buf)?; let inside = bool::azalea_read(buf)?; let world_border = bool::azalea_read(buf)?; Ok(Self { block_pos, direction, location: Vec3 { - x: f64::from(block_pos.x) + f64::from(cursor_x), - y: f64::from(block_pos.y) + f64::from(cursor_y), - z: f64::from(block_pos.z) + f64::from(cursor_z), + x: f64::from(block_pos.x) + f64::from(cursor.x), + y: f64::from(block_pos.y) + f64::from(cursor.y), + z: f64::from(block_pos.z) + f64::from(cursor.z), }, inside, world_border, }) } + fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { + self.block_pos.azalea_write(buf)?; + self.direction.azalea_write(buf)?; + let cursor = Vec3 { + x: self.location.x - f64::from(self.block_pos.x), + y: self.location.y - f64::from(self.block_pos.y), + z: self.location.z - f64::from(self.block_pos.z), + }; + Vec3f32::from(cursor).azalea_write(buf)?; + self.inside.azalea_write(buf)?; + self.world_border.azalea_write(buf)?; + Ok(()) + } } impl From<&BlockHitResult> for BlockHit { diff --git a/azalea-protocol/src/packets/login/c_login_disconnect.rs b/azalea-protocol/src/packets/login/c_login_disconnect.rs index 950d5e5c..e6e6b33a 100644 --- a/azalea-protocol/src/packets/login/c_login_disconnect.rs +++ b/azalea-protocol/src/packets/login/c_login_disconnect.rs @@ -1,6 +1,6 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError}; +use azalea_buf::{AzBuf, BufReadError}; use azalea_chat::FormattedText; use azalea_protocol_macros::ClientboundLoginPacket; use serde::{Deserialize, Serialize}; @@ -11,7 +11,7 @@ pub struct ClientboundLoginDisconnect { pub reason: FormattedText, } -impl AzaleaRead for ClientboundLoginDisconnect { +impl AzBuf for ClientboundLoginDisconnect { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<ClientboundLoginDisconnect, BufReadError> { let disconnect_string = String::azalea_read(buf)?; trace!("Got disconnect packet with string: {disconnect_string:?}"); @@ -29,9 +29,6 @@ impl AzaleaRead for ClientboundLoginDisconnect { reason: FormattedText::deserialize(disconnect_json)?, }) } -} - -impl AzaleaWrite for ClientboundLoginDisconnect { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let status_string = FormattedText::serialize(&self.reason, serde_json::value::Serializer) .unwrap() diff --git a/azalea-protocol/src/packets/login/s_hello.rs b/azalea-protocol/src/packets/login/s_hello.rs index a7a9f4ee..075cd99c 100644 --- a/azalea-protocol/src/packets/login/s_hello.rs +++ b/azalea-protocol/src/packets/login/s_hello.rs @@ -13,7 +13,7 @@ pub struct ServerboundHello { mod tests { use std::io::Cursor; - use azalea_buf::{AzaleaRead, AzaleaWrite}; + use azalea_buf::AzBuf; use super::*; diff --git a/azalea-protocol/src/packets/mod.rs b/azalea-protocol/src/packets/mod.rs index 9dd14311..202bc4ee 100644 --- a/azalea-protocol/src/packets/mod.rs +++ b/azalea-protocol/src/packets/mod.rs @@ -7,7 +7,7 @@ pub mod status; use std::io::{self, Cursor, Write}; -use azalea_buf::{AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; +use azalea_buf::{AzBuf, AzBufVar, BufReadError}; use crate::read::ReadPacketError; @@ -89,15 +89,12 @@ impl From<ClientIntention> for ConnectionProtocol { } } -impl azalea_buf::AzaleaRead for ClientIntention { +impl AzBuf for ClientIntention { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let id = i32::azalea_read_var(buf)?; id.try_into() .map_err(|_| BufReadError::UnexpectedEnumVariant { id }) } -} - -impl AzaleaWrite for ClientIntention { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { (*self as i32).azalea_write_var(buf) } diff --git a/azalea-protocol/src/packets/status/c_status_response.rs b/azalea-protocol/src/packets/status/c_status_response.rs index 933b6c2c..ef283643 100644 --- a/azalea-protocol/src/packets/status/c_status_response.rs +++ b/azalea-protocol/src/packets/status/c_status_response.rs @@ -1,6 +1,6 @@ use std::io::{self, Cursor, Write}; -use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError}; +use azalea_buf::{AzBuf, BufReadError}; use azalea_chat::FormattedText; use azalea_protocol_macros::ClientboundStatusPacket; use serde::{Deserialize, Serialize}; @@ -41,16 +41,13 @@ pub struct ClientboundStatusResponse { pub enforces_secure_chat: Option<bool>, } -impl AzaleaRead for ClientboundStatusResponse { +impl AzBuf for ClientboundStatusResponse { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<ClientboundStatusResponse, BufReadError> { let status_string = String::azalea_read(buf)?; let status_json: serde_json::Value = serde_json::from_str(status_string.as_str())?; Ok(ClientboundStatusResponse::deserialize(status_json)?) } -} - -impl AzaleaWrite for ClientboundStatusResponse { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { let status_string = ClientboundStatusResponse::serialize(self, Serializer) .unwrap() diff --git a/azalea-protocol/src/read.rs b/azalea-protocol/src/read.rs index 5ec7f3b9..9fbb7d61 100644 --- a/azalea-protocol/src/read.rs +++ b/azalea-protocol/src/read.rs @@ -9,7 +9,7 @@ use std::{ sync::LazyLock, }; -use azalea_buf::{AzaleaReadVar, BufReadError}; +use azalea_buf::{AzBufVar, BufReadError}; use azalea_crypto::Aes128CfbDec; use flate2::read::ZlibDecoder; use futures::StreamExt; @@ -406,7 +406,7 @@ where mod tests { use std::io::Cursor; - use azalea_buf::AzaleaRead as _; + use azalea_buf::AzBuf as _; use crate::{packets::game::ClientboundGamePacket, read::deserialize_packet}; diff --git a/azalea-protocol/src/write.rs b/azalea-protocol/src/write.rs index a14463eb..aaa74bd8 100644 --- a/azalea-protocol/src/write.rs +++ b/azalea-protocol/src/write.rs @@ -5,7 +5,7 @@ use std::{ io::{self, Read}, }; -use azalea_buf::AzaleaWriteVar; +use azalea_buf::AzBufVar; use azalea_crypto::Aes128CfbEnc; use flate2::{Compression, bufread::ZlibEncoder}; use thiserror::Error; |
