diff options
| author | mat <github@matdoes.dev> | 2022-05-01 13:51:59 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-05-01 13:51:59 -0500 |
| commit | 9dacd90abcfaa62ade1e4f130ed53da2c9facdbc (patch) | |
| tree | 68a4956399a6d509a5d8ae790235996a5a24024e /azalea-protocol/src/mc_buf/write.rs | |
| parent | 4b1cfd1cf899fbbc3de8f72cbb160695c1e9ae70 (diff) | |
| download | azalea-drasl-9dacd90abcfaa62ade1e4f130ed53da2c9facdbc.tar.xz | |
clientbound_add_entity_packet & clientbound_set_entity_data_packet
Diffstat (limited to 'azalea-protocol/src/mc_buf/write.rs')
| -rwxr-xr-x | azalea-protocol/src/mc_buf/write.rs | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs index 4c7ac60c..e5437ae8 100755 --- a/azalea-protocol/src/mc_buf/write.rs +++ b/azalea-protocol/src/mc_buf/write.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use azalea_chat::component::Component; use azalea_core::{ difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation, - serializable_uuid::SerializableUuid, Slot, + serializable_uuid::SerializableUuid, BlockPos, Direction, Slot, }; use byteorder::{BigEndian, WriteBytesExt}; use std::io::Write; @@ -336,21 +336,8 @@ impl McBufWritable for Option<GameType> { } // Option<String> -impl McBufWritable for Option<String> { - fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { - if let Some(s) = self { - buf.write_boolean(true)?; - buf.write_utf(s)?; - } else { - buf.write_boolean(false)?; - }; - Ok(()) - } -} - -// Option<Component> -impl McBufWritable for Option<Component> { - fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { +impl<T: McBufWritable> McBufWritable for Option<T> { + default fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { if let Some(s) = self { buf.write_boolean(true)?; s.write_into(buf)?; @@ -418,3 +405,21 @@ impl McBufWritable for Uuid { Ok(()) } } + +// BlockPos +impl McBufWritable for BlockPos { + fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { + buf.write_long( + (((self.x & 0x3FFFFFF) as i64) << 38) + | (((self.z & 0x3FFFFFF) as i64) << 12) + | ((self.y & 0xFFF) as i64), + ) + } +} + +// Direction +impl McBufWritable for Direction { + fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { + buf.write_varint(*self as i32) + } +} |
