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/read.rs | |
| parent | 60d1fa50c32c202dd04895caa51172948a4760b6 (diff) | |
| download | azalea-drasl-9b50886c30f3e9129e054b019581264c9e6cadaf.tar.xz | |
player info packet
Diffstat (limited to 'azalea-protocol/src/mc_buf/read.rs')
| -rwxr-xr-x | azalea-protocol/src/mc_buf/read.rs | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/azalea-protocol/src/mc_buf/read.rs b/azalea-protocol/src/mc_buf/read.rs index d3382e0a..e90b4b10 100755 --- a/azalea-protocol/src/mc_buf/read.rs +++ b/azalea-protocol/src/mc_buf/read.rs @@ -1,11 +1,12 @@ use async_trait::async_trait; use azalea_chat::component::Component; use azalea_core::{ - difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation, Slot, - SlotData, + difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation, + serializable_uuid::SerializableUuid, Slot, SlotData, }; use serde::Deserialize; use tokio::io::{AsyncRead, AsyncReadExt}; +use uuid::Uuid; use super::{UnsizedByteArray, MAX_STRING_LENGTH}; @@ -29,6 +30,7 @@ pub trait Readable { async fn read_short(&mut self) -> Result<i16, String>; async fn read_float(&mut self) -> Result<f32, String>; async fn read_double(&mut self) -> Result<f64, String>; + async fn read_uuid(&mut self) -> Result<Uuid, String>; } #[async_trait] @@ -207,6 +209,15 @@ where Err(_) => Err("Error reading double".to_string()), } } + + async fn read_uuid(&mut self) -> Result<Uuid, String> { + Ok(Uuid::from_int_array([ + self.read_int().await? as u32, + self.read_int().await? as u32, + self.read_int().await? as u32, + self.read_int().await? as u32, + ])) + } } #[async_trait] @@ -439,6 +450,37 @@ impl McBufReadable for Option<GameType> { } } +// Option<String> +#[async_trait] +impl McBufReadable for Option<String> { + async fn read_into<R>(buf: &mut R) -> Result<Self, String> + where + R: AsyncRead + std::marker::Unpin + std::marker::Send, + { + let present = buf.read_boolean().await?; + Ok(if present { + Some(buf.read_utf().await?) + } else { + None + }) + } +} +// Option<Component> +#[async_trait] +impl McBufReadable for Option<Component> { + async fn read_into<R>(buf: &mut R) -> Result<Self, String> + where + R: AsyncRead + std::marker::Unpin + std::marker::Send, + { + let present = buf.read_boolean().await?; + Ok(if present { + Some(Component::read_into(buf).await?) + } else { + None + }) + } +} + // azalea_nbt::Tag #[async_trait] impl McBufReadable for azalea_nbt::Tag { @@ -493,3 +535,14 @@ impl McBufReadable for Slot { Ok(Slot::Present(SlotData { id, count, nbt })) } } + +// Uuid +#[async_trait] +impl McBufReadable for Uuid { + async fn read_into<R>(buf: &mut R) -> Result<Self, String> + where + R: AsyncRead + std::marker::Unpin + std::marker::Send, + { + buf.read_uuid().await + } +} |
