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/range.rs | |
| 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/range.rs')
| -rw-r--r-- | azalea-block/src/range.rs | 37 |
1 files changed, 25 insertions, 12 deletions
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) + } +} |
