From 0bfded7bbfe98b57b709271c297c3075e5ca13df Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Fri, 21 Mar 2014 22:58:03 -0500 Subject: [PATCH] Fixed Bug: #0210 - Fuzzy on an export bus do not ignore NBT data and metadata. Fixed Serious issue with items with the same hashes merging. --- util/Platform.java | 4 ++-- util/item/AEItemDef.java | 3 +++ util/item/AEItemStack.java | 24 +++++++++++++++++++----- util/item/AESharedNBT.java | 13 ++++++++++--- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/util/Platform.java b/util/Platform.java index 6caa40a91..ac7067bbb 100644 --- a/util/Platform.java +++ b/util/Platform.java @@ -463,7 +463,7 @@ public class Platform while (i.hasNext()) { String name = i.next(); - hash += NBTOrderlessHash( ctA.getTag( name ) ); + hash += name.hashCode() ^ NBTOrderlessHash( ctA.getTag( name ) ); } return hash; @@ -477,7 +477,7 @@ public class Platform List l = tagList( lA ); for (int x = 0; x < l.size(); x++) { - hash += NBTOrderlessHash( l.get( x ) ); + hash += ((Integer) x).hashCode() ^ NBTOrderlessHash( l.get( x ) ); } return hash; diff --git a/util/item/AEItemDef.java b/util/item/AEItemDef.java index 328af0914..bcdd2ac79 100644 --- a/util/item/AEItemDef.java +++ b/util/item/AEItemDef.java @@ -34,6 +34,9 @@ public class AEItemDef public OreRefrence isOre; + static AESharedNBT lowTag = new AESharedNBT( Integer.MIN_VALUE ); + static AESharedNBT highTag = new AESharedNBT( Integer.MAX_VALUE ); + public AEItemDef copy() { AEItemDef t = new AEItemDef(); diff --git a/util/item/AEItemStack.java b/util/item/AEItemStack.java index 051098565..032085399 100644 --- a/util/item/AEItemStack.java +++ b/util/item/AEItemStack.java @@ -229,12 +229,24 @@ public final class AEItemStack extends AEStack implements IAEItemS @Override public int compareTo(AEItemStack b) { - int id = def.item.hashCode() - b.def.item.hashCode(); - int dv = def.damageValue - b.def.damageValue; - int dspv = def.dspDamage - b.def.dspDamage; + int id = compare( def.item.hashCode(), b.def.item.hashCode() ); + int dv = compare( def.damageValue, b.def.damageValue ); + int dspv = compare( def.dspDamage, b.def.dspDamage ); + // AELog.info( "NBT: " + nbt ); + return id == 0 ? (dv == 0 ? (dspv == 0 ? compareNBT( b.def ) : dspv) : dv) : id; + } - return id == 0 ? (dv == 0 ? (dspv == 0 ? ((def.tagCompound == null ? 0 : def.tagCompound.getHash()) - (b.def.tagCompound == null ? 0 - : b.def.tagCompound.getHash())) : dspv) : dv) : id; + private int compareNBT(AEItemDef b) + { + int nbt = compare( (def.tagCompound == null ? 0 : def.tagCompound.getHash()), (b.tagCompound == null ? 0 : b.tagCompound.getHash()) ); + if ( nbt == 0 ) + return compare( System.identityHashCode( def.tagCompound ), System.identityHashCode( b.tagCompound ) ); + return nbt; + } + + private int compare(int l, long m) + { + return l < m ? -1 : (l > m ? 1 : 0); } @SideOnly(Side.CLIENT) @@ -485,6 +497,7 @@ public final class AEItemStack extends AEStack implements IAEItemS if ( newDef.item.isDamageable() ) newDef.damageValue = newDef.dspDamage; + newDef.tagCompound = newDef.lowTag; newDef.reHash(); return bottom; } @@ -514,6 +527,7 @@ public final class AEItemStack extends AEStack implements IAEItemS if ( newDef.item.isDamageable() ) newDef.damageValue = top.def.dspDamage; + newDef.tagCompound = newDef.highTag; newDef.reHash(); return top; } diff --git a/util/item/AESharedNBT.java b/util/item/AESharedNBT.java index 2a5fedfcb..ddaf200e7 100644 --- a/util/item/AESharedNBT.java +++ b/util/item/AESharedNBT.java @@ -18,7 +18,7 @@ import appeng.util.Platform; public class AESharedNBT extends NBTTagCompound implements IAETagCompound { - private Item itemid; + private Item item; private int meta, hash; public SharedSearchObject sso; private IItemComparison comp; @@ -36,10 +36,17 @@ public class AESharedNBT extends NBTTagCompound implements IAETagCompound private AESharedNBT(Item itemID, int damageValue) { super(); - itemid = itemID; + item = itemID; meta = damageValue; } + public AESharedNBT(int fakeValue) { + super(); + item = null; + meta = 0; + hash = fakeValue; + } + @Override public NBTTagCompound getNBTTagCompoundCopy() { @@ -78,7 +85,7 @@ public class AESharedNBT extends NBTTagCompound implements IAETagCompound public boolean matches(Item itemid2, int meta2, int orderlessHash) { - return itemid2 == itemid && meta == meta2 && hash == orderlessHash; + return itemid2 == item && meta == meta2 && hash == orderlessHash; } public boolean comparePreciseWithRegistry(AESharedNBT tagCompound)