diff options
| author | mat <github@matdoes.dev> | 2022-01-03 00:14:41 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-01-03 00:14:41 -0600 |
| commit | 96eba2b39a596dd19c29a93aaa3b5bb9b700ba62 (patch) | |
| tree | 9a585864e81fd01da15bdc9ca5e4e3e7a69eb1f4 /azalea-protocol/src/mc_buf/read.rs | |
| parent | 394f996df27bedc68be6c1f9e9764e8f78ba6282 (diff) | |
| download | azalea-drasl-96eba2b39a596dd19c29a93aaa3b5bb9b700ba62.tar.xz | |
difficulty packet
Diffstat (limited to 'azalea-protocol/src/mc_buf/read.rs')
| -rw-r--r-- | azalea-protocol/src/mc_buf/read.rs | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/azalea-protocol/src/mc_buf/read.rs b/azalea-protocol/src/mc_buf/read.rs index 5127860e..0fa1d099 100644 --- a/azalea-protocol/src/mc_buf/read.rs +++ b/azalea-protocol/src/mc_buf/read.rs @@ -1,5 +1,8 @@ use async_trait::async_trait; -use azalea_core::{game_type::GameType, resource_location::ResourceLocation}; +use azalea_core::{ + difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation, +}; +use num_traits::FromPrimitive; use tokio::io::{AsyncRead, AsyncReadExt}; use super::MAX_STRING_LENGTH; @@ -338,6 +341,28 @@ impl McBufReadable for bool { } } +// u8 +#[async_trait] +impl McBufReadable for u8 { + async fn read_into<R>(buf: &mut R) -> Result<Self, String> + where + R: AsyncRead + std::marker::Unpin + std::marker::Send, + { + buf.read_byte().await + } +} + +// i8 +#[async_trait] +impl McBufReadable for i8 { + async fn read_into<R>(buf: &mut R) -> Result<Self, String> + where + R: AsyncRead + std::marker::Unpin + std::marker::Send, + { + buf.read_byte().await.map(|i| i as i8) + } +} + // GameType #[async_trait] impl McBufReadable for GameType { @@ -386,3 +411,14 @@ impl McBufReadable for azalea_nbt::Tag { buf.read_nbt().await } } + +// Difficulty +#[async_trait] +impl McBufReadable for Difficulty { + async fn read_into<R>(buf: &mut R) -> Result<Self, String> + where + R: AsyncRead + std::marker::Unpin + std::marker::Send, + { + Ok(Difficulty::by_id(u8::read_into(buf).await?)) + } +} |
