From e733df5448481a9692e3d01a74efbc749c4091f3 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sat, 28 Dec 2013 14:55:31 -0600 Subject: [PATCH] new comparison methods. --- util/item/AEItemDef.java | 33 +++++++++++++++++++++++++++++++++ util/item/AEItemStack.java | 20 +++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/util/item/AEItemDef.java b/util/item/AEItemDef.java index efa0886c..74336eb6 100644 --- a/util/item/AEItemDef.java +++ b/util/item/AEItemDef.java @@ -3,7 +3,10 @@ package appeng.util.item; import java.util.List; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; import appeng.api.storage.data.IAETagCompound; +import appeng.util.Platform; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -38,4 +41,34 @@ public class AEItemDef t.maxDamage = maxDamage; return t; } + + @Override + public boolean equals(Object obj) + { + AEItemDef def = (AEItemDef) obj; + return def.damageValue == damageValue && def.item == item && tagCompound == def.tagCompound; + } + + public int getDamageValueHack(ItemStack is) + { + return Item.blazeRod.getDamage( is ); + } + + public boolean isItem(ItemStack otherStack) + { + // hackery! + int dmg = getDamageValueHack( otherStack ); + + if ( item == otherStack.getItem() && dmg == damageValue ) + { + if ( (tagCompound != null) == otherStack.hasTagCompound() ) + return true; + + if ( tagCompound != null && otherStack.hasTagCompound() ) + return Platform.NBTEqualityTest( (NBTBase) tagCompound, otherStack.getTagCompound() ); + + return true; + } + return false; + } } diff --git a/util/item/AEItemStack.java b/util/item/AEItemStack.java index f9596115..6c7b1168 100644 --- a/util/item/AEItemStack.java +++ b/util/item/AEItemStack.java @@ -71,7 +71,7 @@ public final class AEItemStack extends AEStack implements IAEItemS /* * Kinda Hacky */ - def.damageValue = Item.blazeRod.getDamage( is ); + def.damageValue = def.getDamageValueHack( is ); def.def = is.itemID << Platform.DEF_OFFSET | def.damageValue; def.dspDamage = is.getItemDamageForDisplay(); @@ -496,4 +496,22 @@ public final class AEItemStack extends AEStack implements IAEItemS { return def.tagCompound; } + + @Override + public boolean isSameType(IAEItemStack otherStack) + { + if ( otherStack == null ) + return false; + + return def.equals( ((AEItemStack) otherStack).def ); + } + + @Override + public boolean isSameType(ItemStack otherStack) + { + if ( otherStack == null ) + return false; + + return def.isItem( otherStack ); + } }