From 938a6272189e15be0215cef9bd07957d0478bf0b Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 31 Jul 2026 07:22:31 +0200 Subject: [PATCH] fix(item): prevent stacking items with different components (#2624) --- pumpkin-data/src/item_stack/mod.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pumpkin-data/src/item_stack/mod.rs b/pumpkin-data/src/item_stack/mod.rs index 5ff00d290..481237f3c 100644 --- a/pumpkin-data/src/item_stack/mod.rs +++ b/pumpkin-data/src/item_stack/mod.rs @@ -579,6 +579,11 @@ impl ItemStack { if self.item != other.item { return false; } + + if self.patch.len() != other.patch.len() { + return false; + } + for (id, data) in &self.patch { let mut not_found = true; 'out: for (other_id, other_data) in &other.patch { @@ -745,6 +750,20 @@ mod tests { ItemStack::new(1, &Item::IRON_SWORD) } + #[test] + fn items_with_different_components_are_not_equal_in_either_direction() { + let plain = ItemStack::new(1, &Item::COAL); + + let mut customized = ItemStack::new(1, &Item::COAL); + customized + .patch + .push((DataComponent::Unbreakable, Some(UnbreakableImpl.to_dyn()))); + + assert!(!plain.are_items_and_components_equal(&customized)); + assert!(!customized.are_items_and_components_equal(&plain)); + assert!(customized.are_items_and_components_equal(&customized.clone())); + } + #[test] fn custom_data_sets_and_reads_typed_values() { let mut stack = ItemStack::new(1, &Item::WOODEN_AXE);