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-core/src/data_registry.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-core/src/data_registry.rs')
| -rw-r--r-- | azalea-core/src/data_registry.rs | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/azalea-core/src/data_registry.rs b/azalea-core/src/data_registry.rs index cf82772a..07837b19 100644 --- a/azalea-core/src/data_registry.rs +++ b/azalea-core/src/data_registry.rs @@ -1,16 +1,30 @@ -use azalea_registry::DataRegistry; -use simdnbt::owned::NbtCompound; - -use crate::{ +use azalea_registry::{ + DataRegistry, DataRegistryKey, DataRegistryKeyRef, + data::{self}, identifier::Identifier, - registry_holder::{self, RegistryDeserializesTo, RegistryHolder}, }; +use simdnbt::owned::NbtCompound; + +use crate::registry_holder::{self, RegistryDeserializesTo, RegistryHolder}; + +pub trait DataRegistryWithKey: DataRegistry { + fn key<'s, 'a: 's>( + &'s self, + registries: &'a RegistryHolder, + ) -> Option<<Self::Key as DataRegistryKey>::Borrow<'s>> { + registries + .protocol_id_to_identifier(Identifier::from(Self::NAME), self.protocol_id()) + .map(DataRegistryKeyRef::from_ident) + } +} +impl<R: DataRegistry> DataRegistryWithKey for R {} pub trait ResolvableDataRegistry: DataRegistry { type DeserializesTo: RegistryDeserializesTo; + #[doc(hidden)] + #[deprecated = "use `DataRegistryWithKey::key` instead."] fn resolve_name<'a>(&self, registries: &'a RegistryHolder) -> Option<&'a Identifier> { - // self.resolve(registries).map(|(name, _)| name.clone()) registries.protocol_id_to_identifier(Identifier::from(Self::NAME), self.protocol_id()) } @@ -42,20 +56,20 @@ macro_rules! define_default_deserializes_to { } define_deserializes_to! { - azalea_registry::DimensionType => registry_holder::dimension_type::DimensionTypeElement, - azalea_registry::Enchantment => registry_holder::enchantment::EnchantmentData, + data::DimensionKind => registry_holder::dimension_type::DimensionKindElement, + data::Enchantment => registry_holder::enchantment::EnchantmentData, } define_default_deserializes_to! { - azalea_registry::DamageKind, - azalea_registry::Dialog, - azalea_registry::WolfSoundVariant, - azalea_registry::CowVariant, - azalea_registry::ChickenVariant, - azalea_registry::FrogVariant, - azalea_registry::CatVariant, - azalea_registry::PigVariant, - azalea_registry::PaintingVariant, - azalea_registry::WolfVariant, - azalea_registry::Biome, + data::DamageKind, + data::Dialog, + data::WolfSoundVariant, + data::CowVariant, + data::ChickenVariant, + data::FrogVariant, + data::CatVariant, + data::PigVariant, + data::PaintingVariant, + data::WolfVariant, + data::Biome, } |
