diff options
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::*; |
