diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-03-25 11:17:39 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-25 11:17:39 -0500 |
| commit | ef357fdf3667f3ded03203fc0f7cdec48a01ad8f (patch) | |
| tree | 6e7429c62a22fec1988278f63554c93bdd905a5d /azalea-registry/src/data.rs | |
| parent | 8af265e48bf9f3d5263c074d034770e4216bb3f3 (diff) | |
| download | azalea-drasl-ef357fdf3667f3ded03203fc0f7cdec48a01ad8f.tar.xz | |
1.21.5 (#198)
* 25w02a
* move item_components codegen to a different module
* remove outdated test
* 25w03a
* start updating to 24w09b
* 1.21.5-pre2
* fix broken packets
* 1.21.5-rc2
* merge main
* delete unused acket_handling
* 1.21.5
Diffstat (limited to 'azalea-registry/src/data.rs')
| -rw-r--r-- | azalea-registry/src/data.rs | 66 |
1 files changed, 40 insertions, 26 deletions
diff --git a/azalea-registry/src/data.rs b/azalea-registry/src/data.rs index 17338c8f..7ae55119 100644 --- a/azalea-registry/src/data.rs +++ b/azalea-registry/src/data.rs @@ -1,41 +1,55 @@ -use azalea_buf::AzBuf; +use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite}; + +use crate::Registry; /// A registry which has its values decided by the server in the /// `ClientboundRegistryData` packet. /// /// These can be resolved into their actual values with /// `ResolvableDataRegistry` from azalea-core. -pub trait DataRegistry { +pub trait DataRegistry: AzaleaRead + AzaleaWrite { const NAME: &'static str; fn protocol_id(&self) -> u32; + fn new_raw(id: u32) -> Self; } - -#[derive(Debug, Clone, Copy, AzBuf, PartialEq, Eq, Hash)] -pub struct Enchantment { - #[var] - id: u32, -} -impl DataRegistry for Enchantment { - const NAME: &'static str = "enchantment"; - fn protocol_id(&self) -> u32 { - self.id +impl<T: DataRegistry> Registry for T { + fn from_u32(value: u32) -> Option<Self> { + Some(Self::new_raw(value)) } -} -#[derive(Debug, Clone, Copy, AzBuf, PartialEq, Eq, Hash)] -pub struct DimensionType { - #[var] - id: u32, -} -impl DimensionType { - pub fn new_raw(id: u32) -> Self { - Self { id } + fn to_u32(&self) -> u32 { + self.protocol_id() } } -impl DataRegistry for DimensionType { - const NAME: &'static str = "dimension_type"; - fn protocol_id(&self) -> u32 { - self.id - } + +macro_rules! data_registry { + ($name:ident, $registry_name:expr) => { + #[derive(Debug, Clone, Copy, AzBuf, PartialEq, Eq, Hash)] + pub struct $name { + #[var] + id: u32, + } + impl DataRegistry for $name { + const NAME: &'static str = $registry_name; + fn protocol_id(&self) -> u32 { + self.id + } + fn new_raw(id: u32) -> Self { + Self { id } + } + } + }; } + +data_registry! {Enchantment, "enchantment"} +data_registry! {DimensionType, "dimension_type"} +data_registry! {DamageKind, "damage_kind"} +data_registry! {WolfSoundVariant, "wolf_sound_variant"} +data_registry! {CowVariant, "cow_variant"} +data_registry! {ChickenVariant, "chicken_variant"} +data_registry! {FrogVariant, "frog_variant"} +data_registry! {CatVariant, "cat_variant"} +data_registry! {PigVariant, "pig_variant"} +data_registry! {PaintingVariant, "painting_variant"} +data_registry! {WolfVariant, "wolf_variant"} |
