diff --git a/api/buildcraft/api/core/StackKey.java b/api/buildcraft/api/core/StackKey.java index 4df5050e..9c9ef0e0 100644 --- a/api/buildcraft/api/core/StackKey.java +++ b/api/buildcraft/api/core/StackKey.java @@ -11,6 +11,7 @@ package buildcraft.api.core; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidStack; @@ -82,14 +83,14 @@ public final class StackKey { if (stack != null) { if (stack.getItem() != k.stack.getItem() || stack.getHasSubtypes() && stack.getItemDamage() != k.stack.getItemDamage() || - !stack.getTagCompound().equals(k.stack.getTagCompound())) { + !objectsEqual(stack.getTagCompound(), k.stack.getTagCompound())) { return false; } } if (fluidStack != null) { if (fluidStack.fluidID != k.fluidStack.fluidID || fluidStack.amount != k.fluidStack.amount || - !fluidStack.tag.equals(k.fluidStack.tag)) { + !objectsEqual(fluidStack.tag, k.fluidStack.tag)) { return false; } } @@ -102,17 +103,31 @@ public final class StackKey { if (stack != null) { result = 31 * result + stack.getItem().hashCode(); result = 31 * result + stack.getItemDamage(); - result = 31 * result + stack.getTagCompound().hashCode(); + result = 31 * result + objectHashCode(stack.getTagCompound()); } result = 31 * result + 7; if (fluidStack != null) { result = 31 * result + fluidStack.fluidID; result = 31 * result + fluidStack.amount; - result = 31 * result + fluidStack.tag.hashCode(); + result = 31 * result + objectHashCode(fluidStack.tag); } return result; } + private boolean objectsEqual(Object o1, Object o2) { + if (o1 == null && o2 == null) { + return true; + } else if (o1 == null || o2 == null) { + return false; + } else { + return o1.equals(o2); + } + } + + private int objectHashCode(Object o) { + return o != null ? o.hashCode() : 0; + } + public StackKey copy() { return new StackKey(stack != null ? stack.copy() : null, fluidStack != null ? fluidStack.copy() : null);