diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-12-12 00:56:02 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-12 00:56:02 -0600 |
| commit | f9c25665c203d6377ace62f1e95381d037d8fd9e (patch) | |
| tree | 8b4131d20fe661d3cc1175ec27f801fe61df41ea /azalea-block/src | |
| parent | 82ad975242292d5875780b4398b62637674bf50a (diff) | |
| download | azalea-drasl-f9c25665c203d6377ace62f1e95381d037d8fd9e.tar.xz | |
Refactor azalea-registry (#294)
* move registries in azalea-registry into separate modules
* rename Item and Block to ItemKind and BlockKind
* remove 'extra' registries from azalea-registry
* hide deprecated items from docs
* use DamageKindKey instead of Identifier when parsing registries
* store tag entries as a Vec instead of a HashSet
* sort tag values by protocol id
* update changelog
Diffstat (limited to 'azalea-block/src')
| -rw-r--r-- | azalea-block/src/block_state.rs | 15 | ||||
| -rw-r--r-- | azalea-block/src/fluid_state.rs | 10 | ||||
| -rw-r--r-- | azalea-block/src/lib.rs | 11 | ||||
| -rw-r--r-- | azalea-block/src/range.rs | 37 |
4 files changed, 42 insertions, 31 deletions
diff --git a/azalea-block/src/block_state.rs b/azalea-block/src/block_state.rs index e3f894bf..d39961b3 100644 --- a/azalea-block/src/block_state.rs +++ b/azalea-block/src/block_state.rs @@ -4,6 +4,7 @@ use std::{ }; use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; +use azalea_registry::builtin::BlockKind; use crate::BlockTrait; @@ -129,7 +130,7 @@ impl Debug for BlockState { } } -impl From<BlockState> for azalea_registry::Block { +impl From<BlockState> for BlockKind { fn from(value: BlockState) -> Self { Box::<dyn BlockTrait>::from(value).as_registry_block() } @@ -156,22 +157,16 @@ mod tests { assert_eq!(block.id(), "air"); let block: Box<dyn BlockTrait> = - Box::<dyn BlockTrait>::from(BlockState::from(azalea_registry::Block::FloweringAzalea)); + Box::<dyn BlockTrait>::from(BlockState::from(BlockKind::FloweringAzalea)); assert_eq!(block.id(), "flowering_azalea"); } #[test] fn test_debug_blockstate() { - let formatted = format!( - "{:?}", - BlockState::from(azalea_registry::Block::FloweringAzalea) - ); + let formatted = format!("{:?}", BlockState::from(BlockKind::FloweringAzalea)); assert!(formatted.ends_with(", FloweringAzalea)"), "{}", formatted); - let formatted = format!( - "{:?}", - BlockState::from(azalea_registry::Block::BigDripleafStem) - ); + let formatted = format!("{:?}", BlockState::from(BlockKind::BigDripleafStem)); assert!( formatted.ends_with(", BigDripleafStem { facing: North, waterlogged: false })"), "{}", diff --git a/azalea-block/src/fluid_state.rs b/azalea-block/src/fluid_state.rs index 80d0953b..0a8f7336 100644 --- a/azalea-block/src/fluid_state.rs +++ b/azalea-block/src/fluid_state.rs @@ -1,3 +1,5 @@ +use azalea_registry::builtin::BlockKind; + use crate::block_state::{BlockState, BlockStateIntegerRepr}; #[derive(Clone, Debug)] @@ -80,9 +82,9 @@ impl From<BlockState> for FluidState { }; } - let registry_block = azalea_registry::Block::from(state); + let registry_block = BlockKind::from(state); match registry_block { - azalea_registry::Block::Water => { + BlockKind::Water => { let level = state .property::<crate::properties::WaterLevel>() .expect("water block should always have WaterLevel"); @@ -92,7 +94,7 @@ impl From<BlockState> for FluidState { falling: false, }; } - azalea_registry::Block::Lava => { + BlockKind::Lava => { let level = state .property::<crate::properties::LavaLevel>() .expect("lava block should always have LavaLevel"); @@ -102,7 +104,7 @@ impl From<BlockState> for FluidState { falling: false, }; } - azalea_registry::Block::BubbleColumn => { + BlockKind::BubbleColumn => { return Self::new_source_block(FluidKind::Water, false); } _ => {} diff --git a/azalea-block/src/lib.rs b/azalea-block/src/lib.rs index 2cab022e..ad78102c 100644 --- a/azalea-block/src/lib.rs +++ b/azalea-block/src/lib.rs @@ -9,6 +9,7 @@ mod range; use core::fmt::Debug; use std::{any::Any, collections::HashMap}; +use azalea_registry::builtin::BlockKind; pub use behavior::BlockBehavior; // re-exported for convenience pub use block_state::BlockState; @@ -21,16 +22,16 @@ pub trait BlockTrait: Debug + Any { /// /// For example, `stone` or `grass_block`. fn id(&self) -> &'static str; - /// Convert the block to a block state. + /// Convert the block struct to a [`BlockState`]. /// /// This is a lossless conversion, as [`BlockState`] also contains state /// data. fn as_block_state(&self) -> BlockState; - /// Convert the block to an [`azalea_registry::Block`]. + /// Convert the block struct to a [`BlockKind`]. /// - /// This is a lossy conversion, as [`azalea_registry::Block`] doesn't - /// contain any state data. - fn as_registry_block(&self) -> azalea_registry::Block; + /// This is a lossy conversion, as [`BlockKind`] doesn't contain any state + /// data. + fn as_registry_block(&self) -> BlockKind; /// Returns a map of property names on this block to their values as /// strings. diff --git a/azalea-block/src/range.rs b/azalea-block/src/range.rs index 76b18079..53d2c10f 100644 --- a/azalea-block/src/range.rs +++ b/azalea-block/src/range.rs @@ -1,9 +1,10 @@ use std::{ collections::{HashSet, hash_set}, ops::{Add, RangeInclusive}, + sync::LazyLock, }; -use azalea_registry::Block; +use azalea_registry::{builtin::BlockKind, tags::RegistryTag}; use crate::{BlockState, block_state::BlockStateIntegerRepr}; @@ -47,14 +48,14 @@ impl Add for BlockStates { } } -impl From<HashSet<Block>> for BlockStates { - fn from(set: HashSet<Block>) -> Self { +impl From<HashSet<BlockKind>> for BlockStates { + fn from(set: HashSet<BlockKind>) -> Self { Self::from(&set) } } -impl From<&HashSet<Block>> for BlockStates { - fn from(set: &HashSet<Block>) -> Self { +impl From<&HashSet<BlockKind>> for BlockStates { + fn from(set: &HashSet<BlockKind>) -> Self { let mut block_states = HashSet::with_capacity(set.len()); for &block in set { block_states.extend(BlockStates::from(block)); @@ -63,13 +64,8 @@ impl From<&HashSet<Block>> for BlockStates { } } -impl<const N: usize> From<[Block; N]> for BlockStates { - fn from(arr: [Block; N]) -> Self { - Self::from(&arr[..]) - } -} -impl From<&[Block]> for BlockStates { - fn from(arr: &[Block]) -> Self { +impl From<&[BlockKind]> for BlockStates { + fn from(arr: &[BlockKind]) -> Self { let mut block_states = HashSet::with_capacity(arr.len()); for &block in arr { block_states.extend(BlockStates::from(block)); @@ -77,3 +73,20 @@ impl From<&[Block]> for BlockStates { Self { set: block_states } } } +impl<const N: usize> From<[BlockKind; N]> for BlockStates { + fn from(arr: [BlockKind; N]) -> Self { + Self::from(&arr[..]) + } +} +impl From<&RegistryTag<BlockKind>> for BlockStates { + fn from(tag: &RegistryTag<BlockKind>) -> Self { + Self::from(&**tag) + } +} +// allows users to do like `BlockStates::from(&tags::blocks::LOGS)` instead of +// `BlockStates::from(&&tags::blocks::LOGS)` +impl From<&LazyLock<RegistryTag<BlockKind>>> for BlockStates { + fn from(tag: &LazyLock<RegistryTag<BlockKind>>) -> Self { + Self::from(&**tag) + } +} |
