Add equals(ItemStack) to IAEItemStack contract.

This commit is contained in:
Sebastian Hartte
2020-07-03 14:32:34 +02:00
parent 22facb9748
commit b8aa810a5f
2 changed files with 15 additions and 1 deletions
@@ -106,4 +106,13 @@ public interface IAEItemStack extends IAEStack<IAEItemStack> {
* @return definition stack * @return definition stack
*/ */
ItemStack getDefinition(); ItemStack getDefinition();
/**
* Compare this AE item stack to another item stack, but ignores
* the amount. It checks the item type, NBT and damage values.
*
* @param is An item stack
*/
boolean equals(ItemStack is);
} }
@@ -216,11 +216,16 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
if (ia instanceof AEItemStack) { if (ia instanceof AEItemStack) {
return this.isSameType((AEItemStack) ia); return this.isSameType((AEItemStack) ia);
} else if (ia instanceof ItemStack) { } else if (ia instanceof ItemStack) {
return this.isSameType((ItemStack) ia); // this actually breaks the equals contract (being equals to unrelated classes)
return equals((ItemStack) ia);
} }
return false; return false;
} }
public boolean equals(final ItemStack is) {
return this.isSameType(is);
}
@Override @Override
public String toString() { public String toString() {
return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName(); return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName();