diff --git a/src/main/java/appeng/block/AEBaseTileBlock.java b/src/main/java/appeng/block/AEBaseTileBlock.java index 688fb68b..a40ff1eb 100644 --- a/src/main/java/appeng/block/AEBaseTileBlock.java +++ b/src/main/java/appeng/block/AEBaseTileBlock.java @@ -300,7 +300,7 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity for( final ItemStack ol : itemDropCandidates ) { - if( Platform.isSameItemType( ol, op ) ) + if( Platform.itemComparisons().isEqualItemType( ol, op ) ) { final NBTTagCompound tag = tile.downloadSettings( SettingsFrom.DISMANTLE_ITEM ); if( tag != null ) diff --git a/src/main/java/appeng/container/AEBaseContainer.java b/src/main/java/appeng/container/AEBaseContainer.java index 178a0853..d1b3710a 100644 --- a/src/main/java/appeng/container/AEBaseContainer.java +++ b/src/main/java/appeng/container/AEBaseContainer.java @@ -227,7 +227,7 @@ public abstract class AEBaseContainer extends Container final ItemStack a = stack == null ? null : stack.getItemStack(); final ItemStack b = this.clientRequestedTargetItem == null ? null : this.clientRequestedTargetItem.getItemStack(); - if( Platform.isSameItemPrecise( a, b ) ) + if( Platform.itemComparisons().isSameItem( a, b ) ) { return; } @@ -545,7 +545,7 @@ public abstract class AEBaseContainer extends Container if( !( cs.isPlayerSide() ) && cs instanceof SlotFake ) { - if( Platform.isSameItemPrecise( destination, tis ) ) + if( Platform.itemComparisons().isSameItem( destination, tis ) ) { break; } @@ -577,7 +577,7 @@ public abstract class AEBaseContainer extends Container { final ItemStack t = d.getStack(); - if( Platform.isSameItemPrecise( tis, t ) ) // t.isItemEqual(tis)) + if( Platform.itemComparisons().isSameItem( tis, t ) ) // t.isItemEqual(tis)) { int maxSize = t.getMaxStackSize(); if( maxSize > d.getSlotStackLimit() ) @@ -629,7 +629,7 @@ public abstract class AEBaseContainer extends Container { final ItemStack t = d.getStack(); - if( Platform.isSameItemPrecise( t, tis ) ) + if( Platform.itemComparisons().isSameItem( t, tis ) ) { int maxSize = t.getMaxStackSize(); if( d.getSlotStackLimit() < maxSize ) @@ -929,7 +929,7 @@ public abstract class AEBaseContainer extends Container { liftQty = 0; } - if( !Platform.isSameItemPrecise( slotItem.getItemStack(), item ) ) + if( !Platform.itemComparisons().isSameItem( slotItem.getItemStack(), item ) ) { liftQty = 0; } diff --git a/src/main/java/appeng/container/implementations/ContainerInscriber.java b/src/main/java/appeng/container/implementations/ContainerInscriber.java index 5ace4636..d14ffca5 100644 --- a/src/main/java/appeng/container/implementations/ContainerInscriber.java +++ b/src/main/java/appeng/container/implementations/ContainerInscriber.java @@ -115,7 +115,7 @@ public class ContainerInscriber extends ContainerUpgradeable implements IProgres { for( final ItemStack optional : AEApi.instance().registries().inscriber().getOptionals() ) { - if( Platform.isSameItemPrecise( optional, is ) ) + if( Platform.itemComparisons().isSameItem( optional, is ) ) { return false; } @@ -126,18 +126,18 @@ public class ContainerInscriber extends ContainerUpgradeable implements IProgres for( final IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes() ) { - final boolean matchA = ( top == null && !recipe.getTopOptional().isPresent() ) || ( Platform.isSameItemPrecise( top, recipe.getTopOptional().orElse( null ) ) ) && // and... - ( bot == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.isSameItemPrecise( bot, recipe.getBottomOptional().orElse( null ) ) ); + final boolean matchA = ( top == null && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( top, recipe.getTopOptional().orElse( null ) ) ) && // and... + ( bot == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( bot, recipe.getBottomOptional().orElse( null ) ) ); - final boolean matchB = ( bot == null && !recipe.getTopOptional().isPresent() ) || ( Platform.isSameItemPrecise( bot, recipe.getTopOptional().orElse( null ) ) ) && // and... - ( top == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.isSameItemPrecise( top, recipe.getBottomOptional().orElse( null ) ) ); + final boolean matchB = ( bot == null && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( bot, recipe.getTopOptional().orElse( null ) ) ) && // and... + ( top == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( top, recipe.getBottomOptional().orElse( null ) ) ); if( matchA || matchB ) { matches = true; for( final ItemStack option : recipe.getInputs() ) { - if( Platform.isSameItemPrecise( is, option ) ) + if( Platform.itemComparisons().isSameItem( is, option ) ) { found = true; } @@ -174,13 +174,13 @@ public class ContainerInscriber extends ContainerUpgradeable implements IProgres boolean isValid = false; for( final IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes() ) { - if( Platform.isSameItemPrecise( recipe.getTopOptional().orElse( null ), otherSlot ) ) + if( Platform.itemComparisons().isSameItem( recipe.getTopOptional().orElse( null ), otherSlot ) ) { - isValid = Platform.isSameItemPrecise( is, recipe.getBottomOptional().orElse( null ) ); + isValid = Platform.itemComparisons().isSameItem( is, recipe.getBottomOptional().orElse( null ) ); } - else if( Platform.isSameItemPrecise( recipe.getBottomOptional().orElse( null ), otherSlot ) ) + else if( Platform.itemComparisons().isSameItem( recipe.getBottomOptional().orElse( null ), otherSlot ) ) { - isValid = Platform.isSameItemPrecise( is, recipe.getTopOptional().orElse( null ) ); + isValid = Platform.itemComparisons().isSameItem( is, recipe.getTopOptional().orElse( null ) ); } if( isValid ) diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index 6f414221..56322103 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -67,7 +67,7 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable { if( currentItem != null ) { - if( Platform.isSameItem( this.civ.getItemStack(), currentItem ) ) + if( Platform.itemComparisons().isEqualItem( this.civ.getItemStack(), currentItem ) ) { this.getPlayerInv().setInventorySlotContents( this.getPlayerInv().currentItem, this.civ.getItemStack() ); } diff --git a/src/main/java/appeng/container/implementations/ContainerNetworkTool.java b/src/main/java/appeng/container/implementations/ContainerNetworkTool.java index 65d322de..a339ac60 100644 --- a/src/main/java/appeng/container/implementations/ContainerNetworkTool.java +++ b/src/main/java/appeng/container/implementations/ContainerNetworkTool.java @@ -72,7 +72,7 @@ public class ContainerNetworkTool extends AEBaseContainer { if( currentItem != null ) { - if( Platform.isSameItem( this.toolInv.getItemStack(), currentItem ) ) + if( Platform.itemComparisons().isEqualItem( this.toolInv.getItemStack(), currentItem ) ) { this.getPlayerInv().setInventorySlotContents( this.getPlayerInv().currentItem, this.toolInv.getItemStack() ); } diff --git a/src/main/java/appeng/container/implementations/ContainerPatternTerm.java b/src/main/java/appeng/container/implementations/ContainerPatternTerm.java index e11dea15..5c88a8ad 100644 --- a/src/main/java/appeng/container/implementations/ContainerPatternTerm.java +++ b/src/main/java/appeng/container/implementations/ContainerPatternTerm.java @@ -414,7 +414,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA final IRecipe rr = Platform.findMatchingRecipe( real, p.worldObj ); - if( rr == r && Platform.isSameItemPrecise( rr.getCraftingResult( real ), is ) ) + if( rr == r && Platform.itemComparisons().isSameItem( rr.getCraftingResult( real ), is ) ) { final SlotCrafting sc = new SlotCrafting( p, real, this.cOut, 0, 0, 0 ); sc.onPickupFromSlot( p, is ); diff --git a/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java b/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java index 4d34a9f9..9f9084d8 100644 --- a/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java +++ b/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java @@ -79,7 +79,7 @@ public class ContainerQuartzKnife extends AEBaseContainer implements IAEAppEngIn { if( currentItem != null ) { - if( Platform.isSameItem( this.toolInv.getItemStack(), currentItem ) ) + if( Platform.itemComparisons().isEqualItem( this.toolInv.getItemStack(), currentItem ) ) { this.getPlayerInv().setInventorySlotContents( this.getPlayerInv().currentItem, this.toolInv.getItemStack() ); } diff --git a/src/main/java/appeng/container/implementations/ContainerUpgradeable.java b/src/main/java/appeng/container/implementations/ContainerUpgradeable.java index 320fcd79..d52e85d5 100644 --- a/src/main/java/appeng/container/implementations/ContainerUpgradeable.java +++ b/src/main/java/appeng/container/implementations/ContainerUpgradeable.java @@ -235,7 +235,7 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl { if( currentItem != null ) { - if( Platform.isSameItem( this.tbInventory.getItemStack(), currentItem ) ) + if( Platform.itemComparisons().isEqualItem( this.tbInventory.getItemStack(), currentItem ) ) { this.getPlayerInv().setInventorySlotContents( this.tbSlot, this.tbInventory.getItemStack() ); } diff --git a/src/main/java/appeng/container/slot/SlotCraftingTerm.java b/src/main/java/appeng/container/slot/SlotCraftingTerm.java index e845289b..ffe00ff7 100644 --- a/src/main/java/appeng/container/slot/SlotCraftingTerm.java +++ b/src/main/java/appeng/container/slot/SlotCraftingTerm.java @@ -158,7 +158,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot // update crafting matrix... ItemStack is = this.getStack(); - if( is != null && Platform.isSameItem( request, is ) ) + if( is != null && Platform.itemComparisons().isEqualItem( request, is ) ) { final ItemStack[] set = new ItemStack[this.getPattern().getSizeInventory()]; diff --git a/src/main/java/appeng/container/slot/SlotRestrictedInput.java b/src/main/java/appeng/container/slot/SlotRestrictedInput.java index 1100ca87..cfbba5c7 100644 --- a/src/main/java/appeng/container/slot/SlotRestrictedInput.java +++ b/src/main/java/appeng/container/slot/SlotRestrictedInput.java @@ -170,7 +170,7 @@ public class SlotRestrictedInput extends AppEngSlot for( final ItemStack optional : AEApi.instance().registries().inscriber().getOptionals() ) { - if( Platform.isSameItemPrecise( optional, i ) ) + if( Platform.itemComparisons().isSameItem( optional, i ) ) { return true; } @@ -258,7 +258,7 @@ public class SlotRestrictedInput extends AppEngSlot public static boolean isMetalIngot( final ItemStack i ) { - if( Platform.isSameItemPrecise( i, new ItemStack( Items.IRON_INGOT ) ) ) + if( Platform.itemComparisons().isSameItem( i, new ItemStack( Items.IRON_INGOT ) ) ) { return true; } @@ -267,7 +267,7 @@ public class SlotRestrictedInput extends AppEngSlot { for( final ItemStack ingot : OreDictionary.getOres( "ingot" + name ) ) { - if( Platform.isSameItemPrecise( i, ingot ) ) + if( Platform.itemComparisons().isSameItem( i, ingot ) ) { return true; } diff --git a/src/main/java/appeng/core/features/ItemDefinition.java b/src/main/java/appeng/core/features/ItemDefinition.java index 98285a05..1adb3ae8 100644 --- a/src/main/java/appeng/core/features/ItemDefinition.java +++ b/src/main/java/appeng/core/features/ItemDefinition.java @@ -73,7 +73,7 @@ public class ItemDefinition implements IItemDefinition @Override public final boolean isSameAs( final ItemStack comparableStack ) { - return isEnabled() && Platform.isSameItemType( comparableStack, this.maybeStack( 1 ).get() ); + return isEnabled() && Platform.itemComparisons().isEqualItemType( comparableStack, this.maybeStack( 1 ).get() ); } } diff --git a/src/main/java/appeng/core/features/registries/GrinderRecipeManager.java b/src/main/java/appeng/core/features/registries/GrinderRecipeManager.java index b32a4523..af410952 100644 --- a/src/main/java/appeng/core/features/registries/GrinderRecipeManager.java +++ b/src/main/java/appeng/core/features/registries/GrinderRecipeManager.java @@ -125,7 +125,7 @@ public final class GrinderRecipeManager implements IGrinderRegistry, IOreListene { for( final IGrinderEntry gr : this.recipes ) { - if( Platform.isSameItemPrecise( gr.getInput(), appEngGrinderRecipe.getInput() ) ) + if( Platform.itemComparisons().isSameItem( gr.getInput(), appEngGrinderRecipe.getInput() ) ) { return; } @@ -151,7 +151,7 @@ public final class GrinderRecipeManager implements IGrinderRegistry, IOreListene { for( final IGrinderEntry r : this.recipes ) { - if( Platform.isSameItem( input, r.getInput() ) ) + if( Platform.itemComparisons().isEqualItem( input, r.getInput() ) ) { this.log( "Recipe for " + input.getUnlocalizedName() + " found " + Platform.getItemDisplayName( r.getOutput() ) ); return r; diff --git a/src/main/java/appeng/core/features/registries/MatterCannonAmmoRegistry.java b/src/main/java/appeng/core/features/registries/MatterCannonAmmoRegistry.java index 47f31b8c..0e36f857 100644 --- a/src/main/java/appeng/core/features/registries/MatterCannonAmmoRegistry.java +++ b/src/main/java/appeng/core/features/registries/MatterCannonAmmoRegistry.java @@ -52,7 +52,7 @@ public class MatterCannonAmmoRegistry implements IOreListener, IMatterCannonAmmo { for( final ItemStack o : this.DamageModifiers.keySet() ) { - if( Platform.isSameItem( o, is ) ) + if( Platform.itemComparisons().isEqualItem( o, is ) ) { return this.DamageModifiers.get( o ).floatValue(); } diff --git a/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java b/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java index 8d6e1d2c..e7970de8 100644 --- a/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java +++ b/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java @@ -146,7 +146,7 @@ public final class P2PTunnelRegistry implements IP2PTunnelRegistry return this.tunnels.get( is ); } - if( Platform.isSameItem( is, trigger ) ) + if( Platform.itemComparisons().isEqualItem( is, trigger ) ) { return this.tunnels.get( is ); } diff --git a/src/main/java/appeng/core/stats/AchievementCraftingHandler.java b/src/main/java/appeng/core/stats/AchievementCraftingHandler.java index 15a0b26b..1817389b 100644 --- a/src/main/java/appeng/core/stats/AchievementCraftingHandler.java +++ b/src/main/java/appeng/core/stats/AchievementCraftingHandler.java @@ -54,7 +54,7 @@ public class AchievementCraftingHandler switch( achievement.getType() ) { case Craft: - if( Platform.isSameItemPrecise( achievement.getStack(), event.crafting ) ) + if( Platform.itemComparisons().isSameItem( achievement.getStack(), event.crafting ) ) { achievement.addToPlayer( event.player ); return; diff --git a/src/main/java/appeng/core/stats/AchievementPickupHandler.java b/src/main/java/appeng/core/stats/AchievementPickupHandler.java index 41cc0bbe..1bc22118 100644 --- a/src/main/java/appeng/core/stats/AchievementPickupHandler.java +++ b/src/main/java/appeng/core/stats/AchievementPickupHandler.java @@ -54,7 +54,7 @@ public class AchievementPickupHandler for( final Achievements achievement : Achievements.values() ) { - if( achievement.getType() == AchievementType.Pickup && Platform.isSameItemPrecise( achievement.getStack(), is ) ) + if( achievement.getType() == AchievementType.Pickup && Platform.itemComparisons().isSameItem( achievement.getStack(), is ) ) { achievement.addToPlayer( event.player ); return; diff --git a/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java b/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java index 292eb98d..cb187306 100644 --- a/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java +++ b/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java @@ -167,7 +167,7 @@ public class PacketJEIRecipe extends AppEngPacket final ItemStack newItemStack = r.matches( testInv, pmp.worldObj ) ? r.getCraftingResult( testInv ) : null; testInv.setInventorySlotContents( x, patternItem ); - if( newItemStack == null || !Platform.isSameItemPrecise( newItemStack, is ) ) + if( newItemStack == null || !Platform.itemComparisons().isSameItem( newItemStack, is ) ) { final IAEItemStack in = AEItemStack.create( currentItem ); if( in != null ) diff --git a/src/main/java/appeng/entity/EntityChargedQuartz.java b/src/main/java/appeng/entity/EntityChargedQuartz.java index a12a7e51..ef2eafde 100644 --- a/src/main/java/appeng/entity/EntityChargedQuartz.java +++ b/src/main/java/appeng/entity/EntityChargedQuartz.java @@ -119,12 +119,12 @@ public final class EntityChargedQuartz extends AEBaseEntityItem final ItemStack other = ( (EntityItem) e ).getEntityItem(); if( other != null && other.stackSize > 0 ) { - if( Platform.isSameItem( other, new ItemStack( Items.REDSTONE ) ) ) + if( Platform.itemComparisons().isEqualItem( other, new ItemStack( Items.REDSTONE ) ) ) { redstone = (EntityItem) e; } - if( Platform.isSameItem( other, new ItemStack( Items.QUARTZ ) ) ) + if( Platform.itemComparisons().isEqualItem( other, new ItemStack( Items.QUARTZ ) ) ) { netherQuartz = (EntityItem) e; } diff --git a/src/main/java/appeng/helpers/PatternHelper.java b/src/main/java/appeng/helpers/PatternHelper.java index bc99fecd..3eb2ff6d 100644 --- a/src/main/java/appeng/helpers/PatternHelper.java +++ b/src/main/java/appeng/helpers/PatternHelper.java @@ -245,7 +245,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable, ITickingMo return true; } - return !Platform.isSameItemPrecise( a, b ); + return !Platform.itemComparisons().isSameItem( a, b ); } private void postDifference( final Iterable a ) diff --git a/src/main/java/appeng/parts/CableBusContainer.java b/src/main/java/appeng/parts/CableBusContainer.java index e2be73f1..e30bcc5d 100644 --- a/src/main/java/appeng/parts/CableBusContainer.java +++ b/src/main/java/appeng/parts/CableBusContainer.java @@ -1066,7 +1066,7 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I final ItemStack current = p == null ? null : p.getItemStack( PartItemStack.WORLD ); - if( Platform.isSameItemType( iss, current ) ) + if( Platform.itemComparisons().isEqualItemType( iss, current ) ) { p.readFromNBT( extra ); } diff --git a/src/main/java/appeng/parts/automation/StackUpgradeInventory.java b/src/main/java/appeng/parts/automation/StackUpgradeInventory.java index 0611ad59..0ef879ba 100644 --- a/src/main/java/appeng/parts/automation/StackUpgradeInventory.java +++ b/src/main/java/appeng/parts/automation/StackUpgradeInventory.java @@ -43,7 +43,7 @@ public class StackUpgradeInventory extends UpgradeInventory for( final ItemStack is : upgrades.getSupported().keySet() ) { - if( Platform.isSameItem( this.stack, is ) ) + if( Platform.itemComparisons().isEqualItem( this.stack, is ) ) { max = upgrades.getSupported().get( is ); break; diff --git a/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java b/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java index 6cfdc984..eaef832a 100644 --- a/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java +++ b/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java @@ -111,7 +111,7 @@ class ItemHandlerAdapter implements IMEInventory, IBaseMonitor, IBaseMonitor a ) diff --git a/src/main/java/appeng/parts/p2p/PartP2PTunnel.java b/src/main/java/appeng/parts/p2p/PartP2PTunnel.java index 06125932..e75d193c 100644 --- a/src/main/java/appeng/parts/p2p/PartP2PTunnel.java +++ b/src/main/java/appeng/parts/p2p/PartP2PTunnel.java @@ -270,7 +270,7 @@ public abstract class PartP2PTunnel extends PartBasicSt break; } - if( newType != null && !Platform.isSameItem( newType, this.getItemStack() ) ) + if( newType != null && !Platform.itemComparisons().isEqualItem( newType, this.getItemStack() ) ) { final boolean oldOutput = this.isOutput(); final long myFreq = this.getFrequency(); diff --git a/src/main/java/appeng/recipes/handlers/Crusher.java b/src/main/java/appeng/recipes/handlers/Crusher.java index ee0a573e..5754012a 100644 --- a/src/main/java/appeng/recipes/handlers/Crusher.java +++ b/src/main/java/appeng/recipes/handlers/Crusher.java @@ -87,6 +87,6 @@ public class Crusher implements ICraftHandler, IWebsiteSerializer @Override public boolean canCraft( final ItemStack output ) throws RegistrationError, MissingIngredientError { - return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output ); + return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output ); } } diff --git a/src/main/java/appeng/recipes/handlers/Grind.java b/src/main/java/appeng/recipes/handlers/Grind.java index fe1c2fc3..5bfab1e3 100644 --- a/src/main/java/appeng/recipes/handlers/Grind.java +++ b/src/main/java/appeng/recipes/handlers/Grind.java @@ -73,6 +73,6 @@ public class Grind implements ICraftHandler, IWebsiteSerializer @Override public boolean canCraft( final ItemStack output ) throws RegistrationError, MissingIngredientError { - return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output ); + return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output ); } } diff --git a/src/main/java/appeng/recipes/handlers/GrindFZ.java b/src/main/java/appeng/recipes/handlers/GrindFZ.java index eb0ef12e..ac5e43e2 100644 --- a/src/main/java/appeng/recipes/handlers/GrindFZ.java +++ b/src/main/java/appeng/recipes/handlers/GrindFZ.java @@ -87,6 +87,6 @@ public class GrindFZ implements ICraftHandler, IWebsiteSerializer @Override public boolean canCraft( final ItemStack output ) throws RegistrationError, MissingIngredientError { - return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output ); + return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output ); } } diff --git a/src/main/java/appeng/recipes/handlers/HCCrusher.java b/src/main/java/appeng/recipes/handlers/HCCrusher.java index 1cc3547a..a0ef8dba 100644 --- a/src/main/java/appeng/recipes/handlers/HCCrusher.java +++ b/src/main/java/appeng/recipes/handlers/HCCrusher.java @@ -96,6 +96,6 @@ public class HCCrusher implements ICraftHandler, IWebsiteSerializer @Override public boolean canCraft( final ItemStack output ) throws RegistrationError, MissingIngredientError { - return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output ); + return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output ); } } diff --git a/src/main/java/appeng/recipes/handlers/InscriberProcess.java b/src/main/java/appeng/recipes/handlers/InscriberProcess.java index 198142e4..0032b366 100644 --- a/src/main/java/appeng/recipes/handlers/InscriberProcess.java +++ b/src/main/java/appeng/recipes/handlers/InscriberProcess.java @@ -88,7 +88,7 @@ public abstract class InscriberProcess implements ICraftHandler, IWebsiteSeriali @Override public boolean canCraft( final ItemStack reqOutput ) throws RegistrationError, MissingIngredientError { - return this.output != null && Platform.isSameItemPrecise( this.output.getItemStack(), reqOutput ); + return this.output != null && Platform.itemComparisons().isSameItem( this.output.getItemStack(), reqOutput ); } @Override diff --git a/src/main/java/appeng/recipes/handlers/Macerator.java b/src/main/java/appeng/recipes/handlers/Macerator.java index ca242073..8dea1c93 100644 --- a/src/main/java/appeng/recipes/handlers/Macerator.java +++ b/src/main/java/appeng/recipes/handlers/Macerator.java @@ -87,6 +87,6 @@ public class Macerator implements ICraftHandler, IWebsiteSerializer @Override public boolean canCraft( final ItemStack output ) throws RegistrationError, MissingIngredientError { - return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output ); + return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output ); } } diff --git a/src/main/java/appeng/recipes/handlers/MekCrusher.java b/src/main/java/appeng/recipes/handlers/MekCrusher.java index 62af1e22..371ecc07 100644 --- a/src/main/java/appeng/recipes/handlers/MekCrusher.java +++ b/src/main/java/appeng/recipes/handlers/MekCrusher.java @@ -88,6 +88,6 @@ public class MekCrusher implements ICraftHandler, IWebsiteSerializer @Override public boolean canCraft( final ItemStack output ) throws RegistrationError, MissingIngredientError { - return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output ); + return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output ); } } diff --git a/src/main/java/appeng/recipes/handlers/MekEnrichment.java b/src/main/java/appeng/recipes/handlers/MekEnrichment.java index 2b4ca41c..e5037725 100644 --- a/src/main/java/appeng/recipes/handlers/MekEnrichment.java +++ b/src/main/java/appeng/recipes/handlers/MekEnrichment.java @@ -87,6 +87,6 @@ public class MekEnrichment implements ICraftHandler, IWebsiteSerializer @Override public boolean canCraft( final ItemStack output ) throws RegistrationError, MissingIngredientError { - return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output ); + return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output ); } } diff --git a/src/main/java/appeng/recipes/handlers/Pulverizer.java b/src/main/java/appeng/recipes/handlers/Pulverizer.java index 505b0a80..f5bb0b6b 100644 --- a/src/main/java/appeng/recipes/handlers/Pulverizer.java +++ b/src/main/java/appeng/recipes/handlers/Pulverizer.java @@ -82,6 +82,6 @@ public class Pulverizer implements ICraftHandler, IWebsiteSerializer @Override public boolean canCraft( final ItemStack output ) throws RegistrationError, MissingIngredientError { - return Platform.isSameItemPrecise( this.pro_output[0].getItemStack(), output ); + return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output ); } } diff --git a/src/main/java/appeng/recipes/handlers/Shaped.java b/src/main/java/appeng/recipes/handlers/Shaped.java index 58687d97..f8556b6e 100644 --- a/src/main/java/appeng/recipes/handlers/Shaped.java +++ b/src/main/java/appeng/recipes/handlers/Shaped.java @@ -162,7 +162,7 @@ public class Shaped implements ICraftHandler, IWebsiteSerializer { for( final ItemStack r : i.getItemStackSet() ) { - if( Platform.isSameItemPrecise( r, reqOutput ) ) + if( Platform.itemComparisons().isSameItem( r, reqOutput ) ) { return false; } @@ -171,6 +171,6 @@ public class Shaped implements ICraftHandler, IWebsiteSerializer } } - return Platform.isSameItemPrecise( this.output.getItemStack(), reqOutput ); + return Platform.itemComparisons().isSameItem( this.output.getItemStack(), reqOutput ); } } diff --git a/src/main/java/appeng/recipes/handlers/Shapeless.java b/src/main/java/appeng/recipes/handlers/Shapeless.java index 840f5fe9..fb7aa47a 100644 --- a/src/main/java/appeng/recipes/handlers/Shapeless.java +++ b/src/main/java/appeng/recipes/handlers/Shapeless.java @@ -128,7 +128,7 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer { for( final ItemStack r : i.getItemStackSet() ) { - if( Platform.isSameItemPrecise( r, reqOutput ) ) + if( Platform.itemComparisons().isSameItem( r, reqOutput ) ) { return false; } @@ -136,6 +136,6 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer } } - return Platform.isSameItemPrecise( this.output.getItemStack(), reqOutput ); + return Platform.itemComparisons().isSameItem( this.output.getItemStack(), reqOutput ); } } diff --git a/src/main/java/appeng/recipes/handlers/Smelt.java b/src/main/java/appeng/recipes/handlers/Smelt.java index 8f62ee9a..7d87d761 100644 --- a/src/main/java/appeng/recipes/handlers/Smelt.java +++ b/src/main/java/appeng/recipes/handlers/Smelt.java @@ -81,6 +81,6 @@ public class Smelt implements ICraftHandler, IWebsiteSerializer @Override public boolean canCraft( final ItemStack reqOutput ) throws RegistrationError, MissingIngredientError { - return Platform.isSameItemPrecise( this.out.getItemStack(), reqOutput ); + return Platform.itemComparisons().isSameItem( this.out.getItemStack(), reqOutput ); } } diff --git a/src/main/java/appeng/tile/crafting/TileMolecularAssembler.java b/src/main/java/appeng/tile/crafting/TileMolecularAssembler.java index 95c780b1..13bd9717 100644 --- a/src/main/java/appeng/tile/crafting/TileMolecularAssembler.java +++ b/src/main/java/appeng/tile/crafting/TileMolecularAssembler.java @@ -271,7 +271,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade if( is != null && is.getItem() instanceof ItemEncodedPattern ) { - if( !Platform.isSameItem( is, this.myPattern ) ) + if( !Platform.itemComparisons().isEqualItem( is, this.myPattern ) ) { final World w = this.getWorld(); final ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem(); diff --git a/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java b/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java index 87594e16..7d778b49 100644 --- a/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java +++ b/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java @@ -194,7 +194,7 @@ public class AppEngInternalAEInventory implements IInventory, Iterable newItemStack.stackSize ) { diff --git a/src/main/java/appeng/tile/inventory/AppEngInternalInventory.java b/src/main/java/appeng/tile/inventory/AppEngInternalInventory.java index 1cb5bfbb..e5696510 100644 --- a/src/main/java/appeng/tile/inventory/AppEngInternalInventory.java +++ b/src/main/java/appeng/tile/inventory/AppEngInternalInventory.java @@ -124,7 +124,7 @@ public class AppEngInternalInventory implements IInventory, Iterable ItemStack removed = oldStack; ItemStack added = newItemStack; - if( oldStack != null && newItemStack != null && Platform.isSameItem( oldStack, newItemStack ) ) + if( oldStack != null && newItemStack != null && Platform.itemComparisons().isEqualItem( oldStack, newItemStack ) ) { if( oldStack.stackSize > newItemStack.stackSize ) { diff --git a/src/main/java/appeng/tile/misc/TileCondenser.java b/src/main/java/appeng/tile/misc/TileCondenser.java index 937192d4..a47b91e2 100644 --- a/src/main/java/appeng/tile/misc/TileCondenser.java +++ b/src/main/java/appeng/tile/misc/TileCondenser.java @@ -135,7 +135,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost, private boolean canAddOutput( final ItemStack output ) { final ItemStack outputStack = this.getStackInSlot( 1 ); - return outputStack == null || ( Platform.isSameItem( outputStack, output ) && outputStack.stackSize < outputStack.getMaxStackSize() ); + return outputStack == null || ( Platform.itemComparisons().isEqualItem( outputStack, output ) && outputStack.stackSize < outputStack.getMaxStackSize() ); } /** diff --git a/src/main/java/appeng/tile/misc/TileInscriber.java b/src/main/java/appeng/tile/misc/TileInscriber.java index 1b0284ce..6fc97199 100644 --- a/src/main/java/appeng/tile/misc/TileInscriber.java +++ b/src/main/java/appeng/tile/misc/TileInscriber.java @@ -256,7 +256,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable, for( final ItemStack optionals : AEApi.instance().registries().inscriber().getOptionals() ) { - if( Platform.isSameItemPrecise( optionals, itemstack ) ) + if( Platform.itemComparisons().isSameItem( optionals, itemstack ) ) { return true; } @@ -410,17 +410,17 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable, for( final IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes() ) { - final boolean matchA = ( plateA == null && !recipe.getTopOptional().isPresent() ) || ( Platform.isSameItemPrecise( plateA, recipe.getTopOptional().orElse( null ) ) ) && // and... - ( plateB == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.isSameItemPrecise( plateB, recipe.getBottomOptional().orElse( null ) ) ); + final boolean matchA = ( plateA == null && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( plateA, recipe.getTopOptional().orElse( null ) ) ) && // and... + ( plateB == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( plateB, recipe.getBottomOptional().orElse( null ) ) ); - final boolean matchB = ( plateB == null && !recipe.getTopOptional().isPresent() ) || ( Platform.isSameItemPrecise( plateB, recipe.getTopOptional().orElse( null ) ) ) && // and... - ( plateA == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.isSameItemPrecise( plateA, recipe.getBottomOptional().orElse( null ) ) ); + final boolean matchB = ( plateB == null && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( plateB, recipe.getTopOptional().orElse( null ) ) ) && // and... + ( plateA == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( plateA, recipe.getBottomOptional().orElse( null ) ) ); if( matchA || matchB ) { for( final ItemStack option : recipe.getInputs() ) { - if( Platform.isSameItemPrecise( option, this.getStackInSlot( 2 ) ) ) + if( Platform.itemComparisons().isSameItem( option, this.getStackInSlot( 2 ) ) ) { return recipe; } diff --git a/src/main/java/appeng/tile/storage/TileChest.java b/src/main/java/appeng/tile/storage/TileChest.java index 4ba80666..15294d8f 100644 --- a/src/main/java/appeng/tile/storage/TileChest.java +++ b/src/main/java/appeng/tile/storage/TileChest.java @@ -467,7 +467,7 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan this.lastStateChange = this.worldObj.getTotalWorldTime(); - return oldPaintedColor != this.paintedColor || ( this.state & 0xDB6DB6DB ) != ( oldState & 0xDB6DB6DB ) || !Platform.isSameItemPrecise( oldType, this.storageType ); + return oldPaintedColor != this.paintedColor || ( this.state & 0xDB6DB6DB ) != ( oldState & 0xDB6DB6DB ) || !Platform.itemComparisons().isSameItem( oldType, this.storageType ); } @TileEvent( TileEventType.WORLD_NBT_READ ) diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index fe68bec0..f731badd 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -19,7 +19,6 @@ package appeng.util; -import java.lang.reflect.Field; import java.lang.reflect.Method; import java.security.InvalidParameterException; import java.text.DecimalFormat; @@ -30,8 +29,8 @@ import java.util.EnumSet; import java.util.LinkedList; import java.util.List; import java.util.Random; -import java.util.Set; import java.util.WeakHashMap; + import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -55,11 +54,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTPrimitive; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; import net.minecraft.network.play.server.SPacketChunkData; import net.minecraft.server.management.PlayerChunkMap; import net.minecraft.server.management.PlayerChunkMapEntry; @@ -90,7 +85,6 @@ import net.minecraftforge.oredict.OreDictionary; import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; -import appeng.api.config.FuzzyMode; import appeng.api.config.PowerMultiplier; import appeng.api.config.PowerUnits; import appeng.api.config.SearchBoxMode; @@ -137,10 +131,9 @@ import appeng.integration.IntegrationType; import appeng.me.GridAccessException; import appeng.me.GridNode; import appeng.me.helpers.AENetworkProxy; +import appeng.util.helpers.ItemComparisonHelper; import appeng.util.item.AEItemStack; import appeng.util.item.AESharedNBT; -import appeng.util.item.OreHelper; -import appeng.util.item.OreReference; import appeng.util.prioritylist.IPartitionList; @@ -162,9 +155,15 @@ public class Platform */ private static final Random RANDOM_GENERATOR = new Random(); private static final WeakHashMap FAKE_PLAYERS = new WeakHashMap(); - private static Field tagList; private static Method getEntry; + private static final ItemComparisonHelper ITEM_COMPARISON_HELPER = new ItemComparisonHelper(); + + public static ItemComparisonHelper itemComparisons() + { + return ITEM_COMPARISON_HELPER; + } + public static Random getRandom() { return RANDOM_GENERATOR; @@ -423,251 +422,6 @@ public class Platform } } - /* - * Lots of silliness to try and account for weird tag related junk, basically requires that two tags have at least - * something in their tags before it wasts its time comparing them. - */ - private static boolean sameStackStags( final ItemStack a, final ItemStack b ) - { - if( a == null && b == null ) - { - return true; - } - if( a == null || b == null ) - { - return false; - } - if( a == b ) - { - return true; - } - - final NBTTagCompound ta = a.getTagCompound(); - final NBTTagCompound tb = b.getTagCompound(); - if( ta == tb ) - { - return true; - } - - if( ( ta == null && tb == null ) || ( ta != null && ta.hasNoTags() && tb == null ) || ( tb != null && tb.hasNoTags() && ta == null ) || ( ta != null && ta.hasNoTags() && tb != null && tb.hasNoTags() ) ) - { - return true; - } - - if( ( ta == null && tb != null ) || ( ta != null && tb == null ) ) - { - return false; - } - - // if both tags are shared this is easy... - if( AESharedNBT.isShared( ta ) && AESharedNBT.isShared( tb ) ) - { - return ta == tb; - } - - return NBTEqualityTest( ta, tb ); - } - - /* - * recursive test for NBT Equality, this was faster then trying to compare / generate hashes, its also more reliable - * then the vanilla version which likes to fail when NBT Compound data changes order, it is pretty expensive - * performance wise, so try an use shared tag compounds as long as the system remains in AE. - */ - public static boolean NBTEqualityTest( final NBTBase left, final NBTBase right ) - { - // same type? - final byte id = left.getId(); - if( id == right.getId() ) - { - switch( id ) - { - case 10: - { - final NBTTagCompound ctA = (NBTTagCompound) left; - final NBTTagCompound ctB = (NBTTagCompound) right; - - final Set cA = ctA.getKeySet(); - final Set cB = ctB.getKeySet(); - - if( cA.size() != cB.size() ) - { - return false; - } - - for( final String name : cA ) - { - final NBTBase tag = ctA.getTag( name ); - final NBTBase aTag = ctB.getTag( name ); - if( aTag == null ) - { - return false; - } - - if( !NBTEqualityTest( tag, aTag ) ) - { - return false; - } - } - - return true; - } - - case 9: // ) // A instanceof NBTTagList ) - { - final NBTTagList lA = (NBTTagList) left; - final NBTTagList lB = (NBTTagList) right; - if( lA.tagCount() != lB.tagCount() ) - { - return false; - } - - final List tag = tagList( lA ); - final List aTag = tagList( lB ); - if( tag.size() != aTag.size() ) - { - return false; - } - - for( int x = 0; x < tag.size(); x++ ) - { - if( aTag.get( x ) == null ) - { - return false; - } - - if( !NBTEqualityTest( tag.get( x ), aTag.get( x ) ) ) - { - return false; - } - } - - return true; - } - - case 1: // ( A instanceof NBTTagByte ) - return ( (NBTPrimitive) left ).getByte() == ( (NBTPrimitive) right ).getByte(); - - case 4: // else if ( A instanceof NBTTagLong ) - return ( (NBTPrimitive) left ).getLong() == ( (NBTPrimitive) right ).getLong(); - - case 8: // else if ( A instanceof NBTTagString ) - return ( (NBTTagString) left ).getString().equals( ( (NBTTagString) right ).getString() ) || ( (NBTTagString) left ).getString().equals( ( (NBTTagString) right ).getString() ); - - case 6: // else if ( A instanceof NBTTagDouble ) - return ( (NBTPrimitive) left ).getDouble() == ( (NBTPrimitive) right ).getDouble(); - - case 5: // else if ( A instanceof NBTTagFloat ) - return ( (NBTPrimitive) left ).getFloat() == ( (NBTPrimitive) right ).getFloat(); - - case 3: // else if ( A instanceof NBTTagInt ) - return ( (NBTPrimitive) left ).getInt() == ( (NBTPrimitive) right ).getInt(); - - default: - return left.equals( right ); - } - } - - return false; - } - - private static List tagList( final NBTTagList lB ) - { - if( tagList == null ) - { - try - { - tagList = lB.getClass().getDeclaredField( "tagList" ); - } - catch( final Throwable t ) - { - try - { - tagList = lB.getClass().getDeclaredField( "field_74747_a" ); - } - catch( final Throwable z ) - { - AELog.debug( t ); - AELog.debug( z ); - } - } - } - - try - { - tagList.setAccessible( true ); - return (List) tagList.get( lB ); - } - catch( final Throwable t ) - { - AELog.debug( t ); - } - - return new ArrayList(); - } - - /* - * Orderless hash on NBT Data, used to work thought huge piles fast, but ignores the order just in case MC decided - * to change it... WHICH IS BAD... - */ - public static int NBTOrderlessHash( final NBTBase nbt ) - { - // same type? - int hash = 0; - final byte id = nbt.getId(); - hash += id; - switch( id ) - { - case 10: - { - final NBTTagCompound ctA = (NBTTagCompound) nbt; - - final Set cA = ctA.getKeySet(); - - for( final String name : cA ) - { - hash += name.hashCode() ^ NBTOrderlessHash( ctA.getTag( name ) ); - } - - return hash; - } - - case 9: // ) // A instanceof NBTTagList ) - { - final NBTTagList lA = (NBTTagList) nbt; - hash += 9 * lA.tagCount(); - - final List l = tagList( lA ); - for( int x = 0; x < l.size(); x++ ) - { - hash += ( (Integer) x ).hashCode() ^ NBTOrderlessHash( l.get( x ) ); - } - - return hash; - } - - case 1: // ( A instanceof NBTTagByte ) - return hash + ( (NBTPrimitive) nbt ).getByte(); - - case 4: // else if ( A instanceof NBTTagLong ) - return hash + (int) ( (NBTPrimitive) nbt ).getLong(); - - case 8: // else if ( A instanceof NBTTagString ) - return hash + ( (NBTTagString) nbt ).getString().hashCode(); - - case 6: // else if ( A instanceof NBTTagDouble ) - return hash + (int) ( (NBTPrimitive) nbt ).getDouble(); - - case 5: // else if ( A instanceof NBTTagFloat ) - return hash + (int) ( (NBTPrimitive) nbt ).getFloat(); - - case 3: // else if ( A instanceof NBTTagInt ) - return hash + ( (NBTPrimitive) nbt ).getInt(); - - default: - return hash; - } - } - /* * The usual version of this returns an ItemStack, this version returns the recipe. */ @@ -1127,7 +881,7 @@ public class Platform } return -1; } - + public static int findEmpty( final Object[] l ) { for( int x = 0; x < l.length; x++ ) @@ -1142,6 +896,7 @@ public class Platform /** * Returns a random element from the given collection. + * * @return null if the collection is empty */ @Nullable @@ -1371,102 +1126,6 @@ public class Platform return I18n.translateToLocal( string ); } - public static boolean isSameItemPrecise( @Nullable final ItemStack is, @Nullable final ItemStack filter ) - { - return isSameItem( is, filter ) && sameStackStags( is, filter ); - } - - public static boolean isSameItemFuzzy( final ItemStack a, final ItemStack b, final FuzzyMode mode ) - { - if( a == null && b == null ) - { - return true; - } - - if( a == null ) - { - return false; - } - - if( b == null ) - { - return false; - } - - /* - * if ( a.itemID != 0 && b.itemID != 0 && a.isItemStackDamageable() && ! a.getHasSubtypes() && a.itemID == - * b.itemID ) { return (a.getItemDamage() > 0) == (b.getItemDamage() > 0); } - */ - - // test damageable items.. - if( a.getItem() != null && b.getItem() != null && a.getItem().isDamageable() && a.getItem() == b.getItem() ) - { - try - { - if( mode == FuzzyMode.IGNORE_ALL ) - { - return true; - } - else if( mode == FuzzyMode.PERCENT_99 ) - { - final Item ai = a.getItem(); - final Item bi = b.getItem(); - - return ( ai.getDurabilityForDisplay( a ) > 1 ) == ( bi.getDurabilityForDisplay( b ) > 1 ); - } - else - { - final Item ai = a.getItem(); - final Item bi = b.getItem(); - - final float percentDamagedOfA = 1.0f - (float) ai.getDurabilityForDisplay( a ); - final float percentDamagedOfB = 1.0f - (float) bi.getDurabilityForDisplay( b ); - - return ( percentDamagedOfA > mode.breakPoint ) == ( percentDamagedOfB > mode.breakPoint ); - } - } - catch( final Throwable e ) - { - if( mode == FuzzyMode.IGNORE_ALL ) - { - return true; - } - else if( mode == FuzzyMode.PERCENT_99 ) - { - return ( a.getItemDamage() > 1 ) == ( b.getItemDamage() > 1 ); - } - else - { - final float percentDamagedOfA = (float) a.getItemDamage() / (float) a.getMaxDamage(); - final float percentDamagedOfB = (float) b.getItemDamage() / (float) b.getMaxDamage(); - - return ( percentDamagedOfA > mode.breakPoint ) == ( percentDamagedOfB > mode.breakPoint ); - } - } - } - - final OreReference aOR = OreHelper.INSTANCE.isOre( a ); - final OreReference bOR = OreHelper.INSTANCE.isOre( b ); - - if( OreHelper.INSTANCE.sameOre( aOR, bOR ) ) - { - return true; - } - - /* - * // test ore dictionary.. int OreID = getOreID( a ); if ( OreID != -1 ) return OreID == getOreID( b ); - * if ( Mode != FuzzyMode.IGNORE_ALL ) { if ( a.hasTagCompound() && !isShared( a.getTagCompound() ) ) { a = - * Platform.getSharedItemStack( AEItemStack.create( a ) ); } - * if ( b.hasTagCompound() && !isShared( b.getTagCompound() ) ) { b = Platform.getSharedItemStack( - * AEItemStack.create( b ) ); } - * // test regular items with damage values and what not... if ( isShared( a.getTagCompound() ) && isShared( - * b.getTagCompound() ) && a.itemID == b.itemID ) { return ((AppEngSharedNBTTagCompound) - * a.getTagCompound()).compareFuzzyWithRegistry( (AppEngSharedNBTTagCompound) b.getTagCompound() ); } } - */ - - return a.isItemEqual( b ); - } - public static LookDirection getPlayerRay( final EntityPlayer playerIn, final float eyeOffset ) { double reachDistance = 5.0d; @@ -1982,12 +1641,12 @@ public class Platform for( final IAEItemStack x : items ) { final ItemStack sh = x.getItemStack(); - if( ( Platform.isSameItemType( providedTemplate, sh ) || ae_req.sameOre( x ) ) && !Platform.isSameItem( sh, output ) ) + if( ( Platform.itemComparisons().isEqualItemType( providedTemplate, sh ) || ae_req.sameOre( x ) ) && !Platform.itemComparisons().isEqualItem( sh, output ) ) { // Platform.isSameItemType( sh, providedTemplate ) final ItemStack cp = Platform.cloneItemStack( sh ); cp.stackSize = 1; ci.setInventorySlotContents( slot, cp ); - if( r.matches( ci, w ) && Platform.isSameItem( r.getCraftingResult( ci ), output ) ) + if( r.matches( ci, w ) && Platform.itemComparisons().isEqualItem( r.getCraftingResult( ci ), output ) ) { final IAEItemStack ax = x.copy(); ax.setStackSize( 1 ); @@ -2009,24 +1668,6 @@ public class Platform return null; } - public static boolean isSameItemType( final ItemStack that, final ItemStack other ) - { - if( that != null && other != null && that.getItem() == other.getItem() ) - { - if( that.isItemStackDamageable() ) - { - return true; - } - return that.getItemDamage() == other.getItemDamage(); - } - return false; - } - - public static boolean isSameItem( @Nullable final ItemStack left, @Nullable final ItemStack right ) - { - return left != null && right != null && left.isItemEqual( right ); - } - public static ItemStack cloneItemStack( final ItemStack a ) { return a.copy(); @@ -2097,22 +1738,22 @@ public class Platform { if( parts.cableGlass().sameAs( AEColor.TRANSPARENT, stack ) ) { - return Collections.singletonList(stack); + return Collections.singletonList( stack ); } if( parts.cableCovered().sameAs( AEColor.TRANSPARENT, stack ) ) { - return Collections.singletonList(stack); + return Collections.singletonList( stack ); } if( parts.cableSmart().sameAs( AEColor.TRANSPARENT, stack ) ) { - return Collections.singletonList(stack); + return Collections.singletonList( stack ); } if( parts.cableDense().sameAs( AEColor.TRANSPARENT, stack ) ) { - return Collections.singletonList(stack); + return Collections.singletonList( stack ); } } diff --git a/src/main/java/appeng/util/helpers/ItemComparisonHelper.java b/src/main/java/appeng/util/helpers/ItemComparisonHelper.java new file mode 100644 index 00000000..c20df902 --- /dev/null +++ b/src/main/java/appeng/util/helpers/ItemComparisonHelper.java @@ -0,0 +1,443 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.util.helpers; + + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import javax.annotation.Nullable; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTPrimitive; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import net.minecraftforge.oredict.OreDictionary; + +import appeng.api.config.FuzzyMode; +import appeng.core.AELog; +import appeng.util.item.AESharedNBT; +import appeng.util.item.OreHelper; +import appeng.util.item.OreReference; + + +/** + * A helper class for comparing {@link Item}, {@link ItemStack} or NBT + * + */ +public class ItemComparisonHelper +{ + + private static Field tagList; + + /** + * Compare the two {@link ItemStack}s based on the same {@link Item} and damage value. + * + * In case of the item being damageable, only the {@link Item} will be considered. + * If not it will also compare both damage values. + * + * Ignores NBT. + * + * @return true, if both are equal. + */ + public boolean isEqualItemType( final ItemStack that, final ItemStack other ) + { + if( that != null && other != null && that.getItem() == other.getItem() ) + { + if( that.isItemStackDamageable() ) + { + return true; + } + return that.getItemDamage() == other.getItemDamage(); + } + return false; + } + + /** + * A wrapper around {@link ItemStack#isItemEqual(ItemStack)}. + * + * The benefit is to compare two null item stacks, without any additional null checks. + * + * Ignores NBT. + * + * @return true, if both are equal. + */ + public boolean isEqualItem( @Nullable final ItemStack left, @Nullable final ItemStack right ) + { + return left != null && right != null && left.isItemEqual( right ); + } + + /** + * Compares two {@link ItemStack} and their NBT tag for equality. + * + * Use this when a precise check is required and the same item is required. + * Not just something with different NBT tags. + * + * @return true, if both are identical. + */ + public boolean isSameItem( @Nullable final ItemStack is, @Nullable final ItemStack filter ) + { + return isEqualItem( is, filter ) && hasSameNbtTag( is, filter ); + } + + /** + * Similar to {@link ItemComparisonHelper#isEqualItem(ItemStack, ItemStack)}, + * but it can further check, if both match the same {@link FuzzyMode} + * or are considered equal by the {@link OreDictionary} + * + * @param mode how to compare the two {@link ItemStack}s + * @return true, if both are matching the mode or considered equal by the {@link OreDictionary} + */ + public boolean isFuzzyEqualItem( final ItemStack a, final ItemStack b, final FuzzyMode mode ) + { + if( a == null && b == null ) + { + return true; + } + + if( a == null || b == null ) + { + return false; + } + + /* + * if ( a.itemID != 0 && b.itemID != 0 && a.isItemStackDamageable() && ! a.getHasSubtypes() && a.itemID == + * b.itemID ) { return (a.getItemDamage() > 0) == (b.getItemDamage() > 0); } + */ + + // test damageable items.. + if( a.getItem() != null && b.getItem() != null && a.getItem().isDamageable() && a.getItem() == b.getItem() ) + { + try + { + if( mode == FuzzyMode.IGNORE_ALL ) + { + return true; + } + else if( mode == FuzzyMode.PERCENT_99 ) + { + final Item ai = a.getItem(); + final Item bi = b.getItem(); + + return ( ai.getDurabilityForDisplay( a ) > 1 ) == ( bi.getDurabilityForDisplay( b ) > 1 ); + } + else + { + final Item ai = a.getItem(); + final Item bi = b.getItem(); + + final float percentDamagedOfA = 1.0f - (float) ai.getDurabilityForDisplay( a ); + final float percentDamagedOfB = 1.0f - (float) bi.getDurabilityForDisplay( b ); + + return ( percentDamagedOfA > mode.breakPoint ) == ( percentDamagedOfB > mode.breakPoint ); + } + } + catch( final Throwable e ) + { + if( mode == FuzzyMode.IGNORE_ALL ) + { + return true; + } + else if( mode == FuzzyMode.PERCENT_99 ) + { + return ( a.getItemDamage() > 1 ) == ( b.getItemDamage() > 1 ); + } + else + { + final float percentDamagedOfA = (float) a.getItemDamage() / (float) a.getMaxDamage(); + final float percentDamagedOfB = (float) b.getItemDamage() / (float) b.getMaxDamage(); + + return ( percentDamagedOfA > mode.breakPoint ) == ( percentDamagedOfB > mode.breakPoint ); + } + } + } + + final OreReference aOR = OreHelper.INSTANCE.isOre( a ); + final OreReference bOR = OreHelper.INSTANCE.isOre( b ); + + if( OreHelper.INSTANCE.sameOre( aOR, bOR ) ) + { + return true; + } + + /* + * // test ore dictionary.. int OreID = getOreID( a ); if ( OreID != -1 ) return OreID == getOreID( b ); + * if ( Mode != FuzzyMode.IGNORE_ALL ) { if ( a.hasTagCompound() && !isShared( a.getTagCompound() ) ) { a = + * Platform.getSharedItemStack( AEItemStack.create( a ) ); } + * if ( b.hasTagCompound() && !isShared( b.getTagCompound() ) ) { b = Platform.getSharedItemStack( + * AEItemStack.create( b ) ); } + * // test regular items with damage values and what not... if ( isShared( a.getTagCompound() ) && isShared( + * b.getTagCompound() ) && a.itemID == b.itemID ) { return ((AppEngSharedNBTTagCompound) + * a.getTagCompound()).compareFuzzyWithRegistry( (AppEngSharedNBTTagCompound) b.getTagCompound() ); } } + */ + + return a.isItemEqual( b ); + } + + /** + * recursive test for NBT Equality, this was faster then trying to compare / generate hashes, its also more reliable + * then the vanilla version which likes to fail when NBT Compound data changes order, it is pretty expensive + * performance wise, so try an use shared tag compounds as long as the system remains in AE. + */ + public boolean isNbtTagEqual( final NBTBase left, final NBTBase right ) + { + // same type? + final byte id = left.getId(); + if( id == right.getId() ) + { + switch( id ) + { + case 10: + { + final NBTTagCompound ctA = (NBTTagCompound) left; + final NBTTagCompound ctB = (NBTTagCompound) right; + + final Set cA = ctA.getKeySet(); + final Set cB = ctB.getKeySet(); + + if( cA.size() != cB.size() ) + { + return false; + } + + for( final String name : cA ) + { + final NBTBase tag = ctA.getTag( name ); + final NBTBase aTag = ctB.getTag( name ); + if( aTag == null ) + { + return false; + } + + if( !isNbtTagEqual( tag, aTag ) ) + { + return false; + } + } + + return true; + } + + case 9: // ) // A instanceof NBTTagList ) + { + final NBTTagList lA = (NBTTagList) left; + final NBTTagList lB = (NBTTagList) right; + if( lA.tagCount() != lB.tagCount() ) + { + return false; + } + + final List tag = tagList( lA ); + final List aTag = tagList( lB ); + if( tag.size() != aTag.size() ) + { + return false; + } + + for( int x = 0; x < tag.size(); x++ ) + { + if( aTag.get( x ) == null ) + { + return false; + } + + if( !isNbtTagEqual( tag.get( x ), aTag.get( x ) ) ) + { + return false; + } + } + + return true; + } + + case 1: // NBTTagByte + return ( (NBTPrimitive) left ).getByte() == ( (NBTPrimitive) right ).getByte(); + + case 4: // NBTTagLong + return ( (NBTPrimitive) left ).getLong() == ( (NBTPrimitive) right ).getLong(); + + case 8: // NBTTagString + return ( (NBTTagString) left ).getString().equals( ( (NBTTagString) right ).getString() ); + + case 6: // NBTTagDouble + return ( (NBTPrimitive) left ).getDouble() == ( (NBTPrimitive) right ).getDouble(); + + case 5: // NBTTagFloat + return ( (NBTPrimitive) left ).getFloat() == ( (NBTPrimitive) right ).getFloat(); + + case 3: // NBTTagInt + return ( (NBTPrimitive) left ).getInt() == ( (NBTPrimitive) right ).getInt(); + + default: + return left.equals( right ); + } + } + + return false; + } + + /** + * Unordered hash of NBT Data, used to work thought huge piles fast, but ignores the order just in case MC + * decided to change it... WHICH IS BAD... + */ + public int createUnorderedNbtHash( final NBTBase nbt ) + { + // same type? + int hash = 0; + final byte id = nbt.getId(); + hash += id; + switch( id ) + { + case 10: + { + final NBTTagCompound ctA = (NBTTagCompound) nbt; + + final Set cA = ctA.getKeySet(); + + for( final String name : cA ) + { + hash += name.hashCode() ^ createUnorderedNbtHash( ctA.getTag( name ) ); + } + + return hash; + } + + case 9: // ) // A instanceof NBTTagList ) + { + final NBTTagList lA = (NBTTagList) nbt; + hash += 9 * lA.tagCount(); + + final List l = tagList( lA ); + for( int x = 0; x < l.size(); x++ ) + { + hash += ( (Integer) x ).hashCode() ^ createUnorderedNbtHash( l.get( x ) ); + } + + return hash; + } + + case 1: // NBTTagByte + return hash + ( (NBTPrimitive) nbt ).getByte(); + + case 4: // NBTTagLong + return hash + (int) ( (NBTPrimitive) nbt ).getLong(); + + case 8: // NBTTagString + return hash + ( (NBTTagString) nbt ).getString().hashCode(); + + case 6: // NBTTagDouble + return hash + (int) ( (NBTPrimitive) nbt ).getDouble(); + + case 5: // NBTTagFloat + return hash + (int) ( (NBTPrimitive) nbt ).getFloat(); + + case 3: // NBTTagInt + return hash + ( (NBTPrimitive) nbt ).getInt(); + + default: + return hash; + } + } + + /** + * Lots of silliness to try and account for weird tag related junk, basically requires that two tags have at least + * something in their tags before it wastes its time comparing them. + */ + private boolean hasSameNbtTag( final ItemStack a, final ItemStack b ) + { + if( a == null && b == null ) + { + return true; + } + if( a == null || b == null ) + { + return false; + } + if( a == b ) + { + return true; + } + + final NBTTagCompound ta = a.getTagCompound(); + final NBTTagCompound tb = b.getTagCompound(); + if( ta == tb ) + { + return true; + } + + if( ( ta == null && tb == null ) || ( ta != null && ta.hasNoTags() && tb == null ) || ( tb != null && tb.hasNoTags() && ta == null ) || ( ta != null && ta.hasNoTags() && tb != null && tb.hasNoTags() ) ) + { + return true; + } + + if( ( ta == null && tb != null ) || ( ta != null && tb == null ) ) + { + return false; + } + + // if both tags are shared this is easy... + if( AESharedNBT.isShared( ta ) && AESharedNBT.isShared( tb ) ) + { + return ta == tb; + } + + return isNbtTagEqual( ta, tb ); + } + + private List tagList( final NBTTagList lB ) + { + if( tagList == null ) + { + try + { + tagList = lB.getClass().getDeclaredField( "tagList" ); + } + catch( final Throwable t ) + { + try + { + tagList = lB.getClass().getDeclaredField( "field_74747_a" ); + } + catch( final Throwable z ) + { + AELog.debug( t ); + AELog.debug( z ); + } + } + } + + try + { + tagList.setAccessible( true ); + return (List) tagList.get( lB ); + } + catch( final Throwable t ) + { + AELog.debug( t ); + } + + return new ArrayList(); + } + +} diff --git a/src/main/java/appeng/util/inv/AdaptorIInventory.java b/src/main/java/appeng/util/inv/AdaptorIInventory.java index 97aeaf41..b4a574ed 100644 --- a/src/main/java/appeng/util/inv/AdaptorIInventory.java +++ b/src/main/java/appeng/util/inv/AdaptorIInventory.java @@ -50,7 +50,7 @@ public class AdaptorIInventory extends InventoryAdaptor for( int x = 0; x < s && amount > 0; x++ ) { final ItemStack is = this.i.getStackInSlot( x ); - if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) ) + if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.itemComparisons().isSameItem( is, filter ) ) ) { int boundAmounts = amount; if( boundAmounts > is.stackSize ) @@ -108,7 +108,7 @@ public class AdaptorIInventory extends InventoryAdaptor for( int x = 0; x < s && amount > 0; x++ ) { final ItemStack is = this.i.getStackInSlot( x ); - if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) ) + if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.itemComparisons().isSameItem( is, filter ) ) ) { int boundAmount = amount; if( boundAmount > is.stackSize ) @@ -147,7 +147,7 @@ public class AdaptorIInventory extends InventoryAdaptor for( int x = 0; x < s; x++ ) { final ItemStack is = this.i.getStackInSlot( x ); - if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) ) + if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) ) { int newAmount = amount; if( newAmount > is.stackSize ) @@ -197,7 +197,7 @@ public class AdaptorIInventory extends InventoryAdaptor { final ItemStack is = this.i.getStackInSlot( x ); - if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) ) + if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) ) { int boundAmount = amount; if( boundAmount > is.stackSize ) @@ -293,7 +293,7 @@ public class AdaptorIInventory extends InventoryAdaptor return null; } } - else if( Platform.isSameItemPrecise( is, left ) && is.stackSize < perOperationLimit ) + else if( Platform.itemComparisons().isSameItem( is, left ) && is.stackSize < perOperationLimit ) { final int room = perOperationLimit - is.stackSize; final int used = Math.min( left.stackSize, room ); diff --git a/src/main/java/appeng/util/inv/AdaptorItemHandler.java b/src/main/java/appeng/util/inv/AdaptorItemHandler.java index 12fb68aa..e1953084 100644 --- a/src/main/java/appeng/util/inv/AdaptorItemHandler.java +++ b/src/main/java/appeng/util/inv/AdaptorItemHandler.java @@ -47,7 +47,7 @@ public class AdaptorItemHandler extends InventoryAdaptor for( int slot = 0; slot < slots && amount > 0; slot++ ) { final ItemStack is = itemHandler.getStackInSlot( slot ); - if( is == null || ( filter != null && !Platform.isSameItemPrecise( is, filter ) ) ) + if( is == null || ( filter != null && !Platform.itemComparisons().isSameItem( is, filter ) ) ) { continue; } @@ -101,7 +101,7 @@ public class AdaptorItemHandler extends InventoryAdaptor for( int slot = 0; slot < slots && amount > 0; slot++ ) { final ItemStack is = itemHandler.getStackInSlot( slot ); - if( is != null && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) ) + if( is != null && ( filter == null || Platform.itemComparisons().isSameItem( is, filter ) ) ) { ItemStack extracted = itemHandler.extractItem( slot, amount, true ); @@ -149,7 +149,7 @@ public class AdaptorItemHandler extends InventoryAdaptor for( int slot = 0; slot < slots && extracted == null; slot++ ) { final ItemStack is = itemHandler.getStackInSlot( slot ); - if( is == null || ( filter != null && !Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) ) + if( is == null || ( filter != null && !Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) ) { continue; } @@ -184,7 +184,7 @@ public class AdaptorItemHandler extends InventoryAdaptor for( int slot = 0; slot < slots && extracted == null; slot++ ) { final ItemStack is = itemHandler.getStackInSlot( slot ); - if( is == null || ( filter != null && !Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) ) + if( is == null || ( filter != null && !Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) ) { continue; } @@ -229,7 +229,7 @@ public class AdaptorItemHandler extends InventoryAdaptor { ItemStack is = itemHandler.getStackInSlot( slot ); - if( is == null || Platform.isSameItemPrecise( is, left ) ) + if( is == null || Platform.itemComparisons().isSameItem( is, left ) ) { left = itemHandler.insertItem( slot, left, simulate ); diff --git a/src/main/java/appeng/util/inv/AdaptorList.java b/src/main/java/appeng/util/inv/AdaptorList.java index aae14c23..5d801a99 100644 --- a/src/main/java/appeng/util/inv/AdaptorList.java +++ b/src/main/java/appeng/util/inv/AdaptorList.java @@ -47,7 +47,7 @@ public class AdaptorList extends InventoryAdaptor for( int x = 0; x < s; x++ ) { final ItemStack is = this.i.get( x ); - if( is != null && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) ) + if( is != null && ( filter == null || Platform.itemComparisons().isSameItem( is, filter ) ) ) { if( amount > is.stackSize ) { @@ -82,7 +82,7 @@ public class AdaptorList extends InventoryAdaptor { for( final ItemStack is : this.i ) { - if( is != null && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) ) + if( is != null && ( filter == null || Platform.itemComparisons().isSameItem( is, filter ) ) ) { if( amount > is.stackSize ) { @@ -111,7 +111,7 @@ public class AdaptorList extends InventoryAdaptor for( int x = 0; x < s; x++ ) { final ItemStack is = this.i.get( x ); - if( is != null && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) ) + if( is != null && ( filter == null || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) ) { if( amount > is.stackSize ) { @@ -146,7 +146,7 @@ public class AdaptorList extends InventoryAdaptor { for( final ItemStack is : this.i ) { - if( is != null && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) ) + if( is != null && ( filter == null || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) ) { if( amount > is.stackSize ) { @@ -184,7 +184,7 @@ public class AdaptorList extends InventoryAdaptor for( final ItemStack is : this.i ) { - if( Platform.isSameItem( is, left ) ) + if( Platform.itemComparisons().isEqualItem( is, left ) ) { is.stackSize += left.stackSize; return null; diff --git a/src/main/java/appeng/util/inv/AdaptorPlayerHand.java b/src/main/java/appeng/util/inv/AdaptorPlayerHand.java index ce0ed7a3..95290073 100644 --- a/src/main/java/appeng/util/inv/AdaptorPlayerHand.java +++ b/src/main/java/appeng/util/inv/AdaptorPlayerHand.java @@ -52,7 +52,7 @@ public class AdaptorPlayerHand extends InventoryAdaptor return null; } - if( filter == null || Platform.isSameItemPrecise( filter, hand ) ) + if( filter == null || Platform.itemComparisons().isSameItem( filter, hand ) ) { final ItemStack result = hand.copy(); result.stackSize = hand.stackSize > amount ? amount : hand.stackSize; @@ -77,7 +77,7 @@ public class AdaptorPlayerHand extends InventoryAdaptor return null; } - if( filter == null || Platform.isSameItemPrecise( filter, hand ) ) + if( filter == null || Platform.itemComparisons().isSameItem( filter, hand ) ) { final ItemStack result = hand.copy(); result.stackSize = hand.stackSize > amount ? amount : hand.stackSize; @@ -96,7 +96,7 @@ public class AdaptorPlayerHand extends InventoryAdaptor return null; } - if( filter == null || Platform.isSameItemFuzzy( filter, hand, fuzzyMode ) ) + if( filter == null || Platform.itemComparisons().isFuzzyEqualItem( filter, hand, fuzzyMode ) ) { final ItemStack result = hand.copy(); result.stackSize = hand.stackSize > amount ? amount : hand.stackSize; @@ -121,7 +121,7 @@ public class AdaptorPlayerHand extends InventoryAdaptor return null; } - if( filter == null || Platform.isSameItemFuzzy( filter, hand, fuzzyMode ) ) + if( filter == null || Platform.itemComparisons().isFuzzyEqualItem( filter, hand, fuzzyMode ) ) { final ItemStack result = hand.copy(); result.stackSize = hand.stackSize > amount ? amount : hand.stackSize; @@ -154,7 +154,7 @@ public class AdaptorPlayerHand extends InventoryAdaptor final ItemStack hand = this.player.inventory.getItemStack(); - if( hand != null && !Platform.isSameItemPrecise( toBeAdded, hand ) ) + if( hand != null && !Platform.itemComparisons().isSameItem( toBeAdded, hand ) ) { return toBeAdded; } @@ -194,7 +194,7 @@ public class AdaptorPlayerHand extends InventoryAdaptor return null; } - if( hand != null && !Platform.isSameItem( toBeSimulated, hand ) ) + if( hand != null && !Platform.itemComparisons().isEqualItem( toBeSimulated, hand ) ) { return toBeSimulated; } diff --git a/src/main/java/appeng/util/item/AEFluidStack.java b/src/main/java/appeng/util/item/AEFluidStack.java index 7be937f0..1d972981 100644 --- a/src/main/java/appeng/util/item/AEFluidStack.java +++ b/src/main/java/appeng/util/item/AEFluidStack.java @@ -327,7 +327,7 @@ public final class AEFluidStack extends AEStack implements IAEFlu return ta == tb; } - return Platform.NBTEqualityTest( ta, tb ); + return Platform.itemComparisons().isNbtTagEqual( ta, tb ); } } return false; diff --git a/src/main/java/appeng/util/item/AEItemDef.java b/src/main/java/appeng/util/item/AEItemDef.java index 672bad95..18d3d728 100644 --- a/src/main/java/appeng/util/item/AEItemDef.java +++ b/src/main/java/appeng/util/item/AEItemDef.java @@ -100,7 +100,7 @@ public class AEItemDef if( this.getTagCompound() != null && otherStack.hasTagCompound() ) { - return Platform.NBTEqualityTest( this.getTagCompound(), otherStack.getTagCompound() ); + return Platform.itemComparisons().isNbtTagEqual( this.getTagCompound(), otherStack.getTagCompound() ); } return true; diff --git a/src/main/java/appeng/util/item/AEItemStack.java b/src/main/java/appeng/util/item/AEItemStack.java index 04184180..d81e0c85 100644 --- a/src/main/java/appeng/util/item/AEItemStack.java +++ b/src/main/java/appeng/util/item/AEItemStack.java @@ -522,7 +522,7 @@ public final class AEItemStack extends AEStack implements IAEItemS return ta == tb; } - return Platform.NBTEqualityTest( ta, tb ); + return Platform.itemComparisons().isNbtTagEqual( ta, tb ); } } return false; diff --git a/src/main/java/appeng/util/item/AESharedNBT.java b/src/main/java/appeng/util/item/AESharedNBT.java index f3416fc0..8ee28987 100644 --- a/src/main/java/appeng/util/item/AESharedNBT.java +++ b/src/main/java/appeng/util/item/AESharedNBT.java @@ -136,7 +136,7 @@ public class AESharedNBT extends NBTTagCompound implements IAETagCompound x.setTag( name, c.getTag( name ).copy() ); } - x.hash = Platform.NBTOrderlessHash( c ); + x.hash = Platform.itemComparisons().createUnorderedNbtHash( c ); final ItemStack isc = new ItemStack( itemID, 1, damageValue ); isc.setTagCompound( c ); diff --git a/src/main/java/appeng/util/item/SharedSearchObject.java b/src/main/java/appeng/util/item/SharedSearchObject.java index ea1ba732..5e8717b3 100644 --- a/src/main/java/appeng/util/item/SharedSearchObject.java +++ b/src/main/java/appeng/util/item/SharedSearchObject.java @@ -36,7 +36,7 @@ public class SharedSearchObject public SharedSearchObject( final Item itemID, final int damageValue, final NBTTagCompound tagCompound ) { this.def = ( damageValue << Platform.DEF_OFFSET ) | Item.REGISTRY.getIDForObject( itemID ); - this.hash = Platform.NBTOrderlessHash( tagCompound ); + this.hash = Platform.itemComparisons().createUnorderedNbtHash( tagCompound ); this.setCompound( tagCompound ); } @@ -60,7 +60,7 @@ public class SharedSearchObject final SharedSearchObject other = (SharedSearchObject) obj; if( this.def == other.def && this.hash == other.hash ) { - return Platform.NBTEqualityTest( this.getCompound(), other.getCompound() ); + return Platform.itemComparisons().isNbtTagEqual( this.getCompound(), other.getCompound() ); } return false; }