From fcb5bdf04241082d08b1ecc083745d6d97af61a9 Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 5 Sep 2022 11:44:48 -0500 Subject: use az-registry in az-protocol --- azalea-block/src/lib.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'azalea-block/src') 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 for BlockState { } } +impl McBufReadable for BlockState { + fn read_from(buf: &mut impl Read) -> Result { + 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::*; -- cgit v1.2.3