- 1,137
- 5
- 3
Можанги, по их обычаям, написали костыль. На этот раз в ItemStack. Там не реализован ни equals, ни hashCode. Зато есть статический метод areItemStackEquals. И что делать? Я сделал промежуточный класс, но боюсь, что будут коллизии.
Код:
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof ItemStackWithEquals) {
return ItemStack.areItemStacksEqual(((ItemStackWithEquals) obj).getStack(), stack);
} else {
return super.equals(obj);
}
}
@Override
public int hashCode() {
Item item = stack.getItem();
NBTTagCompound tagCompound = stack.getTagCompound();
int stackSize = stack.stackSize;
int hashCode = 0;
hashCode += stackSize;
if (item != null) {
hashCode += item.hashCode();
if (tagCompound != null) {
hashCode += tagCompound.hashCode();
}
return hashCode;
} else {
return super.hashCode();
}
}