From f9c25665c203d6377ace62f1e95381d037d8fd9e Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Fri, 12 Dec 2025 00:56:02 -0600 Subject: 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 --- azalea-block/src/range.rs | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'azalea-block/src/range.rs') 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> for BlockStates { - fn from(set: HashSet) -> Self { +impl From> for BlockStates { + fn from(set: HashSet) -> Self { Self::from(&set) } } -impl From<&HashSet> for BlockStates { - fn from(set: &HashSet) -> Self { +impl From<&HashSet> for BlockStates { + fn from(set: &HashSet) -> 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> for BlockStates { } } -impl 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 From<[BlockKind; N]> for BlockStates { + fn from(arr: [BlockKind; N]) -> Self { + Self::from(&arr[..]) + } +} +impl From<&RegistryTag> for BlockStates { + fn from(tag: &RegistryTag) -> Self { + Self::from(&**tag) + } +} +// allows users to do like `BlockStates::from(&tags::blocks::LOGS)` instead of +// `BlockStates::from(&&tags::blocks::LOGS)` +impl From<&LazyLock>> for BlockStates { + fn from(tag: &LazyLock>) -> Self { + Self::from(&**tag) + } +} -- cgit v1.2.3