aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/plugins
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2025-08-10 18:55:23 -0500
committerGitHub <noreply@github.com>2025-08-10 18:55:23 -0500
commit7120842f9d2c659a2f12d8922299c2a761bc5582 (patch)
tree0d7976ceec82d914e4c75f23adcdd5839f9960a4 /azalea-client/src/plugins
parent3b659833c1ad4cca89b4cd553193edcb6d223163 (diff)
downloadazalea-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-client/src/plugins')
-rw-r--r--azalea-client/src/plugins/inventory.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/azalea-client/src/plugins/inventory.rs b/azalea-client/src/plugins/inventory.rs
index 1662be9f..732e1154 100644
--- a/azalea-client/src/plugins/inventory.rs
+++ b/azalea-client/src/plugins/inventory.rs
@@ -18,6 +18,7 @@ use azalea_protocol::packets::game::{
s_set_carried_item::ServerboundSetCarriedItem,
};
use azalea_registry::MenuKind;
+use azalea_world::{InstanceContainer, InstanceName};
use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*;
use tracing::{error, warn};
@@ -835,12 +836,19 @@ pub struct ContainerClickEvent {
pub operation: ClickOperation,
}
pub fn handle_container_click_event(
- mut query: Query<(Entity, &mut Inventory, Option<&PlayerAbilities>)>,
+ mut query: Query<(
+ Entity,
+ &mut Inventory,
+ Option<&PlayerAbilities>,
+ &InstanceName,
+ )>,
mut events: EventReader<ContainerClickEvent>,
mut commands: Commands,
+ instance_container: Res<InstanceContainer>,
) {
for event in events.read() {
- let (entity, mut inventory, player_abilities) = query.get_mut(event.entity).unwrap();
+ let (entity, mut inventory, player_abilities, instance_name) =
+ query.get_mut(event.entity).unwrap();
if inventory.id != event.window_id {
error!(
"Tried to click container with ID {}, but the current container ID is {}. Click packet won't be sent.",
@@ -849,6 +857,10 @@ pub fn handle_container_click_event(
continue;
}
+ let Some(instance) = instance_container.get(instance_name) else {
+ continue;
+ };
+
let old_slots = inventory.menu().slots();
inventory.simulate_click(
&event.operation,
@@ -856,13 +868,18 @@ pub fn handle_container_click_event(
);
let new_slots = inventory.menu().slots();
+ let registry_holder = &instance.read().registries;
+
// see which slots changed after clicking and put them in the hashmap
// the server uses this to check if we desynced
let mut changed_slots: HashMap<u16, HashedStack> = HashMap::new();
for (slot_index, old_slot) in old_slots.iter().enumerate() {
let new_slot = &new_slots[slot_index];
if old_slot != new_slot {
- changed_slots.insert(slot_index as u16, HashedStack::from(new_slot));
+ changed_slots.insert(
+ slot_index as u16,
+ HashedStack::from_item_stack(new_slot, registry_holder),
+ );
}
}
@@ -875,7 +892,7 @@ pub fn handle_container_click_event(
button_num: event.operation.button_num(),
click_type: event.operation.click_type(),
changed_slots,
- carried_item: (&inventory.carried).into(),
+ carried_item: HashedStack::from_item_stack(&inventory.carried, registry_holder),
},
));
}