diff options
| author | mat <github@matdoes.dev> | 2022-04-27 18:00:50 +0000 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-04-27 18:00:50 +0000 |
| commit | 9b50886c30f3e9129e054b019581264c9e6cadaf (patch) | |
| tree | 8dfcc5bb8980a86d650a0d3d7afb705624b818c6 /azalea-protocol/src/mc_buf/write.rs | |
| parent | 60d1fa50c32c202dd04895caa51172948a4760b6 (diff) | |
| download | azalea-drasl-9b50886c30f3e9129e054b019581264c9e6cadaf.tar.xz | |
player info packet
Diffstat (limited to 'azalea-protocol/src/mc_buf/write.rs')
| -rwxr-xr-x | azalea-protocol/src/mc_buf/write.rs | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs index b57ad786..bd5e3f52 100755 --- a/azalea-protocol/src/mc_buf/write.rs +++ b/azalea-protocol/src/mc_buf/write.rs @@ -2,10 +2,12 @@ use super::{UnsizedByteArray, MAX_STRING_LENGTH}; use async_trait::async_trait; use azalea_chat::component::Component; use azalea_core::{ - difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation, Slot, + difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation, + serializable_uuid::SerializableUuid, Slot, }; use byteorder::{BigEndian, WriteBytesExt}; use std::io::Write; +use uuid::Uuid; #[async_trait] pub trait Writable { @@ -43,6 +45,7 @@ pub trait Writable { ) -> Result<(), std::io::Error>; fn write_float(&mut self, n: f32) -> Result<(), std::io::Error>; fn write_double(&mut self, n: f64) -> Result<(), std::io::Error>; + fn write_uuid(&mut self, uuid: &Uuid) -> Result<(), std::io::Error>; } #[async_trait] @@ -163,6 +166,15 @@ impl Writable for Vec<u8> { ) -> Result<(), std::io::Error> { self.write_utf(&location.to_string()) } + + fn write_uuid(&mut self, uuid: &Uuid) -> Result<(), std::io::Error> { + let [a, b, c, d] = uuid.to_int_array(); + a.write_into(self)?; + b.write_into(self)?; + c.write_into(self)?; + d.write_into(self)?; + Ok(()) + } } pub trait McBufWritable @@ -317,6 +329,32 @@ 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> { + if let Some(s) = self { + buf.write_boolean(true)?; + s.write_into(buf)?; + } else { + buf.write_boolean(false)?; + }; + Ok(()) + } +} + // azalea_nbt::Tag impl McBufWritable for azalea_nbt::Tag { fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { @@ -365,3 +403,12 @@ impl McBufWritable for Slot { Ok(()) } } + +// Slot +impl McBufWritable for Uuid { + fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { + buf.write_uuid(self)?; + + Ok(()) + } +} |
