diff options
| author | mat <github@matdoes.dev> | 2022-09-05 11:44:48 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-09-05 11:44:48 -0500 |
| commit | fcb5bdf04241082d08b1ecc083745d6d97af61a9 (patch) | |
| tree | b41a76923e299dc60802d676a319c85f9c76858c /azalea-block/src | |
| parent | 4301a2f2d4c711fd50a54cf065079c42b89a72f2 (diff) | |
| download | azalea-drasl-fcb5bdf04241082d08b1ecc083745d6d97af61a9.tar.xz | |
use az-registry in az-protocol
Diffstat (limited to 'azalea-block/src')
| -rw-r--r-- | azalea-block/src/lib.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/azalea-block/src/lib.rs b/azalea-block/src/lib.rs index 3eb86a90..fdcfe631 100644 --- a/azalea-block/src/lib.rs +++ b/azalea-block/src/lib.rs @@ -1,10 +1,13 @@ mod behavior; mod blocks; +use azalea_buf::{BufReadError, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable}; pub use behavior::BlockBehavior; pub use blocks::*; - -use std::mem; +use std::{ + io::{Read, Write}, + mem, +}; impl BlockState { /// Transmutes a u32 to a block state. @@ -35,6 +38,20 @@ impl TryFrom<u32> for BlockState { } } +impl McBufReadable for BlockState { + fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> { + let state_id = u32::var_read_from(buf)?; + Self::try_from(state_id).map_err(|_| BufReadError::UnexpectedEnumVariant { + id: state_id as i32, + }) + } +} +impl McBufWritable for BlockState { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + u32::var_write_into(&(*self as u32), buf) + } +} + #[cfg(test)] mod tests { use super::*; |
