fix(item): prevent stacking items with different components (#2624)

This commit is contained in:
Colin
2026-07-31 07:22:31 +02:00
committed by GitHub
parent bc61503db0
commit 938a627218

View File

@@ -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);