diff options
| author | mat <github@matdoes.dev> | 2022-06-17 16:27:58 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-06-17 16:27:58 -0500 |
| commit | d0fc7d0eff32687d7210b730584db2c3faa055ae (patch) | |
| tree | 8cbc9930a045d12c4eedd2b5af815f7c795f34d2 /azalea-block/src | |
| parent | 69e1125ecbb3e695125b8e65deba3e3f7be41b70 (diff) | |
| download | azalea-drasl-d0fc7d0eff32687d7210b730584db2c3faa055ae.tar.xz | |
ClientboundSetEquipmentPacket
Diffstat (limited to 'azalea-block/src')
| -rw-r--r-- | azalea-block/src/blocks.rs | 2 | ||||
| -rw-r--r-- | azalea-block/src/lib.rs | 56 |
2 files changed, 29 insertions, 29 deletions
diff --git a/azalea-block/src/blocks.rs b/azalea-block/src/blocks.rs index b8d204fd..05973797 100644 --- a/azalea-block/src/blocks.rs +++ b/azalea-block/src/blocks.rs @@ -4951,4 +4951,4 @@ make_block_states! { reinforced_deepslate => BlockBehavior::default(), { }, } -}
\ No newline at end of file +} diff --git a/azalea-block/src/lib.rs b/azalea-block/src/lib.rs index 95e8ce37..a6de1e92 100644 --- a/azalea-block/src/lib.rs +++ b/azalea-block/src/lib.rs @@ -7,41 +7,41 @@ pub use blocks::*; use std::mem; impl BlockState { - /// Transmutes a u32 to a block state. UB if the value is not a valid block - /// state. - #[inline] - pub unsafe fn from_u32_unsafe(state_id: u32) -> Self { - mem::transmute::<u32, BlockState>(state_id) - } - - #[inline] - pub fn is_valid_state(state_id: u32) -> bool { - state_id <= Self::max_state() - } + /// Transmutes a u32 to a block state. UB if the value is not a valid block + /// state. + #[inline] + pub unsafe fn from_u32_unsafe(state_id: u32) -> Self { + mem::transmute::<u32, BlockState>(state_id) + } + + #[inline] + pub fn is_valid_state(state_id: u32) -> bool { + state_id <= Self::max_state() + } } impl TryFrom<u32> for BlockState { - type Error = (); - - /// Safely converts a state id to a block state. - fn try_from(state_id: u32) -> Result<Self, Self::Error> { - if Self::is_valid_state(state_id) { - Ok(unsafe { Self::from_u32_unsafe(state_id) }) - } else { - Err(()) - } - } + type Error = (); + + /// Safely converts a state id to a block state. + fn try_from(state_id: u32) -> Result<Self, Self::Error> { + if Self::is_valid_state(state_id) { + Ok(unsafe { Self::from_u32_unsafe(state_id) }) + } else { + Err(()) + } + } } #[cfg(test)] mod tests { - use super::*; + use super::*; - #[test] - fn test_from_u32() { - assert_eq!(BlockState::try_from(0).unwrap(), BlockState::Air); + #[test] + fn test_from_u32() { + assert_eq!(BlockState::try_from(0).unwrap(), BlockState::Air); - assert!(BlockState::try_from(BlockState::max_state()).is_ok()); - assert!(BlockState::try_from(BlockState::max_state() + 1).is_err()); - } + assert!(BlockState::try_from(BlockState::max_state()).is_ok()); + assert!(BlockState::try_from(BlockState::max_state() + 1).is_err()); + } } |
