mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
fix(item): prevent stacking items with different components (#2624)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user