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 | |
| 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')
| -rw-r--r-- | azalea-protocol/Cargo.toml | 6 | ||||
| -rw-r--r-- | azalea-protocol/src/packets/game/s_container_click.rs | 34 |
2 files changed, 18 insertions, 22 deletions
diff --git a/azalea-protocol/Cargo.toml b/azalea-protocol/Cargo.toml index 92814e74..b3f161c9 100644 --- a/azalea-protocol/Cargo.toml +++ b/azalea-protocol/Cargo.toml @@ -18,7 +18,7 @@ azalea-block.workspace = true azalea-brigadier = { workspace = true, features = ["azalea-buf"] } azalea-buf.workspace = true azalea-chat = { workspace = true, features = ["numbers", "azalea-buf"] } -azalea-core = { workspace = true, optional = true, features = ["serde"] } +azalea-core = { workspace = true, optional = true } azalea-crypto.workspace = true azalea-entity.workspace = true azalea-inventory.workspace = true @@ -41,10 +41,8 @@ tokio-util = { workspace = true, features = ["codec"] } tracing.workspace = true hickory-resolver = { workspace = true, features = ["tokio", "system-config"] } uuid.workspace = true -crc32fast = { workspace = true, optional = true } [features] connecting = [] default = ["packets"] -packets = ["connecting", "dep:azalea-core", "crc32"] -crc32 = ["dep:crc32fast"] +packets = ["connecting", "dep:azalea-core"] 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); } |
