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-protocol/src/packets | |
| 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-protocol/src/packets')
| -rw-r--r-- | azalea-protocol/src/packets/game/s_container_click.rs | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/azalea-protocol/src/packets/game/s_container_click.rs b/azalea-protocol/src/packets/game/s_container_click.rs index 9c4696ed..a06e7c0c 100644 --- a/azalea-protocol/src/packets/game/s_container_click.rs +++ b/azalea-protocol/src/packets/game/s_container_click.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; -use azalea_buf::{AzBuf, AzaleaWrite}; +use azalea_buf::AzBuf; +use azalea_core::{checksum::Checksum, registry_holder::RegistryHolder}; use azalea_inventory::{ItemStack, operations::ClickType}; use azalea_protocol_macros::ServerboundGamePacket; @@ -35,34 +36,31 @@ pub struct HashedPatchMap { /// The value is a CRC32 hash of the data component's network serialization. /// (kind + data) #[limit(256)] - pub added_components: Vec<(azalea_registry::DataComponentKind, u32)>, + pub added_components: Vec<(azalea_registry::DataComponentKind, Checksum)>, #[limit(256)] pub removed_components: Vec<azalea_registry::DataComponentKind>, } -/// Convert your [`ItemStack`] into a [`HashedStack`] by hashing the data -/// components. -/// -/// This will be necessary if you're writing a client or server, but if you're -/// just making a proxy then you can remove the `crc32` dependency by disabling -/// the `crc32` feature on `azalea-protocol`. -#[cfg(feature = "crc32")] -impl From<&ItemStack> for HashedStack { - fn from(item: &ItemStack) -> Self { +impl HashedStack { + /// Convert your [`ItemStack`] into a [`HashedStack`] by hashing the data + /// components. + /// + /// Minecraft uses this whenever the client sends data components to the + /// server. + /// + /// The [`RegistryHolder`] is required as some components will hash + /// differently based on the server's registries. + pub fn from_item_stack(item: &ItemStack, registries: &RegistryHolder) -> Self { let ItemStack::Present(item) = item else { - return Self(None); + return HashedStack(None); }; let mut added_components = Vec::new(); let mut removed_components = Vec::new(); - for (&kind, data) in &item.component_patch.components { + for (kind, data) in item.component_patch.iter() { if let Some(data) = data { - // encodeCap in TypedDataComponent.java - let mut buf = Vec::new(); - kind.azalea_write(&mut buf).unwrap(); - data.encode(&mut buf).unwrap(); - added_components.push((kind, crc32fast::hash(&buf))); + added_components.push((kind, data.crc_hash(registries))); } else { removed_components.push(kind); } |
