diff options
Diffstat (limited to 'azalea-block')
| -rw-r--r-- | azalea-block/Cargo.toml | 1 | ||||
| -rw-r--r-- | azalea-block/src/lib.rs | 21 |
2 files changed, 20 insertions, 2 deletions
diff --git a/azalea-block/Cargo.toml b/azalea-block/Cargo.toml index e23eea4d..3dbc7735 100644 --- a/azalea-block/Cargo.toml +++ b/azalea-block/Cargo.toml @@ -11,3 +11,4 @@ version = "0.1.0" [dependencies] azalea-block-macros = {path = "./azalea-block-macros", version = "^0.1.0"} +azalea-buf = {path = "../azalea-buf", version = "^0.1.0"} 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::*; |
