diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-08-10 18:55:23 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-10 18:55:23 -0500 |
| commit | 7120842f9d2c659a2f12d8922299c2a761bc5582 (patch) | |
| tree | 0d7976ceec82d914e4c75f23adcdd5839f9960a4 /azalea-registry/src | |
| parent | 3b659833c1ad4cca89b4cd553193edcb6d223163 (diff) | |
| download | azalea-drasl-7120842f9d2c659a2f12d8922299c2a761bc5582.tar.xz | |
Send correct data component checksums (#234)
* start implementing data component crc32 hashes
* start doing serde impls for checksums
* make more components hashable
* make all data components serializable
* support recursive components
* fix simdnbt dep
* update changelog
* clippy
Diffstat (limited to 'azalea-registry/src')
| -rw-r--r-- | azalea-registry/src/data.rs | 11 | ||||
| -rw-r--r-- | azalea-registry/src/lib.rs | 59 |
2 files changed, 69 insertions, 1 deletions
diff --git a/azalea-registry/src/data.rs b/azalea-registry/src/data.rs index a9f797b6..c1c1efe5 100644 --- a/azalea-registry/src/data.rs +++ b/azalea-registry/src/data.rs @@ -40,6 +40,17 @@ macro_rules! data_registry { Self { id } } } + + #[cfg(feature = "serde")] + impl serde::Serialize for $name { + fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> + where + S: serde::Serializer, + { + // see ChecksumSerializer::serialize_newtype_variant + serializer.serialize_newtype_variant(concat!("minecraft:", $registry_name), self.id, "", &()) + } + } }; } diff --git a/azalea-registry/src/lib.rs b/azalea-registry/src/lib.rs index 8ab12853..90f1ff55 100644 --- a/azalea-registry/src/lib.rs +++ b/azalea-registry/src/lib.rs @@ -18,6 +18,8 @@ use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufRead use azalea_registry_macros::registry; pub use data::*; pub use extra::*; +#[cfg(feature = "serde")] +use serde::Serialize; pub trait Registry: AzaleaRead + AzaleaWrite where @@ -125,7 +127,7 @@ impl<D: Registry, ResourceLocation: AzaleaRead + AzaleaWrite> AzaleaWrite item.azalea_write(buf)?; } } - Self::Named { key, .. } => { + Self::Named { key, contents: _ } => { 0i32.azalea_write_var(buf)?; key.azalea_write(buf)?; } @@ -147,6 +149,42 @@ impl<D: Registry + Debug, ResourceLocation: AzaleaRead + AzaleaWrite + Debug> De } } } +impl<D: Registry, ResourceLocation: AzaleaRead + AzaleaWrite> From<Vec<D>> + for HolderSet<D, ResourceLocation> +{ + fn from(contents: Vec<D>) -> Self { + Self::Direct { contents } + } +} +#[cfg(feature = "serde")] +impl<D: Registry + Serialize, ResourceLocation: AzaleaRead + AzaleaWrite + Serialize> Serialize + for HolderSet<D, ResourceLocation> +{ + fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> + where + S: serde::Serializer, + { + match self { + Self::Direct { contents } => { + if contents.len() == 1 { + contents[0].serialize(serializer) + } else { + contents.serialize(serializer) + } + } + Self::Named { key, contents: _ } => key.serialize(serializer), + } + } +} +impl<D: Registry, ResourceLocation: AzaleaRead + AzaleaWrite> Default + for HolderSet<D, ResourceLocation> +{ + fn default() -> Self { + Self::Direct { + contents: Vec::new(), + } + } +} /// A reference to either a registry or a custom value (usually something with a /// ResourceLocation). @@ -206,6 +244,25 @@ impl<R: Registry + PartialEq, Direct: AzaleaRead + AzaleaWrite + PartialEq> Part } } } +impl<R: Registry + Default, Direct: AzaleaRead + AzaleaWrite> Default for Holder<R, Direct> { + fn default() -> Self { + Self::Reference(R::default()) + } +} +#[cfg(feature = "serde")] +impl<R: Registry + Serialize, Direct: AzaleaRead + AzaleaWrite + Serialize> Serialize + for Holder<R, Direct> +{ + fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> + where + S: serde::Serializer, + { + match self { + Self::Reference(value) => value.serialize(serializer), + Self::Direct(value) => value.serialize(serializer), + } + } +} registry! { /// The AI code that's currently being executed for the entity. |
