diff --git a/src/api/java/appeng/api/storage/data/IAEItemStack.java b/src/api/java/appeng/api/storage/data/IAEItemStack.java index 3da0fdb5b..bc5d83f87 100644 --- a/src/api/java/appeng/api/storage/data/IAEItemStack.java +++ b/src/api/java/appeng/api/storage/data/IAEItemStack.java @@ -46,7 +46,7 @@ public interface IAEItemStack extends IAEStack * * @return new ItemStack */ - ItemStack getItemStack(); + ItemStack createItemStack(); /** * is there NBT Data for this item? @@ -105,4 +105,11 @@ public interface IAEItemStack extends IAEStack * @return true if it is the same type (same item, damage, nbt) */ boolean isSameType( ItemStack stored ); + + /** + * DO NOT MODIFY THIS STACK! NEVER. If you think about it .. DON'T + * + * @return definition stack + */ + ItemStack getDefinition(); } \ No newline at end of file diff --git a/src/api/java/appeng/api/storage/data/IAEStack.java b/src/api/java/appeng/api/storage/data/IAEStack.java index adc877cf3..8166e21ea 100644 --- a/src/api/java/appeng/api/storage/data/IAEStack.java +++ b/src/api/java/appeng/api/storage/data/IAEStack.java @@ -28,13 +28,14 @@ import java.io.IOException; import io.netty.buffer.ByteBuf; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import appeng.api.config.FuzzyMode; import appeng.api.storage.StorageChannel; -public interface IAEStack +public interface IAEStack> { /** @@ -182,13 +183,6 @@ public interface IAEStack */ StackType empty(); - /** - * obtain the NBT Data for the item. - * - * @return nbt data - */ - IAETagCompound getTagCompound(); - /** * @return true if the stack is a {@link IAEItemStack} */ @@ -203,4 +197,11 @@ public interface IAEStack * @return ITEM or FLUID */ StorageChannel getChannel(); + + /** + * Returns itemstack for display and similar purposes. Always has a count of 1. + * + * @return itemstack + */ + ItemStack asItemStackRepresentation(); } diff --git a/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java b/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java index 0582b9a79..15bdf91d6 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java @@ -352,12 +352,11 @@ public class GuiCraftConfirm extends AEBaseGui final int posX = x * ( 1 + sectionLength ) + xo + sectionLength - 19; final int posY = y * offY + yo; - final ItemStack is = refStack.getItemStack(); - is.setCount( 1 ); + final ItemStack is = refStack.asItemStackRepresentation(); if( this.tooltip == z - viewStart ) { - dspToolTip = Platform.getItemDisplayName( is ); + dspToolTip = Platform.getItemDisplayName( refStack ); if( lineList.size() > 0 ) { diff --git a/src/main/java/appeng/client/gui/implementations/GuiCraftingCPU.java b/src/main/java/appeng/client/gui/implementations/GuiCraftingCPU.java index 135e2f82f..40a0b5ec3 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCraftingCPU.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCraftingCPU.java @@ -309,12 +309,11 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource final int posX = x * ( 1 + SECTION_LENGTH ) + ITEMSTACK_LEFT_OFFSET + SECTION_LENGTH - 19; final int posY = y * offY + ITEMSTACK_TOP_OFFSET; - final ItemStack is = refStack.getItemStack(); - is.setCount( 1 ); + final ItemStack is = refStack.asItemStackRepresentation(); if( this.tooltip == z - viewStart ) { - dspToolTip = Platform.getItemDisplayName( is ); + dspToolTip = Platform.getItemDisplayName( refStack ); if( lineList.size() > 0 ) { diff --git a/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java b/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java index d5450cd42..8f0a09ea2 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java +++ b/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java @@ -180,7 +180,7 @@ public class GuiNetworkStatus extends AEBaseGui implements ISortSource if( this.tooltip == z - viewStart ) { - toolTip = Platform.getItemDisplayName( this.repo.getItem( z ) ); + toolTip = Platform.getItemDisplayName( refStack ); toolTip += ( '\n' + GuiText.Installed.getLocal() + ": " + ( refStack.getStackSize() ) ); if( refStack.getCountRequestable() > 0 ) @@ -192,7 +192,7 @@ public class GuiNetworkStatus extends AEBaseGui implements ISortSource toolPosY = y * 18 + yo; } - this.drawItem( posX, posY, this.repo.getItem( z ) ); + this.drawItem( posX, posY, refStack.asItemStackRepresentation() ); x++; diff --git a/src/main/java/appeng/client/me/InternalSlotME.java b/src/main/java/appeng/client/me/InternalSlotME.java index 90b72c2f9..efbfb8448 100644 --- a/src/main/java/appeng/client/me/InternalSlotME.java +++ b/src/main/java/appeng/client/me/InternalSlotME.java @@ -42,7 +42,7 @@ public class InternalSlotME ItemStack getStack() { - return this.repo.getItem( this.offset ); + return this.getAEStack() == null ? ItemStack.EMPTY : this.getAEStack().asItemStackRepresentation(); } IAEItemStack getAEStack() diff --git a/src/main/java/appeng/client/me/ItemRepo.java b/src/main/java/appeng/client/me/ItemRepo.java index 55c9d3cba..17beb847e 100644 --- a/src/main/java/appeng/client/me/ItemRepo.java +++ b/src/main/java/appeng/client/me/ItemRepo.java @@ -50,7 +50,6 @@ public class ItemRepo private final IItemList list = AEApi.instance().storage().createItemList(); private final ArrayList view = new ArrayList<>(); - private final ArrayList dsp = new ArrayList<>(); private final IScrollSource src; private final ISortSource sortSrc; @@ -78,17 +77,6 @@ public class ItemRepo return this.view.get( idx ); } - public ItemStack getItem( int idx ) - { - idx += this.src.getCurrentScroll() * this.rowSize; - - if( idx >= this.dsp.size() ) - { - return ItemStack.EMPTY; - } - return this.dsp.get( idx ); - } - void setSearch( final String search ) { this.searchString = search == null ? "" : search; @@ -118,10 +106,8 @@ public class ItemRepo public void updateView() { this.view.clear(); - this.dsp.clear(); this.view.ensureCapacity( this.list.size() ); - this.dsp.ensureCapacity( this.list.size() ); final Enum viewMode = this.sortSrc.getSortDisplay(); final Enum searchMode = AEConfig.instance().getConfigManager().getSetting( Settings.SEARCH_MODE ); @@ -235,13 +221,6 @@ public class ItemRepo { Collections.sort( this.view, ItemSorters.CONFIG_BASED_SORT_BY_NAME ); } - - for( final IAEItemStack is : this.view ) - { - final ItemStack displayStack = is.getItemStack(); - displayStack.setCount( 1 ); - this.dsp.add( displayStack ); - } } private void updateJEI( String filter ) diff --git a/src/main/java/appeng/client/render/TesrRenderHelper.java b/src/main/java/appeng/client/render/TesrRenderHelper.java index 66035e3fa..9d20cafe0 100644 --- a/src/main/java/appeng/client/render/TesrRenderHelper.java +++ b/src/main/java/appeng/client/render/TesrRenderHelper.java @@ -126,8 +126,7 @@ public class TesrRenderHelper */ public static void renderItem2dWithAmount( IAEItemStack itemStack, float itemScale, float spacing ) { - final ItemStack renderStack = itemStack.getItemStack(); - renderStack.setCount( 1 ); + final ItemStack renderStack = itemStack.asItemStackRepresentation(); TesrRenderHelper.renderItem2d( renderStack, itemScale ); diff --git a/src/main/java/appeng/client/render/effects/AssemblerFX.java b/src/main/java/appeng/client/render/effects/AssemblerFX.java index 47e2d01b6..9936324c2 100644 --- a/src/main/java/appeng/client/render/effects/AssemblerFX.java +++ b/src/main/java/appeng/client/render/effects/AssemblerFX.java @@ -46,8 +46,7 @@ public class AssemblerFX extends Particle implements ICanDie this.motionY = 0; this.motionZ = 0; this.speed = speed; - final ItemStack displayItem = is.getItemStack(); - displayItem.setCount( 1 ); + final ItemStack displayItem = is.asItemStackRepresentation(); this.fi = new EntityFloatingItem( this, w, x, y, z, displayItem ); w.spawnEntity( this.fi ); this.particleMaxAge = (int) Math.ceil( Math.max( 1, 100.0f / speed ) ) + 2; diff --git a/src/main/java/appeng/container/AEBaseContainer.java b/src/main/java/appeng/container/AEBaseContainer.java index 59992e635..f0cf1e6df 100644 --- a/src/main/java/appeng/container/AEBaseContainer.java +++ b/src/main/java/appeng/container/AEBaseContainer.java @@ -862,7 +862,7 @@ public abstract class AEBaseContainer extends Container if( slotItem != null ) { IAEItemStack ais = slotItem.copy(); - ItemStack myItem = ais.getItemStack(); + ItemStack myItem = ais.createItemStack(); ais.setStackSize( myItem.getMaxStackSize() ); @@ -878,7 +878,7 @@ public abstract class AEBaseContainer extends Container ais = Platform.poweredExtraction( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() ); if( ais != null ) { - adp.addItems( ais.getItemStack() ); + adp.addItems( ais.createItemStack() ); } } break; @@ -902,7 +902,7 @@ public abstract class AEBaseContainer extends Container { final InventoryAdaptor ia = new AdaptorItemHandler( new WrapperCursorItemHandler( player.inventory ) ); - final ItemStack fail = ia.removeItems( 1, extracted.getItemStack(), null ); + final ItemStack fail = ia.removeItems( 1, extracted.getDefinition(), null ); if( fail.isEmpty() ) { this.getCellInventory().extractItems( extracted, Actionable.MODULATE, this.getActionSource() ); @@ -931,7 +931,7 @@ public abstract class AEBaseContainer extends Container { liftQty = 0; } - if( !Platform.itemComparisons().isSameItem( slotItem.getItemStack(), item ) ) + if( !Platform.itemComparisons().isSameItem( slotItem.getDefinition(), item ) ) { liftQty = 0; } @@ -946,7 +946,7 @@ public abstract class AEBaseContainer extends Container { final InventoryAdaptor ia = new AdaptorItemHandler( new WrapperCursorItemHandler( player.inventory ) ); - final ItemStack fail = ia.addItems( ais.getItemStack() ); + final ItemStack fail = ia.addItems( ais.createItemStack() ); if( !fail.isEmpty() ) { this.getCellInventory().injectItems( ais, Actionable.MODULATE, this.getActionSource() ); @@ -968,11 +968,11 @@ public abstract class AEBaseContainer extends Container if( slotItem != null ) { IAEItemStack ais = slotItem.copy(); - ais.setStackSize( ais.getItemStack().getMaxStackSize() ); + ais.setStackSize( ais.getDefinition().getMaxStackSize() ); ais = Platform.poweredExtraction( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() ); if( ais != null ) { - player.inventory.setItemStack( ais.getItemStack() ); + player.inventory.setItemStack( ais.createItemStack() ); } else { @@ -987,7 +987,7 @@ public abstract class AEBaseContainer extends Container ais = Platform.poweredInsert( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() ); if( ais != null ) { - player.inventory.setItemStack( ais.getItemStack() ); + player.inventory.setItemStack( ais.createItemStack() ); } else { @@ -1008,7 +1008,7 @@ public abstract class AEBaseContainer extends Container if( slotItem != null ) { IAEItemStack ais = slotItem.copy(); - final long maxSize = ais.getItemStack().getMaxStackSize(); + final long maxSize = ais.getDefinition().getMaxStackSize(); ais.setStackSize( maxSize ); ais = this.getCellInventory().extractItems( ais, Actionable.SIMULATE, this.getActionSource() ); @@ -1021,7 +1021,7 @@ public abstract class AEBaseContainer extends Container if( ais != null ) { - player.inventory.setItemStack( ais.getItemStack() ); + player.inventory.setItemStack( ais.createItemStack() ); } else { @@ -1051,7 +1051,7 @@ public abstract class AEBaseContainer extends Container case CREATIVE_DUPLICATE: if( player.capabilities.isCreativeMode && slotItem != null ) { - final ItemStack is = slotItem.getItemStack(); + final ItemStack is = slotItem.createItemStack(); is.setCount( is.getMaxStackSize() ); player.inventory.setItemStack( is ); this.updateHeld( player ); @@ -1070,7 +1070,7 @@ public abstract class AEBaseContainer extends Container for( int slotNum = 0; slotNum < playerInv; slotNum++ ) { IAEItemStack ais = slotItem.copy(); - ItemStack myItem = ais.getItemStack(); + ItemStack myItem = ais.createItemStack(); ais.setStackSize( myItem.getMaxStackSize() ); @@ -1086,7 +1086,7 @@ public abstract class AEBaseContainer extends Container ais = Platform.poweredExtraction( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() ); if( ais != null ) { - adp.addItems( ais.getItemStack() ); + adp.addItems( ais.createItemStack() ); } else { @@ -1129,7 +1129,7 @@ public abstract class AEBaseContainer extends Container { return ItemStack.EMPTY; } - return ais.getItemStack(); + return ais.createItemStack(); } private void updateSlot( final Slot clickSlot ) diff --git a/src/main/java/appeng/container/implementations/ContainerCellWorkbench.java b/src/main/java/appeng/container/implementations/ContainerCellWorkbench.java index 5b078d437..7e26ab6de 100644 --- a/src/main/java/appeng/container/implementations/ContainerCellWorkbench.java +++ b/src/main/java/appeng/container/implementations/ContainerCellWorkbench.java @@ -240,8 +240,8 @@ public class ContainerCellWorkbench extends ContainerUpgradeable { if( i.hasNext() ) { - final ItemStack g = i.next().getItemStack(); - g.setCount( 1 ); + // TODO: check if ok + final ItemStack g = i.next().asItemStackRepresentation(); ItemHandlerUtil.setStackInSlot( inv, x, g ); } else diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index a473208b9..2f617f9e0 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -26,7 +26,6 @@ import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.container.interfaces.IInventorySlotAware; -import appeng.util.Platform; public class ContainerMEPortableCell extends ContainerMEMonitorable @@ -67,7 +66,7 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable { if( !currentItem.isEmpty() ) { - if( Platform.itemComparisons().isEqualItem( this.civ.getItemStack(), currentItem ) ) + if( ItemStack.areItemsEqual( 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 0a024b052..7004d7809 100644 --- a/src/main/java/appeng/container/implementations/ContainerNetworkTool.java +++ b/src/main/java/appeng/container/implementations/ContainerNetworkTool.java @@ -73,7 +73,7 @@ public class ContainerNetworkTool extends AEBaseContainer { if( !currentItem.isEmpty() ) { - if( Platform.itemComparisons().isEqualItem( this.toolInv.getItemStack(), currentItem ) ) + if( ItemStack.areItemsEqual( 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 f6ff82a18..debd866bd 100644 --- a/src/main/java/appeng/container/implementations/ContainerPatternTerm.java +++ b/src/main/java/appeng/container/implementations/ContainerPatternTerm.java @@ -364,7 +364,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA inv = playerInv; } - if( !inv.simulateAdd( out.getItemStack() ).isEmpty() ) + if( !inv.simulateAdd( out.createItemStack() ).isEmpty() ) { return; } @@ -374,7 +374,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA if( extracted != null ) { - inv.addItems( extracted.getItemStack() ); + inv.addItems( extracted.createItemStack() ); if( p instanceof EntityPlayerMP ) { this.updateHeld( (EntityPlayerMP) p ); @@ -388,7 +388,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA for( int x = 0; x < 9; x++ ) { - ic.setInventorySlotContents( x, packetPatternSlot.pattern[x] == null ? ItemStack.EMPTY : packetPatternSlot.pattern[x].getItemStack() ); + ic.setInventorySlotContents( x, packetPatternSlot.pattern[x] == null ? ItemStack.EMPTY : packetPatternSlot.pattern[x].createItemStack() ); } final IRecipe r = CraftingManager.findMatchingRecipe( ic, p.world ); diff --git a/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java b/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java index 01b320e86..078775612 100644 --- a/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java +++ b/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java @@ -73,7 +73,7 @@ public class ContainerQuartzKnife extends AEBaseContainer { if( !currentItem.isEmpty() ) { - if( Platform.itemComparisons().isEqualItem( this.toolInv.getItemStack(), currentItem ) ) + if( ItemStack.areItemsEqual( this.toolInv.getItemStack(), currentItem ) ) { this.getPlayerInv().setInventorySlotContents( this.getPlayerInv().currentItem, this.toolInv.getItemStack() ); } diff --git a/src/main/java/appeng/container/implementations/ContainerStorageBus.java b/src/main/java/appeng/container/implementations/ContainerStorageBus.java index 17984377c..5fba253c5 100644 --- a/src/main/java/appeng/container/implementations/ContainerStorageBus.java +++ b/src/main/java/appeng/container/implementations/ContainerStorageBus.java @@ -165,8 +165,8 @@ public class ContainerStorageBus extends ContainerUpgradeable { if( i.hasNext() && this.isSlotEnabled( ( x / 9 ) - 2 ) ) { - final ItemStack g = i.next().getItemStack(); - g.setCount( 1 ); + // TODO: check if ok + final ItemStack g = i.next().asItemStackRepresentation(); ItemHandlerUtil.setStackInSlot( inv, x, g ); } else diff --git a/src/main/java/appeng/container/implementations/ContainerUpgradeable.java b/src/main/java/appeng/container/implementations/ContainerUpgradeable.java index c876d17b0..3c3dd87ee 100644 --- a/src/main/java/appeng/container/implementations/ContainerUpgradeable.java +++ b/src/main/java/appeng/container/implementations/ContainerUpgradeable.java @@ -245,7 +245,7 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl { if( !currentItem.isEmpty() ) { - if( Platform.itemComparisons().isEqualItem( this.tbInventory.getItemStack(), currentItem ) ) + if( ItemStack.areItemsEqual( 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 5127350fb..9b68d6a29 100644 --- a/src/main/java/appeng/container/slot/SlotCraftingTerm.java +++ b/src/main/java/appeng/container/slot/SlotCraftingTerm.java @@ -134,7 +134,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot return; } - final ItemStack rs = Platform.cloneItemStack( this.getStack() ); + final ItemStack rs = this.getStack().copy(); if( rs.isEmpty() ) { return; @@ -202,7 +202,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot // update crafting matrix... ItemStack is = this.getStack(); - if( !is.isEmpty() && Platform.itemComparisons().isEqualItem( request, is ) ) + if( !is.isEmpty() && ItemStack.areItemsEqual( request, is ) ) { final ItemStack[] set = new ItemStack[this.getPattern().getSlots()]; // Safeguard for empty slots in the inventory for now @@ -309,7 +309,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot final IAEItemStack fail = inv.injectItems( AEItemStack.create( set[x] ), Actionable.MODULATE, this.mySrc ); if( fail != null ) { - drops.add( fail.getItemStack() ); + drops.add( fail.createItemStack() ); } } } diff --git a/src/main/java/appeng/core/features/registries/MatterCannonAmmoRegistry.java b/src/main/java/appeng/core/features/registries/MatterCannonAmmoRegistry.java index feda186d2..24e0ce52b 100644 --- a/src/main/java/appeng/core/features/registries/MatterCannonAmmoRegistry.java +++ b/src/main/java/appeng/core/features/registries/MatterCannonAmmoRegistry.java @@ -27,7 +27,6 @@ import net.minecraft.item.ItemStack; import appeng.api.features.IMatterCannonAmmoRegistry; import appeng.recipes.ores.IOreListener; import appeng.recipes.ores.OreDictionaryHandler; -import appeng.util.Platform; public class MatterCannonAmmoRegistry implements IOreListener, IMatterCannonAmmoRegistry @@ -52,7 +51,7 @@ public class MatterCannonAmmoRegistry implements IOreListener, IMatterCannonAmmo { for( final ItemStack o : this.DamageModifiers.keySet() ) { - if( Platform.itemComparisons().isEqualItem( o, is ) ) + if( ItemStack.areItemsEqual( 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 09f56e8a5..6c3a9a15b 100644 --- a/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java +++ b/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java @@ -41,7 +41,6 @@ import appeng.api.definitions.IParts; import appeng.api.features.IP2PTunnelRegistry; import appeng.api.util.AEColor; import appeng.capabilities.Capabilities; -import appeng.util.Platform; public final class P2PTunnelRegistry implements IP2PTunnelRegistry @@ -216,7 +215,7 @@ public final class P2PTunnelRegistry implements IP2PTunnelRegistry return this.tunnels.get( is ); } - if( Platform.itemComparisons().isEqualItem( is, trigger ) ) + if( ItemStack.areItemsEqual( is, trigger ) ) { return this.tunnels.get( is ); } diff --git a/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java b/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java index 51e52ec42..375156be7 100644 --- a/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java +++ b/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java @@ -141,10 +141,7 @@ public class PacketInventoryAction extends AppEngPacket if( baseContainer.getTargetStack() != null ) { - // Force to stack size 1 to fix a client-side display problem... - ItemStack displayIs = baseContainer.getTargetStack().getItemStack(); - displayIs.setCount( 1 ); - cca.getCraftingItem().putStack( displayIs ); + cca.getCraftingItem().putStack( baseContainer.getTargetStack().asItemStackRepresentation() ); // This is the *actual* item that matters, not the display item above cca.setItemToCraft( baseContainer.getTargetStack() ); } @@ -171,7 +168,7 @@ public class PacketInventoryAction extends AppEngPacket } else { - AppEng.proxy.getPlayers().get( 0 ).inventory.setItemStack( this.slotItem.getItemStack() ); + AppEng.proxy.getPlayers().get( 0 ).inventory.setItemStack( this.slotItem.createItemStack() ); } } } diff --git a/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java b/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java index 57b34f6ad..a2d08b7c0 100644 --- a/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java +++ b/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java @@ -155,7 +155,7 @@ public class PacketJEIRecipe extends AppEngPacket final IAEItemStack out = cct.useRealItems() ? Platform.poweredInsert( energy, storage, in, cct.getActionSource() ) : null; if( out != null ) { - currentItem = out.getItemStack(); + currentItem = out.createItemStack(); } else { @@ -188,7 +188,7 @@ public class PacketJEIRecipe extends AppEngPacket if( out != null ) { - currentItem = out.getItemStack(); + currentItem = out.createItemStack(); } } diff --git a/src/main/java/appeng/crafting/CraftingTreeNode.java b/src/main/java/appeng/crafting/CraftingTreeNode.java index 8c05e0afb..9b021ceec 100644 --- a/src/main/java/appeng/crafting/CraftingTreeNode.java +++ b/src/main/java/appeng/crafting/CraftingTreeNode.java @@ -147,7 +147,7 @@ public class CraftingTreeNode for( IAEItemStack fuzz : itemList ) { - if( this.parent.details.isValidItemForSlot( this.getSlot(), fuzz.getItemStack(), this.world ) ) + if( this.parent.details.isValidItemForSlot( this.getSlot(), fuzz.createItemStack(), this.world ) ) { fuzz = fuzz.copy(); fuzz.setStackSize( l ); diff --git a/src/main/java/appeng/crafting/CraftingTreeProcess.java b/src/main/java/appeng/crafting/CraftingTreeProcess.java index 41c084a97..fdab4d0e7 100644 --- a/src/main/java/appeng/crafting/CraftingTreeProcess.java +++ b/src/main/java/appeng/crafting/CraftingTreeProcess.java @@ -73,7 +73,7 @@ public class CraftingTreeProcess final IAEItemStack[] is = details.getInputs(); for( int x = 0; x < ic.getSizeInventory(); x++ ) { - ic.setInventorySlotContents( x, is[x] == null ? ItemStack.EMPTY : is[x].getItemStack() ); + ic.setInventorySlotContents( x, is[x] == null ? ItemStack.EMPTY : is[x].createItemStack() ); } FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) world ), details.getOutput( ic, world ), ic ); @@ -89,7 +89,7 @@ public class CraftingTreeProcess for( final IAEItemStack part : details.getCondensedInputs() ) { - final ItemStack g = part.getItemStack(); + final ItemStack g = part.createItemStack(); boolean isAnInput = false; for( final IAEItemStack a : details.getCondensedOutputs() ) @@ -146,7 +146,7 @@ public class CraftingTreeProcess { for( final IAEItemStack part : details.getCondensedInputs() ) { - final ItemStack g = part.getItemStack(); + final ItemStack g = part.createItemStack(); boolean isAnInput = false; for( final IAEItemStack a : details.getCondensedOutputs() ) @@ -197,7 +197,7 @@ public class CraftingTreeProcess final IAEItemStack item = entry.getKey().getStack( entry.getValue() ); final IAEItemStack stack = entry.getKey().request( inv, item.getStackSize(), src ); - ic.setInventorySlotContents( entry.getKey().getSlot(), stack.getItemStack() ); + ic.setInventorySlotContents( entry.getKey().getSlot(), stack.createItemStack() ); } FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) this.world ), this.details.getOutput( ic, this.world ), ic ); @@ -225,7 +225,7 @@ public class CraftingTreeProcess if( this.containerItems ) { - final ItemStack is = Platform.getContainerItem( stack.getItemStack() ); + final ItemStack is = Platform.getContainerItem( stack.createItemStack() ); final IAEItemStack o = AEApi.instance().storage().createItemStack( is ); if( o != null ) { diff --git a/src/main/java/appeng/entity/EntityChargedQuartz.java b/src/main/java/appeng/entity/EntityChargedQuartz.java index 90af5ea4a..50f69befe 100644 --- a/src/main/java/appeng/entity/EntityChargedQuartz.java +++ b/src/main/java/appeng/entity/EntityChargedQuartz.java @@ -121,12 +121,12 @@ public final class EntityChargedQuartz extends AEBaseEntityItem final ItemStack other = ( (EntityItem) e ).getItem(); if( !other.isEmpty() ) { - if( Platform.itemComparisons().isEqualItem( other, new ItemStack( Items.REDSTONE ) ) ) + if( ItemStack.areItemsEqual( other, new ItemStack( Items.REDSTONE ) ) ) { redstone = (EntityItem) e; } - if( Platform.itemComparisons().isEqualItem( other, new ItemStack( Items.QUARTZ ) ) ) + if( ItemStack.areItemsEqual( other, new ItemStack( Items.QUARTZ ) ) ) { netherQuartz = (EntityItem) e; } diff --git a/src/main/java/appeng/helpers/DualityInterface.java b/src/main/java/appeng/helpers/DualityInterface.java index b86dce57e..dabc26aa1 100644 --- a/src/main/java/appeng/helpers/DualityInterface.java +++ b/src/main/java/appeng/helpers/DualityInterface.java @@ -673,7 +673,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn else if( itemStack.getStackSize() > 0 ) { // make sure strange things didn't happen... - if( !adaptor.simulateAdd( itemStack.getItemStack() ).isEmpty() ) + if( !adaptor.simulateAdd( itemStack.createItemStack() ).isEmpty() ) { changed = true; throw new GridAccessException(); @@ -683,7 +683,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn if( acquired != null ) { changed = true; - final ItemStack issue = adaptor.addItems( acquired.getItemStack() ); + final ItemStack issue = adaptor.addItems( acquired.createItemStack() ); if( !issue.isEmpty() ) { throw new IllegalStateException( "bad attempt at managing inventory. ( addItems )" ); @@ -702,7 +702,8 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn long diff = toStore.getStackSize(); // make sure strange things didn't happen... - final ItemStack canExtract = adaptor.simulateRemove( (int) diff, toStore.getItemStack(), null ); + // TODO: check if OK + final ItemStack canExtract = adaptor.simulateRemove( (int) diff, toStore.getDefinition(), null ); if( canExtract.isEmpty() || canExtract.getCount() != diff ) { changed = true; @@ -1118,11 +1119,11 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn if( mode == Actionable.SIMULATE ) { - return AEItemStack.create( adaptor.simulateAdd( acquired.getItemStack() ) ); + return AEItemStack.create( adaptor.simulateAdd( acquired.createItemStack() ) ); } else { - final IAEItemStack is = AEItemStack.create( adaptor.addItems( acquired.getItemStack() ) ); + final IAEItemStack is = AEItemStack.create( adaptor.addItems( acquired.createItemStack() ) ); this.updatePlan( slot ); return is; } diff --git a/src/main/java/appeng/helpers/MultiCraftingTracker.java b/src/main/java/appeng/helpers/MultiCraftingTracker.java index 7d1223036..464ef0716 100644 --- a/src/main/java/appeng/helpers/MultiCraftingTracker.java +++ b/src/main/java/appeng/helpers/MultiCraftingTracker.java @@ -83,7 +83,7 @@ public class MultiCraftingTracker public boolean handleCrafting( final int x, final long itemToCraft, final IAEItemStack ais, final InventoryAdaptor d, final World w, final IGrid g, final ICraftingGrid cg, final IActionSource mySrc ) { - if( ais != null && d.simulateAdd( ais.getItemStack() ).isEmpty() ) + if( ais != null && d.simulateAdd( ais.createItemStack() ).isEmpty() ) { final Future craftingJob = this.getJob( x ); diff --git a/src/main/java/appeng/helpers/PatternHelper.java b/src/main/java/appeng/helpers/PatternHelper.java index ed54352f7..63a3a85ed 100644 --- a/src/main/java/appeng/helpers/PatternHelper.java +++ b/src/main/java/appeng/helpers/PatternHelper.java @@ -334,7 +334,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable 0 ) { - return this.outputs[0].getItemStack(); + return this.outputs[0].createItemStack(); } return ItemStack.EMPTY; diff --git a/src/main/java/appeng/integration/modules/jei/GrinderRecipeCategory.java b/src/main/java/appeng/integration/modules/jei/GrinderRecipeCategory.java index 6e525656c..b305a1a02 100644 --- a/src/main/java/appeng/integration/modules/jei/GrinderRecipeCategory.java +++ b/src/main/java/appeng/integration/modules/jei/GrinderRecipeCategory.java @@ -88,12 +88,14 @@ class GrinderRecipeCategory implements IRecipeCategory, IR itemStacks.set( ingredients ); } - @Override public void addRecipeCategories( IRecipeCategory... recipeCategories ) + @Override + public void addRecipeCategories( IRecipeCategory... recipeCategories ) { } - @Override public IJeiHelpers getJeiHelpers() + @Override + public IJeiHelpers getJeiHelpers() { return null; } diff --git a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java index 9f235ba77..c2a5e7cd0 100644 --- a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java +++ b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java @@ -175,7 +175,8 @@ public class JEIPlugin implements IModPlugin if( !matterBall.isEmpty() || !singularity.isEmpty() ) { registry.addRecipeCatalyst( condenser, CondenserCategory.UID ); - registry.handleRecipes( CondenserOutput.class, new CondenserOutputHandler( registry.getJeiHelpers().getGuiHelper(), matterBall, singularity) , CondenserCategory.UID ); + registry.handleRecipes( CondenserOutput.class, new CondenserOutputHandler( registry.getJeiHelpers().getGuiHelper(), matterBall, singularity ), + CondenserCategory.UID ); } } diff --git a/src/main/java/appeng/integration/modules/theoneprobe/part/StorageMonitorInfoProvider.java b/src/main/java/appeng/integration/modules/theoneprobe/part/StorageMonitorInfoProvider.java index ccf07c545..976999ff6 100644 --- a/src/main/java/appeng/integration/modules/theoneprobe/part/StorageMonitorInfoProvider.java +++ b/src/main/java/appeng/integration/modules/theoneprobe/part/StorageMonitorInfoProvider.java @@ -48,10 +48,11 @@ public class StorageMonitorInfoProvider implements IPartProbInfoProvider final IAEStack displayed = monitor.getDisplayed(); final boolean isLocked = monitor.isLocked(); + // TODO: generalize if( displayed instanceof IAEItemStack ) { final IAEItemStack ais = (IAEItemStack) displayed; - probeInfo.text( TheOneProbeText.SHOWING.getLocal() + ": " + ais.getItemStack().getDisplayName() ); + probeInfo.text( TheOneProbeText.SHOWING.getLocal() + ": " + ais.asItemStackRepresentation().getDisplayName() ); } else if( displayed instanceof IAEFluidStack ) { diff --git a/src/main/java/appeng/integration/modules/theoneprobe/tile/CraftingMonitorInfoProvider.java b/src/main/java/appeng/integration/modules/theoneprobe/tile/CraftingMonitorInfoProvider.java index 877102245..d1557c909 100644 --- a/src/main/java/appeng/integration/modules/theoneprobe/tile/CraftingMonitorInfoProvider.java +++ b/src/main/java/appeng/integration/modules/theoneprobe/tile/CraftingMonitorInfoProvider.java @@ -48,7 +48,8 @@ public class CraftingMonitorInfoProvider implements ITileProbInfoProvider if( displayStack != null ) { - final ItemStack itemStack = displayStack.getItemStack(); + // TODO: check if OK + final ItemStack itemStack = displayStack.asItemStackRepresentation(); final String itemName = itemStack.getDisplayName(); final String formattedCrafting = String.format( TheOneProbeText.CRAFTING.getLocal(), itemName ); diff --git a/src/main/java/appeng/integration/modules/waila/part/StorageMonitorWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/part/StorageMonitorWailaDataProvider.java index 829a9c557..30647b6de 100644 --- a/src/main/java/appeng/integration/modules/waila/part/StorageMonitorWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/part/StorageMonitorWailaDataProvider.java @@ -62,10 +62,11 @@ public final class StorageMonitorWailaDataProvider extends BasePartWailaDataProv final IAEStack displayed = monitor.getDisplayed(); final boolean isLocked = monitor.isLocked(); + // TODO: generalize if( displayed instanceof IAEItemStack ) { final IAEItemStack ais = (IAEItemStack) displayed; - currentToolTip.add( WailaText.Showing.getLocal() + ": " + ais.getItemStack().getDisplayName() ); + currentToolTip.add( WailaText.Showing.getLocal() + ": " + ais.asItemStackRepresentation().getDisplayName() ); } else if( displayed instanceof IAEFluidStack ) { diff --git a/src/main/java/appeng/integration/modules/waila/tile/CraftingMonitorWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/tile/CraftingMonitorWailaDataProvider.java index 7159cfd3d..0c04718e1 100644 --- a/src/main/java/appeng/integration/modules/waila/tile/CraftingMonitorWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/tile/CraftingMonitorWailaDataProvider.java @@ -63,7 +63,7 @@ public final class CraftingMonitorWailaDataProvider extends BaseWailaDataProvide if( displayStack != null ) { - final String currentCrafting = displayStack.getItemStack().getDisplayName(); + final String currentCrafting = displayStack.asItemStackRepresentation().getDisplayName(); currentToolTip.add( WailaText.Crafting.getLocal() + ": " + currentCrafting ); } diff --git a/src/main/java/appeng/items/misc/ItemEncodedPattern.java b/src/main/java/appeng/items/misc/ItemEncodedPattern.java index 2554fbc68..11f25ed20 100644 --- a/src/main/java/appeng/items/misc/ItemEncodedPattern.java +++ b/src/main/java/appeng/items/misc/ItemEncodedPattern.java @@ -229,7 +229,7 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt return ItemStack.EMPTY; } - SIMPLE_CACHE.put( item, out = details.getCondensedOutputs()[0].getItemStack() ); + SIMPLE_CACHE.put( item, out = details.getCondensedOutputs()[0].createItemStack() ); return out; } } diff --git a/src/main/java/appeng/items/tools/powered/ToolColorApplicator.java b/src/main/java/appeng/items/tools/powered/ToolColorApplicator.java index fa1fec7e8..500614942 100644 --- a/src/main/java/appeng/items/tools/powered/ToolColorApplicator.java +++ b/src/main/java/appeng/items/tools/powered/ToolColorApplicator.java @@ -126,7 +126,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe if( option != null ) { - paintBall = option.getItemStack(); + paintBall = option.createItemStack(); paintBall.setCount( 1 ); } else @@ -274,7 +274,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe final IAEItemStack firstItem = itemList.getFirstItem(); if( firstItem != null ) { - newColor = firstItem.getItemStack(); + newColor = firstItem.createItemStack(); } } else @@ -321,7 +321,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe list.addFirst( list.removeLast() ); } - return list.get( 0 ).getItemStack(); + return list.get( 0 ).createItemStack(); } } @@ -465,7 +465,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe { if( requestedAddition != null ) { - final int[] id = OreDictionary.getOreIDs( requestedAddition.getItemStack() ); + final int[] id = OreDictionary.getOreIDs( requestedAddition.getDefinition() ); for( final int x : id ) { diff --git a/src/main/java/appeng/items/tools/powered/ToolMatterCannon.java b/src/main/java/appeng/items/tools/powered/ToolMatterCannon.java index cd0bc5881..e31f89ba3 100644 --- a/src/main/java/appeng/items/tools/powered/ToolMatterCannon.java +++ b/src/main/java/appeng/items/tools/powered/ToolMatterCannon.java @@ -140,13 +140,12 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell } aeAmmo.setStackSize( 1 ); - final ItemStack ammo = ( (IAEItemStack) aeAmmo ).getItemStack(); + final ItemStack ammo = ( (IAEItemStack) aeAmmo ).createItemStack(); if( ammo == null ) { return new ActionResult<>( EnumActionResult.SUCCESS, p.getHeldItem( hand ) ); } - ammo.setCount( 1 ); aeAmmo = inv.extractItems( aeAmmo, Actionable.MODULATE, new PlayerSource( p, null ) ); if( aeAmmo == null ) { @@ -167,7 +166,7 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell final float penetration = AEApi.instance().registries().matterCannon().getPenetration( ammo ); // 196.96655f; if( penetration <= 0 ) { - final ItemStack type = ( (IAEItemStack) aeAmmo ).getItemStack(); + final ItemStack type = aeAmmo.asItemStackRepresentation(); if( type.getItem() instanceof ItemPaintBall ) { this.shootPaintBalls( type, w, p, Vec3d, Vec3d1, direction, d0, d1, d2 ); @@ -497,7 +496,7 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell @Override public boolean isBlackListed( final ItemStack cellItem, final IAEItemStack requestedAddition ) { - final float pen = AEApi.instance().registries().matterCannon().getPenetration( requestedAddition.getItemStack() ); + final float pen = AEApi.instance().registries().matterCannon().getPenetration( requestedAddition.createItemStack() ); if( pen > 0 ) { return false; diff --git a/src/main/java/appeng/me/cache/CraftingGridCache.java b/src/main/java/appeng/me/cache/CraftingGridCache.java index 1afe8c31f..ba5213bc4 100644 --- a/src/main/java/appeng/me/cache/CraftingGridCache.java +++ b/src/main/java/appeng/me/cache/CraftingGridCache.java @@ -484,7 +484,8 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper { if( ais.getItem() == whatToCraft.getItem() && ( !ais.getItem().getHasSubtypes() || ais.getItemDamage() == whatToCraft.getItemDamage() ) ) { - if( details.isValidItemForSlot( slotIndex, ais.getItemStack(), world ) ) + // TODO: check if OK + if( details.isValidItemForSlot( slotIndex, ais.createItemStack(), world ) ) { return this.craftableItems.get( ais ); } diff --git a/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java b/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java index 4b670faba..5f59d01b8 100644 --- a/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java +++ b/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java @@ -504,7 +504,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU fuzz = fuzz.copy(); fuzz.setStackSize( g.getStackSize() ); final IAEItemStack ais = this.inventory.extractItems( fuzz, Actionable.SIMULATE, this.machineSrc ); - final ItemStack is = ais == null ? ItemStack.EMPTY : ais.getItemStack(); + final ItemStack is = ais == null ? ItemStack.EMPTY : ais.createItemStack(); if( !is.isEmpty() && is.getCount() == g.getStackSize() ) { @@ -526,7 +526,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU else { final IAEItemStack ais = this.inventory.extractItems( g.copy(), Actionable.SIMULATE, this.machineSrc ); - final ItemStack is = ais == null ? ItemStack.EMPTY : ais.getItemStack(); + final ItemStack is = ais == null ? ItemStack.EMPTY : ais.createItemStack(); if( is.isEmpty() || is.getCount() < g.getStackSize() ) { @@ -690,10 +690,10 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU fuzz = fuzz.copy(); fuzz.setStackSize( input[x].getStackSize() ); - if( details.isValidItemForSlot( x, fuzz.getItemStack(), this.getWorld() ) ) + if( details.isValidItemForSlot( x, fuzz.createItemStack(), this.getWorld() ) ) { final IAEItemStack ais = this.inventory.extractItems( fuzz, Actionable.MODULATE, this.machineSrc ); - final ItemStack is = ais == null ? ItemStack.EMPTY : ais.getItemStack(); + final ItemStack is = ais == null ? ItemStack.EMPTY : ais.createItemStack(); if( !is.isEmpty() ) { @@ -708,7 +708,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU else { final IAEItemStack ais = this.inventory.extractItems( input[x].copy(), Actionable.MODULATE, this.machineSrc ); - final ItemStack is = ais == null ? ItemStack.EMPTY : ais.getItemStack(); + final ItemStack is = ais == null ? ItemStack.EMPTY : ais.createItemStack(); if( !is.isEmpty() ) { @@ -1217,7 +1217,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU if( pattern != null && pattern.getItem() instanceof ICraftingPatternItem ) { final ICraftingPatternItem cpi = (ICraftingPatternItem) pattern.getItem(); - final ICraftingPatternDetails details = cpi.getPatternForItem( pattern.getItemStack(), this.getWorld() ); + final ICraftingPatternDetails details = cpi.getPatternForItem( pattern.createItemStack(), this.getWorld() ); if( details != null ) { final TaskProgress tp = new TaskProgress(); diff --git a/src/main/java/appeng/me/storage/CellInventory.java b/src/main/java/appeng/me/storage/CellInventory.java index 50b46afe9..0682e834b 100644 --- a/src/main/java/appeng/me/storage/CellInventory.java +++ b/src/main/java/appeng/me/storage/CellInventory.java @@ -23,7 +23,6 @@ import java.util.HashSet; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.oredict.OreDictionary; @@ -218,7 +217,7 @@ public class CellInventory implements ICellInventory return input; } - final ItemStack sharedItemStack = input.getItemStack(); + final ItemStack sharedItemStack = input.createItemStack(); if( CellInventory.isStorageCell( sharedItemStack ) ) { @@ -269,11 +268,11 @@ public class CellInventory implements ICellInventory { if( input.getStackSize() > remainingItemCount ) { - final ItemStack toReturn = Platform.cloneItemStack( sharedItemStack ); + final ItemStack toReturn = sharedItemStack.copy(); toReturn.setCount( sharedItemStack.getCount() - remainingItemCount ); if( mode == Actionable.MODULATE ) { - final ItemStack toWrite = Platform.cloneItemStack( sharedItemStack ); + final ItemStack toWrite = sharedItemStack.copy(); toWrite.setCount( remainingItemCount ); this.cellItems.add( AEItemStack.create( toWrite ) ); @@ -368,22 +367,10 @@ public class CellInventory implements ICellInventory { itemCount += v.getStackSize(); - final NBTBase c = this.tagCompound.getTag( itemSlots[x] ); - if( c instanceof NBTTagCompound ) - { - v.writeToNBT( (NBTTagCompound) c ); - } - else - { - final NBTTagCompound g = new NBTTagCompound(); - v.writeToNBT( g ); - this.tagCompound.setTag( itemSlots[x], g ); - } + final NBTTagCompound g = new NBTTagCompound(); + v.writeToNBT( g ); + this.tagCompound.setTag( itemSlots[x], g ); - /* - * NBTBase tagSlotCount = tagCompound.getTag( itemSlotCount[x] ); if ( tagSlotCount instanceof - * NBTTagInt ) ((NBTTagInt) tagSlotCount).data = (int) v.getStackSize(); else - */ this.tagCompound.setInteger( itemSlotCount[x], (int) v.getStackSize() ); x++; diff --git a/src/main/java/appeng/me/storage/MEMonitorIInventory.java b/src/main/java/appeng/me/storage/MEMonitorIInventory.java index 0b572360b..32bfe9edb 100644 --- a/src/main/java/appeng/me/storage/MEMonitorIInventory.java +++ b/src/main/java/appeng/me/storage/MEMonitorIInventory.java @@ -79,11 +79,11 @@ public class MEMonitorIInventory implements IMEMonitor, ITickingMo if( type == Actionable.SIMULATE ) { - out = this.adaptor.simulateAdd( input.getItemStack() ); + out = this.adaptor.simulateAdd( input.createItemStack() ); } else { - out = this.adaptor.addItems( input.getItemStack() ); + out = this.adaptor.addItems( input.createItemStack() ); } if( type == Actionable.MODULATE ) @@ -109,11 +109,11 @@ public class MEMonitorIInventory implements IMEMonitor, ITickingMo if( type == Actionable.SIMULATE ) { - out = this.adaptor.simulateRemove( (int) request.getStackSize(), request.getItemStack(), null ); + out = this.adaptor.simulateRemove( (int) request.getStackSize(), request.getDefinition(), null ); } else { - out = this.adaptor.removeItems( (int) request.getStackSize(), request.getItemStack(), null ); + out = this.adaptor.removeItems( (int) request.getStackSize(), request.getDefinition(), null ); } if( out.isEmpty() ) diff --git a/src/main/java/appeng/me/storage/SecurityStationInventory.java b/src/main/java/appeng/me/storage/SecurityStationInventory.java index 91061136c..e6e58c094 100644 --- a/src/main/java/appeng/me/storage/SecurityStationInventory.java +++ b/src/main/java/appeng/me/storage/SecurityStationInventory.java @@ -51,7 +51,7 @@ public class SecurityStationInventory implements IMEInventoryHandler inv, IAEItemStack ais ) { - final ItemStack is = ais.getItemStack(); + final ItemStack is = ais.createItemStack(); is.setCount( (int) this.itemToSend ); final ItemStack o = d.simulateAdd( is ); @@ -320,7 +320,7 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest { this.itemToSend -= itemsToAdd.getStackSize(); - final ItemStack failed = d.addItems( itemsToAdd.getItemStack() ); + final ItemStack failed = d.addItems( itemsToAdd.createItemStack() ); if( !failed.isEmpty() ) { ais.setStackSize( failed.getCount() ); diff --git a/src/main/java/appeng/parts/automation/PartFormationPlane.java b/src/main/java/appeng/parts/automation/PartFormationPlane.java index 7af84d41a..e15ced0a8 100644 --- a/src/main/java/appeng/parts/automation/PartFormationPlane.java +++ b/src/main/java/appeng/parts/automation/PartFormationPlane.java @@ -436,7 +436,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine final YesNo placeBlock = (YesNo) this.getConfigManager().getSetting( Settings.PLACE_BLOCK ); - final ItemStack is = input.getItemStack(); + final ItemStack is = input.createItemStack(); final Item i = is.getItem(); long maxStorage = Math.min( input.getStackSize(), is.getMaxStackSize() ); diff --git a/src/main/java/appeng/parts/automation/PartImportBus.java b/src/main/java/appeng/parts/automation/PartImportBus.java index 92c441123..a05711900 100644 --- a/src/main/java/appeng/parts/automation/PartImportBus.java +++ b/src/main/java/appeng/parts/automation/PartImportBus.java @@ -218,12 +218,12 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 ) { - newItems = myAdaptor.removeSimilarItems( toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getItemStack(), fzMode, + newItems = myAdaptor.removeSimilarItems( toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), fzMode, this.configDestination( inv ) ); } else { - newItems = myAdaptor.removeItems( toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getItemStack(), this.configDestination( inv ) ); + newItems = myAdaptor.removeItems( toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), this.configDestination( inv ) ); } if( !newItems.isEmpty() ) @@ -245,7 +245,7 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin if( failed != null ) { - myAdaptor.addItems( failed.getItemStack() ); + myAdaptor.addItems( failed.createItemStack() ); return true; } else @@ -272,7 +272,7 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin } else { - itemStackToImport = whatToImport.getItemStack(); + itemStackToImport = whatToImport.getDefinition(); } final IAEItemStack itemAmountNotStorable; diff --git a/src/main/java/appeng/parts/automation/StackUpgradeInventory.java b/src/main/java/appeng/parts/automation/StackUpgradeInventory.java index 8ea57e6d9..c99afda08 100644 --- a/src/main/java/appeng/parts/automation/StackUpgradeInventory.java +++ b/src/main/java/appeng/parts/automation/StackUpgradeInventory.java @@ -22,7 +22,6 @@ package appeng.parts.automation; import net.minecraft.item.ItemStack; import appeng.api.config.Upgrades; -import appeng.util.Platform; import appeng.util.inv.IAEAppEngInventory; @@ -43,7 +42,7 @@ public class StackUpgradeInventory extends UpgradeInventory for( final ItemStack is : upgrades.getSupported().keySet() ) { - if( Platform.itemComparisons().isEqualItem( this.stack, is ) ) + if( ItemStack.areItemsEqual( 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 8f0c19152..4ea9d5737 100644 --- a/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java +++ b/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java @@ -68,7 +68,7 @@ class ItemHandlerAdapter implements IMEInventory, IBaseMonitor, IBaseMonitor extends PartBasicSt @Override public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos ) { - if ( hand == EnumHand.OFF_HAND ) + if( hand == EnumHand.OFF_HAND ) { return false; } - + final ItemStack is = player.getHeldItem( hand ); // UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor( is.getItem() ); @@ -265,7 +265,7 @@ public abstract class PartP2PTunnel extends PartBasicSt break; } - if( !newType.isEmpty() && !Platform.itemComparisons().isEqualItem( newType, this.getItemStack() ) ) + if( !newType.isEmpty() && !ItemStack.areItemsEqual( newType, this.getItemStack() ) ) { final boolean oldOutput = this.isOutput(); final short myFreq = this.getFrequency(); diff --git a/src/main/java/appeng/parts/reporting/PartConversionMonitor.java b/src/main/java/appeng/parts/reporting/PartConversionMonitor.java index ae622950b..0e13c726f 100644 --- a/src/main/java/appeng/parts/reporting/PartConversionMonitor.java +++ b/src/main/java/appeng/parts/reporting/PartConversionMonitor.java @@ -93,7 +93,7 @@ public class PartConversionMonitor extends AbstractPartMonitor if( item.isEmpty() && this.getDisplayed() != null ) { ModeB = true; - item = ( (IAEItemStack) this.getDisplayed() ).getItemStack(); + item = ( (IAEItemStack) this.getDisplayed() ).createItemStack(); } if( !item.isEmpty() ) @@ -119,7 +119,7 @@ public class PartConversionMonitor extends AbstractPartMonitor final IAEItemStack insertItem = input.copy(); insertItem.setStackSize( targetStack.getCount() ); final IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, insertItem, new PlayerSource( player, this ) ); - player.inventory.setInventorySlotContents( x, failedToInsert == null ? ItemStack.EMPTY : failedToInsert.getItemStack() ); + player.inventory.setInventorySlotContents( x, failedToInsert == null ? ItemStack.EMPTY : failedToInsert.createItemStack() ); } } } @@ -127,7 +127,7 @@ public class PartConversionMonitor extends AbstractPartMonitor { final IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, input, new PlayerSource( player, this ) ); player.inventory.setInventorySlotContents( player.inventory.currentItem, - failedToInsert == null ? ItemStack.EMPTY : failedToInsert.getItemStack() ); + failedToInsert == null ? ItemStack.EMPTY : failedToInsert.createItemStack() ); } } catch( final GridAccessException e ) @@ -154,13 +154,13 @@ public class PartConversionMonitor extends AbstractPartMonitor final IEnergySource energy = this.getProxy().getEnergy(); final IMEMonitor cell = this.getProxy().getStorage().getItemInventory(); - final ItemStack is = input.getItemStack(); + final ItemStack is = input.createItemStack(); input.setStackSize( is.getMaxStackSize() ); final IAEItemStack retrieved = Platform.poweredExtraction( energy, cell, input, new PlayerSource( player, this ) ); if( retrieved != null ) { - ItemStack newItems = retrieved.getItemStack(); + ItemStack newItems = retrieved.createItemStack(); final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor( player ); newItems = adaptor.addItems( newItems ); if( !newItems.isEmpty() ) diff --git a/src/main/java/appeng/parts/reporting/PartPatternTerminal.java b/src/main/java/appeng/parts/reporting/PartPatternTerminal.java index a1af924c1..d917907a3 100644 --- a/src/main/java/appeng/parts/reporting/PartPatternTerminal.java +++ b/src/main/java/appeng/parts/reporting/PartPatternTerminal.java @@ -137,13 +137,13 @@ public class PartPatternTerminal extends AbstractPartTerminal for( int x = 0; x < this.crafting.getSlots() && x < details.getInputs().length; x++ ) { final IAEItemStack item = details.getInputs()[x]; - this.crafting.setStackInSlot( x, item == null ? ItemStack.EMPTY : item.getItemStack() ); + this.crafting.setStackInSlot( x, item == null ? ItemStack.EMPTY : item.createItemStack() ); } for( int x = 0; x < this.output.getSlots() && x < details.getOutputs().length; x++ ) { final IAEItemStack item = details.getOutputs()[x]; - this.output.setStackInSlot( x, item == null ? ItemStack.EMPTY : item.getItemStack() ); + this.output.setStackInSlot( x, item == null ? ItemStack.EMPTY : item.createItemStack() ); } } } diff --git a/src/main/java/appeng/tile/crafting/TileCraftingTile.java b/src/main/java/appeng/tile/crafting/TileCraftingTile.java index e7787dc97..73d3b43bf 100644 --- a/src/main/java/appeng/tile/crafting/TileCraftingTile.java +++ b/src/main/java/appeng/tile/crafting/TileCraftingTile.java @@ -317,7 +317,7 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP for( IAEItemStack ais : inv.getAvailableItems( AEApi.instance().storage().createItemList() ) ) { ais = ais.copy(); - ais.setStackSize( ais.getItemStack().getMaxStackSize() ); + ais.setStackSize( ais.getDefinition().getMaxStackSize() ); while( true ) { final IAEItemStack g = inv.extractItems( ais.copy(), Actionable.MODULATE, this.cluster.getActionSource() ); @@ -329,7 +329,7 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP final WorldCoord wc = places.poll(); places.add( wc ); - Platform.spawnDrops( this.world, wc.getPos(), Collections.singletonList( g.getItemStack() ) ); + Platform.spawnDrops( this.world, wc.getPos(), Collections.singletonList( g.createItemStack() ) ); } } diff --git a/src/main/java/appeng/tile/crafting/TileMolecularAssembler.java b/src/main/java/appeng/tile/crafting/TileMolecularAssembler.java index 87c0a2134..af3d455ba 100644 --- a/src/main/java/appeng/tile/crafting/TileMolecularAssembler.java +++ b/src/main/java/appeng/tile/crafting/TileMolecularAssembler.java @@ -273,7 +273,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade if( !is.isEmpty() && is.getItem() instanceof ItemEncodedPattern ) { - if( !Platform.itemComparisons().isEqualItem( is, this.myPattern ) ) + if( !ItemStack.areItemsEqual( 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 9217c3fdd..7a985e233 100644 --- a/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java +++ b/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java @@ -140,7 +140,7 @@ public class AppEngInternalAEInventory implements IInternalItemHandler, Iterable return ItemStack.EMPTY; } - return this.inv[var1].getItemStack(); + return this.inv[var1].createItemStack(); } @Override @@ -227,7 +227,7 @@ public class AppEngInternalAEInventory implements IInternalItemHandler, Iterable ItemStack newStack = newItemStack.copy(); InvOperation op = InvOperation.SET; - if( Platform.itemComparisons().isEqualItem( oldStack, newStack ) ) + if( ItemStack.areItemsEqual( oldStack, newStack ) ) { if( newStack.getCount() > oldStack.getCount() ) { diff --git a/src/main/java/appeng/tile/inventory/AppEngInternalInventory.java b/src/main/java/appeng/tile/inventory/AppEngInternalInventory.java index a3cbf2b32..1ee707ca3 100644 --- a/src/main/java/appeng/tile/inventory/AppEngInternalInventory.java +++ b/src/main/java/appeng/tile/inventory/AppEngInternalInventory.java @@ -122,7 +122,7 @@ public class AppEngInternalInventory extends ItemStackHandler implements IIntern ItemStack oldStack = this.previousStack; InvOperation op = InvOperation.SET; - if( newStack.isEmpty() || oldStack.isEmpty() || Platform.itemComparisons().isEqualItem( newStack, oldStack ) ) + if( newStack.isEmpty() || oldStack.isEmpty() || ItemStack.areItemsEqual( newStack, oldStack ) ) { if( newStack.getCount() > oldStack.getCount() ) { diff --git a/src/main/java/appeng/tile/misc/TileCharger.java b/src/main/java/appeng/tile/misc/TileCharger.java index 601c2d325..8dbaec7e5 100644 --- a/src/main/java/appeng/tile/misc/TileCharger.java +++ b/src/main/java/appeng/tile/misc/TileCharger.java @@ -86,7 +86,7 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid try { final IAEItemStack item = AEItemStack.loadItemStackFromPacket( data ); - final ItemStack is = item.getItemStack(); + final ItemStack is = item.createItemStack(); this.inv.setStackInSlot( 0, is ); } catch( final Throwable t ) diff --git a/src/main/java/appeng/tile/misc/TileInscriber.java b/src/main/java/appeng/tile/misc/TileInscriber.java index 6c5b39d8b..464ab4f2f 100644 --- a/src/main/java/appeng/tile/misc/TileInscriber.java +++ b/src/main/java/appeng/tile/misc/TileInscriber.java @@ -165,7 +165,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable, { if( ( slot & ( 1 << num ) ) > 0 ) { - this.inv.setStackInSlot( num, AEItemStack.loadItemStackFromPacket( data ).getItemStack() ); + this.inv.setStackInSlot( num, AEItemStack.loadItemStackFromPacket( data ).createItemStack() ); } else { diff --git a/src/main/java/appeng/tile/misc/TileSecurityStation.java b/src/main/java/appeng/tile/misc/TileSecurityStation.java index 834bcc67b..0e527bf64 100644 --- a/src/main/java/appeng/tile/misc/TileSecurityStation.java +++ b/src/main/java/appeng/tile/misc/TileSecurityStation.java @@ -125,7 +125,7 @@ public class TileSecurityStation extends AENetworkTile implements ITerminalHost, for( final IAEItemStack ais : this.inventory.getStoredItems() ) { - drops.add( ais.getItemStack() ); + drops.add( ais.createItemStack() ); } } @@ -171,7 +171,7 @@ public class TileSecurityStation extends AENetworkTile implements ITerminalHost, for( final IAEItemStack ais : this.inventory.getStoredItems() ) { final NBTTagCompound it = new NBTTagCompound(); - ais.getItemStack().writeToNBT( it ); + ais.createItemStack().writeToNBT( it ); storedItems.setTag( String.valueOf( offset ), it ); offset++; } @@ -322,7 +322,7 @@ public class TileSecurityStation extends AENetworkTile implements ITerminalHost, // read permissions for( final IAEItemStack ais : this.inventory.getStoredItems() ) { - final ItemStack is = ais.getItemStack(); + final ItemStack is = ais.createItemStack(); final Item i = is.getItem(); if( i instanceof IBiometricCard ) { diff --git a/src/main/java/appeng/tile/storage/TileChest.java b/src/main/java/appeng/tile/storage/TileChest.java index 1a74ee71b..b732f1e93 100644 --- a/src/main/java/appeng/tile/storage/TileChest.java +++ b/src/main/java/appeng/tile/storage/TileChest.java @@ -620,7 +620,7 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal } else { - this.inputInventory.setStackInSlot( 0, returns.getItemStack() ); + this.inputInventory.setStackInSlot( 0, returns.createItemStack() ); } } } diff --git a/src/main/java/appeng/util/ItemSorters.java b/src/main/java/appeng/util/ItemSorters.java index b0039be74..d77dc878d 100644 --- a/src/main/java/appeng/util/ItemSorters.java +++ b/src/main/java/appeng/util/ItemSorters.java @@ -97,7 +97,7 @@ public class ItemSorters return CONFIG_BASED_SORT_BY_NAME.compare( o1, o2 ); } - final int cmp = api.compareItems( o1.getItemStack(), o2.getItemStack() ); + final int cmp = api.compareItems( o1.asItemStackRepresentation(), o2.asItemStackRepresentation() ); if( getDirection() == SortDir.ASCENDING ) { diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index 25afdf3d8..69d2a7d9e 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -103,7 +103,6 @@ import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IAETagCompound; import appeng.api.storage.data.IItemList; import appeng.api.util.AEColor; import appeng.api.util.AEPartLocation; @@ -123,7 +122,6 @@ import appeng.me.helpers.AENetworkProxy; import appeng.util.helpers.ItemComparisonHelper; import appeng.util.helpers.P2PHelper; import appeng.util.item.AEItemStack; -import appeng.util.item.AESharedNBT; import appeng.util.prioritylist.IPartitionList; @@ -571,11 +569,11 @@ public class Platform } @SideOnly( Side.CLIENT ) - public static List getTooltip( final Object o ) + public static List getTooltip( final Object o ) { if( o == null ) { - return new ArrayList(); + return new ArrayList<>(); } ItemStack itemStack = ItemStack.EMPTY; @@ -590,7 +588,7 @@ public class Platform } else { - return new ArrayList(); + return new ArrayList<>(); } try @@ -601,7 +599,7 @@ public class Platform } catch( final Exception errB ) { - return new ArrayList(); + return new ArrayList<>(); } } @@ -661,32 +659,6 @@ public class Platform } } - public static boolean hasSpecialComparison( final IAEItemStack willAdd ) - { - if( willAdd == null ) - { - return false; - } - final IAETagCompound tag = willAdd.getTagCompound(); - if( tag != null && tag.getSpecialComparison() != null ) - { - return true; - } - return false; - } - - public static boolean hasSpecialComparison( final ItemStack willAdd ) - { - if( AESharedNBT.isShared( willAdd.getTagCompound() ) ) - { - if( ( (IAETagCompound) willAdd.getTagCompound() ).getSpecialComparison() != null ) - { - return true; - } - } - return false; - } - public static boolean isWrench( final EntityPlayer player, final ItemStack eq, final BlockPos pos ) { if( !eq.isEmpty() ) @@ -1475,7 +1447,7 @@ public class Platform final IAEItemStack ae_ext = src.extractItems( ae_req, realForFake, mySrc ); if( ae_ext != null ) { - final ItemStack extracted = ae_ext.getItemStack(); + final ItemStack extracted = ae_ext.createItemStack(); if( !extracted.isEmpty() ) { energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG ); @@ -1484,21 +1456,21 @@ public class Platform } } - final boolean checkFuzzy = ae_req.isOre() || providedTemplate.getItemDamage() == OreDictionary.WILDCARD_VALUE || providedTemplate + final boolean checkFuzzy = ae_req.getOre().isPresent() || providedTemplate.getItemDamage() == OreDictionary.WILDCARD_VALUE || providedTemplate .hasTagCompound() || providedTemplate.isItemStackDamageable(); if( items != null && checkFuzzy ) { for( final IAEItemStack x : items ) { - final ItemStack sh = x.getItemStack(); - if( ( Platform.itemComparisons().isEqualItemType( providedTemplate, - sh ) || ae_req.sameOre( x ) ) && !Platform.itemComparisons().isEqualItem( sh, output ) ) + final ItemStack sh = x.getDefinition(); + if( ( Platform.itemComparisons().isEqualItemType( providedTemplate, sh ) || ae_req.sameOre( x ) ) && !ItemStack.areItemsEqual( sh, + output ) ) { // Platform.isSameItemType( sh, providedTemplate ) - final ItemStack cp = Platform.cloneItemStack( sh ); + final ItemStack cp = sh.copy(); cp.setCount( 1 ); ci.setInventorySlotContents( slot, cp ); - if( r.matches( ci, w ) && Platform.itemComparisons().isEqualItem( r.getCraftingResult( ci ), output ) ) + if( r.matches( ci, w ) && ItemStack.areItemsEqual( r.getCraftingResult( ci ), output ) ) { final IAEItemStack ax = x.copy(); ax.setStackSize( 1 ); @@ -1508,7 +1480,7 @@ public class Platform if( ex != null ) { energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG ); - return ex.getItemStack(); + return ex.createItemStack(); } } } @@ -1520,11 +1492,6 @@ public class Platform return ItemStack.EMPTY; } - public static ItemStack cloneItemStack( final ItemStack a ) - { - return a.copy(); - } - public static ItemStack getContainerItem( final ItemStack stackInSlot ) { if( stackInSlot == null ) diff --git a/src/main/java/appeng/util/helpers/ItemComparisonHelper.java b/src/main/java/appeng/util/helpers/ItemComparisonHelper.java index cbfa5c551..d11f190a0 100644 --- a/src/main/java/appeng/util/helpers/ItemComparisonHelper.java +++ b/src/main/java/appeng/util/helpers/ItemComparisonHelper.java @@ -19,26 +19,15 @@ package appeng.util.helpers; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - import javax.annotation.Nonnull; import net.minecraft.init.Items; 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; @@ -50,8 +39,6 @@ import appeng.util.item.OreReference; public class ItemComparisonHelper { - private static Field tagList; - /** * Compare the two {@link ItemStack}s based on the same {@link Item} and damage value. * @@ -62,7 +49,7 @@ public class ItemComparisonHelper * * @return true, if both are equal. */ - public boolean isEqualItemType( final ItemStack that, final ItemStack other ) + public boolean isEqualItemType( @Nonnull final ItemStack that, @Nonnull final ItemStack other ) { if( !that.isEmpty() && !other.isEmpty() && that.getItem() == other.getItem() ) { @@ -75,29 +62,6 @@ public class ItemComparisonHelper 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( @Nonnull final ItemStack left, @Nonnull final ItemStack right ) - { - return this.isItemEqual( left, right ); - } - - /** - * A slightly different method from ItemStack.java to skip the isEmpty() check. This allows you to check for - * identical empty spots.. - */ - public boolean isItemEqual( ItemStack left, ItemStack right ) - { - return left.getItem() == right.getItem() && left.getItemDamage() == right.getItemDamage(); - } - /** * Compares two {@link ItemStack} and their NBT tag for equality. * @@ -108,7 +72,7 @@ public class ItemComparisonHelper */ public boolean isSameItem( @Nonnull final ItemStack is, @Nonnull final ItemStack filter ) { - return this.isEqualItem( is, filter ) && this.hasSameNbtTag( is, filter ); + return ItemStack.areItemsEqual( is, filter ) && this.isNbtTagEqual( is.getTagCompound(), filter.getTagCompound() ); } /** @@ -183,8 +147,8 @@ public class ItemComparisonHelper } } - final OreReference aOR = OreHelper.INSTANCE.isOre( a ); - final OreReference bOR = OreHelper.INSTANCE.isOre( b ); + final OreReference aOR = OreHelper.INSTANCE.getOre( a ).orElse( null ); + final OreReference bOR = OreHelper.INSTANCE.getOre( b ).orElse( null ); if( OreHelper.INSTANCE.sameOre( aOR, bOR ) ) { @@ -212,243 +176,14 @@ public class ItemComparisonHelper */ public boolean isNbtTagEqual( final NBTBase left, final NBTBase right ) { - // same type? - final byte id = left.getId(); - if( id == right.getId() ) + if( left == right ) { - 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( !this.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 = this.tagList( lA ); - final List aTag = this.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( !this.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 true; + } + if( left != null ) + { + 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() ^ this.createUnorderedNbtHash( ctA.getTag( name ) ); - } - - return hash; - } - - case 9: // ) // A instanceof NBTTagList ) - { - final NBTTagList lA = (NBTTagList) nbt; - hash += 9 * lA.tagCount(); - - final List l = this.tagList( lA ); - for( int x = 0; x < l.size(); x++ ) - { - hash += ( (Integer) x ).hashCode() ^ this.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.isEmpty() && b.isEmpty() ) - { - return true; - } - if( a.isEmpty() || b.isEmpty() ) - { - 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 this.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/AdaptorList.java b/src/main/java/appeng/util/inv/AdaptorList.java index 87f61eb84..c004eb7fd 100644 --- a/src/main/java/appeng/util/inv/AdaptorList.java +++ b/src/main/java/appeng/util/inv/AdaptorList.java @@ -190,7 +190,7 @@ public class AdaptorList extends InventoryAdaptor for( final ItemStack is : this.i ) { - if( Platform.itemComparisons().isEqualItem( is, left ) ) + if( ItemStack.areItemsEqual( is, left ) ) { is.grow( left.getCount() ); return ItemStack.EMPTY; diff --git a/src/main/java/appeng/util/inv/IMEAdaptor.java b/src/main/java/appeng/util/inv/IMEAdaptor.java index 3c2d61e56..8b8817293 100644 --- a/src/main/java/appeng/util/inv/IMEAdaptor.java +++ b/src/main/java/appeng/util/inv/IMEAdaptor.java @@ -99,7 +99,7 @@ public class IMEAdaptor extends InventoryAdaptor if( out != null ) { - return out.getItemStack(); + return out.createItemStack(); } return ItemStack.EMPTY; @@ -139,7 +139,7 @@ public class IMEAdaptor extends InventoryAdaptor out = this.target.extractItems( req, type, this.src ); if( out != null ) { - return out.getItemStack(); + return out.createItemStack(); } } } @@ -166,7 +166,7 @@ public class IMEAdaptor extends InventoryAdaptor final IAEItemStack out = this.target.injectItems( in, Actionable.MODULATE, this.src ); if( out != null ) { - return out.getItemStack(); + return out.createItemStack(); } } return ItemStack.EMPTY; @@ -181,7 +181,7 @@ public class IMEAdaptor extends InventoryAdaptor final IAEItemStack out = this.target.injectItems( in, Actionable.SIMULATE, this.src ); if( out != null ) { - return out.getItemStack(); + return out.createItemStack(); } } return ItemStack.EMPTY; diff --git a/src/main/java/appeng/util/inv/ItemSlot.java b/src/main/java/appeng/util/inv/ItemSlot.java index c5e157d4e..2e2320da1 100644 --- a/src/main/java/appeng/util/inv/ItemSlot.java +++ b/src/main/java/appeng/util/inv/ItemSlot.java @@ -37,7 +37,7 @@ public class ItemSlot public ItemStack getItemStack() { return this.itemStack - .isEmpty() ? ( this.aeItemStack == null ? ItemStack.EMPTY : ( this.itemStack = this.aeItemStack.getItemStack() ) ) : this.itemStack; + .isEmpty() ? ( this.aeItemStack == null ? ItemStack.EMPTY : ( this.itemStack = this.aeItemStack.createItemStack() ) ) : this.itemStack; } public void setItemStack( final ItemStack is ) diff --git a/src/main/java/appeng/util/item/AEFluidStack.java b/src/main/java/appeng/util/item/AEFluidStack.java index e6c38ae3b..5fcb4c30b 100644 --- a/src/main/java/appeng/util/item/AEFluidStack.java +++ b/src/main/java/appeng/util/item/AEFluidStack.java @@ -35,12 +35,12 @@ import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; import appeng.api.config.FuzzyMode; import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IAETagCompound; import appeng.util.Platform; @@ -49,7 +49,7 @@ public final class AEFluidStack extends AEStack implements IAEFlu private final int myHash; private final Fluid fluid; - private IAETagCompound tagCompound; + private NBTTagCompound tagCompound; private AEFluidStack( final AEFluidStack is ) { @@ -262,12 +262,6 @@ public final class AEFluidStack extends AEStack implements IAEFlu return dup; } - @Override - public IAETagCompound getTagCompound() - { - return this.tagCompound; - } - @Override public boolean isItem() { @@ -330,11 +324,6 @@ public final class AEFluidStack extends AEStack implements IAEFlu return false; } - if( AESharedNBT.isShared( tb ) ) - { - return ta == tb; - } - return Platform.itemComparisons().isNbtTagEqual( ta, tb ); } } @@ -359,7 +348,7 @@ public final class AEFluidStack extends AEStack implements IAEFlu final FluidStack is = new FluidStack( this.fluid, (int) Math.min( Integer.MAX_VALUE, this.getStackSize() ) ); if( this.tagCompound != null ) { - is.tag = this.tagCompound.getNBTTagCompoundCopy(); + is.tag = this.tagCompound.copy(); } return is; @@ -372,22 +361,24 @@ public final class AEFluidStack extends AEStack implements IAEFlu } @Override - void writeIdentity( final ByteBuf i ) throws IOException + public ItemStack asItemStackRepresentation() + { + // TODO: fluids, how do they even work? + return FluidUtil.getFilledBucket( getFluidStack() ); + } + + @Override + protected void writeToStream( final ByteBuf i ) throws IOException { final byte[] name = this.fluid.getName().getBytes( "UTF-8" ); i.writeByte( (byte) name.length ); i.writeBytes( name ); - } - - @Override - void readNBT( final ByteBuf i ) throws IOException - { if( this.hasTagCompound() ) { final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final DataOutputStream data = new DataOutputStream( bytes ); - CompressedStreamTools.write( (NBTTagCompound) this.tagCompound, data ); + CompressedStreamTools.write( this.tagCompound, data ); final byte[] tagBytes = bytes.toByteArray(); final int size = tagBytes.length; diff --git a/src/main/java/appeng/util/item/AEItemDef.java b/src/main/java/appeng/util/item/AEItemDef.java deleted file mode 100644 index 18d3d7288..000000000 --- a/src/main/java/appeng/util/item/AEItemDef.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * 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.item; - - -import java.util.List; - -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -import appeng.util.Platform; - - -public class AEItemDef -{ - - static final AESharedNBT LOW_TAG = new AESharedNBT( Integer.MIN_VALUE ); - static final AESharedNBT HIGH_TAG = new AESharedNBT( Integer.MAX_VALUE ); - - private final int itemID; - private final Item item; - private int myHash; - private int def; - private int damageValue; - private int displayDamage; - private int maxDamage; - private AESharedNBT tagCompound; - @SideOnly( Side.CLIENT ) - private String displayName; - @SideOnly( Side.CLIENT ) - private List tooltip; - @SideOnly( Side.CLIENT ) - private ResourceLocation uniqueID; - private OreReference isOre; - - public AEItemDef( final Item it ) - { - this.item = it; - this.itemID = Item.getIdFromItem( it ); - } - - AEItemDef copy() - { - final AEItemDef t = new AEItemDef( this.getItem() ); - t.def = this.def; - t.setDamageValue( this.getDamageValue() ); - t.setDisplayDamage( this.getDisplayDamage() ); - t.setMaxDamage( this.getMaxDamage() ); - t.setTagCompound( this.getTagCompound() ); - t.setIsOre( this.getIsOre() ); - return t; - } - - @Override - public boolean equals( final Object obj ) - { - if( obj == null ) - { - return false; - } - if( this.getClass() != obj.getClass() ) - { - return false; - } - final AEItemDef other = (AEItemDef) obj; - return other.getDamageValue() == this.getDamageValue() && other.getItem() == this.getItem() && this.getTagCompound() == other.getTagCompound(); - } - - boolean isItem( final ItemStack otherStack ) - { - // hackery! - final int dmg = this.getDamageValueHack( otherStack ); - - if( this.getItem() == otherStack.getItem() && dmg == this.getDamageValue() ) - { - if( ( this.getTagCompound() != null ) == otherStack.hasTagCompound() ) - { - return true; - } - - if( this.getTagCompound() != null && otherStack.hasTagCompound() ) - { - return Platform.itemComparisons().isNbtTagEqual( this.getTagCompound(), otherStack.getTagCompound() ); - } - - return true; - } - return false; - } - - int getDamageValueHack( final ItemStack is ) - { - return Items.BLAZE_ROD.getDamage( is ); - } - - void reHash() - { - this.def = this.getItemID() << Platform.DEF_OFFSET | this.getDamageValue(); - this.myHash = this.def ^ ( this.getTagCompound() == null ? 0 : System.identityHashCode( this.getTagCompound() ) ); - } - - AESharedNBT getTagCompound() - { - return this.tagCompound; - } - - void setTagCompound( final AESharedNBT tagCompound ) - { - this.tagCompound = tagCompound; - } - - int getDamageValue() - { - return this.damageValue; - } - - int setDamageValue( final int damageValue ) - { - this.damageValue = damageValue; - return damageValue; - } - - Item getItem() - { - return this.item; - } - - int getDisplayDamage() - { - return this.displayDamage; - } - - void setDisplayDamage( final int displayDamage ) - { - this.displayDamage = displayDamage; - } - - String getDisplayName() - { - return this.displayName; - } - - void setDisplayName( final String displayName ) - { - this.displayName = displayName; - } - - List getTooltip() - { - return this.tooltip; - } - - List setTooltip( final List tooltip ) - { - this.tooltip = tooltip; - return tooltip; - } - - ResourceLocation getUniqueID() - { - return this.uniqueID; - } - - ResourceLocation setUniqueID( final ResourceLocation uniqueID ) - { - this.uniqueID = uniqueID; - return uniqueID; - } - - OreReference getIsOre() - { - return this.isOre; - } - - void setIsOre( final OreReference isOre ) - { - this.isOre = isOre; - } - - int getItemID() - { - return this.itemID; - } - - int getMaxDamage() - { - return this.maxDamage; - } - - void setMaxDamage( final int maxDamage ) - { - this.maxDamage = maxDamage; - } - - /** - * TODO: Check if replaceable by hashCode(); - */ - int getMyHash() - { - return this.myHash; - } - -} diff --git a/src/main/java/appeng/util/item/AEItemStack.java b/src/main/java/appeng/util/item/AEItemStack.java index 01ba3051e..feca99453 100644 --- a/src/main/java/appeng/util/item/AEItemStack.java +++ b/src/main/java/appeng/util/item/AEItemStack.java @@ -19,102 +19,57 @@ package appeng.util.item; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; import java.io.IOException; -import java.security.InvalidParameterException; import java.util.List; +import java.util.Optional; import javax.annotation.Nullable; import io.netty.buffer.ByteBuf; -import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.ItemHandlerHelper; import appeng.api.config.FuzzyMode; import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IAETagCompound; import appeng.util.Platform; -public final class AEItemStack extends AEStack implements IAEItemStack, Comparable +public final class AEItemStack extends AEStack implements IAEItemStack { + private AESharedItemStack sharedStack; + private Optional oreReference; - private AEItemDef def; + @SideOnly( Side.CLIENT ) + private String displayName; + @SideOnly( Side.CLIENT ) + private List tooltip; + @SideOnly( Side.CLIENT ) + private ResourceLocation uniqueID; private AEItemStack( final AEItemStack is ) { - this.setDefinition( is.getDefinition() ); this.setStackSize( is.getStackSize() ); this.setCraftable( is.isCraftable() ); this.setCountRequestable( is.getCountRequestable() ); + this.sharedStack = is.sharedStack; + this.oreReference = is.oreReference; } - private AEItemStack( final ItemStack is ) + private AEItemStack( final AESharedItemStack is, long size ) { - if( is.isEmpty() ) - { - throw new InvalidParameterException( "null is not a valid ItemStack for AEItemStack." ); - } - - final Item item = is.getItem(); - if( item == Items.AIR ) - { - throw new InvalidParameterException( "Contained item is null, thus not a valid ItemStack for AEItemStack." ); - } - - this.setDefinition( new AEItemDef( item ) ); - - if( this.getDefinition().getItem() == Items.AIR ) - { - throw new InvalidParameterException( "This ItemStack is bad, it has a null item." ); - } - - /* - * Prevent an Item from changing the damage value on me... Either, this or a core mod. - */ - - /* - * Super hackery. - * is.itemID = appeng.api.Materials.matQuartz.itemID; damageValue = is.getItemDamage(); is.itemID = itemID; - */ - - /* - * Kinda hackery - */ - this.getDefinition().setDamageValue( this.def.getDamageValueHack( is ) ); - if( !is.getItem().isDamageable() ) - { - this.getDefinition().setDisplayDamage( Integer.MAX_VALUE ); - } - else - { - this.getDefinition().setDisplayDamage( (int) ( is.getItem().getDurabilityForDisplay( is ) * Integer.MAX_VALUE ) ); - } - this.getDefinition().setMaxDamage( is.getMaxDamage() ); - - final NBTTagCompound tagCompound = is.getTagCompound(); - if( tagCompound != null ) - { - this.getDefinition().setTagCompound( (AESharedNBT) AESharedNBT.getSharedTagCompound( tagCompound, is ) ); - } - - this.setStackSize( is.getCount() ); + this.sharedStack = is; + this.setStackSize( size ); this.setCraftable( false ); this.setCountRequestable( 0 ); - - this.getDefinition().reHash(); - this.getDefinition().setIsOre( OreHelper.INSTANCE.isOre( is ) ); + this.oreReference = OreHelper.INSTANCE.getOre( is.getDefinition() ); } public static IAEItemStack loadItemStackFromNBT( final NBTTagCompound i ) @@ -131,7 +86,6 @@ public final class AEItemStack extends AEStack implements IAEItemS } final AEItemStack item = AEItemStack.create( itemstack ); - // item.priority = i.getInteger( "Priority" ); item.setStackSize( i.getLong( "Cnt" ) ); item.setCountRequestable( i.getLong( "Req" ) ); item.setCraftable( i.getBoolean( "Craft" ) ); @@ -146,7 +100,7 @@ public final class AEItemStack extends AEStack implements IAEItemS return null; } - return new AEItemStack( stack ); + return new AEItemStack( AEItemStackRegistry.getRegisteredStack( stack ), stack.getCount() ); } public static IAEItemStack loadItemStackFromPacket( final ByteBuf data ) throws IOException @@ -156,41 +110,17 @@ public final class AEItemStack extends AEStack implements IAEItemS final byte stackType = (byte) ( ( mask & 0x0C ) >> 2 ); final byte countReqType = (byte) ( ( mask & 0x30 ) >> 4 ); final boolean isCraftable = ( mask & 0x40 ) > 0; - final boolean hasTagCompound = ( mask & 0x80 ) > 0; - // don't send this... - final NBTTagCompound d = new NBTTagCompound(); - - // For some insane reason, Vanilla can only parse numeric item ids if they are strings - short itemNumericId = data.readShort(); - d.setString( "id", String.valueOf( itemNumericId ) ); - d.setShort( "Damage", data.readShort() ); - d.setByte( "Count", (byte) 1 ); // 1 Because vanilla'll freak out otherwise - - if( hasTagCompound ) - { - final int len = data.readInt(); - - final byte[] bd = new byte[len]; - data.readBytes( bd ); - - final ByteArrayInputStream di = new ByteArrayInputStream( bd ); - d.setTag( "tag", CompressedStreamTools.read( new DataInputStream( di ) ) ); - } - - // long priority = getPacketValue( PriorityType, data ); + final ItemStack itemstack = ByteBufUtils.readItemStack( data ); final long stackSize = getPacketValue( stackType, data ); final long countRequestable = getPacketValue( countReqType, data ); - final ItemStack itemstack = new ItemStack( d ); - if( itemstack.isEmpty() ) { return null; } final AEItemStack item = AEItemStack.create( itemstack ); - // item.priority = (int) priority; item.setStackSize( stackSize ); item.setCountRequestable( countRequestable ); item.setCraftable( isCraftable ); @@ -205,9 +135,6 @@ public final class AEItemStack extends AEStack implements IAEItemS return; } - // if ( priority < ((AEItemStack) option).priority ) - // priority = ((AEItemStack) option).priority; - this.incStackSize( option.getStackSize() ); this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() ); this.setCraftable( this.isCraftable() || option.isCraftable() ); @@ -216,57 +143,10 @@ public final class AEItemStack extends AEStack implements IAEItemS @Override public void writeToNBT( final NBTTagCompound i ) { - /* - * Mojang Fucked this over ; GC Optimization - Ugly Yes, but it saves a lot in the memory department. - */ - - /* - * NBTBase id = i.getTag( "id" ); NBTBase Count = i.getTag( "Count" ); NBTBase Cnt = i.getTag( "Cnt" ); NBTBase - * Req = i.getTag( "Req" ); NBTBase Craft = i.getTag( "Craft" ); NBTBase Damage = i.getTag( "Damage" ); - */ - - /* - * if ( id != null && id instanceof NBTTagShort ) ((NBTTagShort) id).data = (short) this.def.item.itemID; else - */ - // i.setShort( "id", (short) Item.REGISTRY.getIDForObject( this.getDefinition().getItem() ) ); - ResourceLocation resourcelocation = Item.REGISTRY.getNameForObject( this.getItem() ); - i.setString( "id", resourcelocation == null ? "minecraft:air" : resourcelocation.toString() ); - - /* - * if ( Count != null && Count instanceof NBTTagByte ) ((NBTTagByte) Count).data = (byte) 1; else - */ - i.setByte( "Count", (byte) 1 ); - - /* - * if ( Cnt != null && Cnt instanceof NBTTagLong ) ((NBTTagLong) Cnt).data = this.stackSize; else - */ + this.getDefinition().writeToNBT( i ); i.setLong( "Cnt", this.getStackSize() ); - - /* - * if ( Req != null && Req instanceof NBTTagLong ) ((NBTTagLong) Req).data = this.stackSize; else - */ i.setLong( "Req", this.getCountRequestable() ); - - /* - * if ( Craft != null && Craft instanceof NBTTagByte ) ((NBTTagByte) Craft).data = (byte) (this.isCraftable() ? - * 1 : 0); else - */ i.setBoolean( "Craft", this.isCraftable() ); - - /* - * if ( Damage != null && Damage instanceof NBTTagShort ) ((NBTTagShort) Damage).data = (short) - * this.def.damageValue; else - */ - i.setShort( "Damage", (short) this.getDefinition().getDamageValue() ); - - if( this.getDefinition().getTagCompound() != null ) - { - i.setTag( "tag", this.getDefinition().getTagCompound() ); - } - else - { - i.removeTag( "tag" ); - } } @Override @@ -285,8 +165,8 @@ public final class AEItemStack extends AEStack implements IAEItemS { if( this.getDefinition().getItem().isDamageable() ) { - final ItemStack a = this.getItemStack(); - final ItemStack b = o.getItemStack(); + final ItemStack a = this.getDefinition(); + final ItemStack b = o.getDefinition(); try { @@ -346,7 +226,7 @@ public final class AEItemStack extends AEStack implements IAEItemS { if( this.getDefinition().getItem().isDamageable() ) { - final ItemStack a = this.getItemStack(); + final ItemStack a = this.getDefinition(); try { @@ -405,20 +285,6 @@ public final class AEItemStack extends AEStack implements IAEItemS return new AEItemStack( this ); } - @Override - public IAEItemStack empty() - { - final IAEItemStack dup = this.copy(); - dup.reset(); - return dup; - } - - @Override - public IAETagCompound getTagCompound() - { - return this.getDefinition().getTagCompound(); - } - @Override public boolean isItem() { @@ -438,16 +304,9 @@ public final class AEItemStack extends AEStack implements IAEItemS } @Override - public ItemStack getItemStack() + public ItemStack createItemStack() { - final ItemStack is = new ItemStack( this.getDefinition().getItem(), (int) Math.min( Integer.MAX_VALUE, this.getStackSize() ), this.getDefinition() - .getDamageValue() ); - if( this.getDefinition().getTagCompound() != null ) - { - is.setTagCompound( this.getDefinition().getTagCompound().getNBTTagCompoundCopy() ); - } - - return is; + return ItemHandlerHelper.copyStackWithSize( this.getDefinition(), (int) Math.min( Integer.MAX_VALUE, this.getStackSize() ) ); } @Override @@ -459,7 +318,7 @@ public final class AEItemStack extends AEStack implements IAEItemS @Override public int getItemDamage() { - return this.getDefinition().getDamageValue(); + return this.sharedStack.getItemDamage(); } @Override @@ -476,7 +335,7 @@ public final class AEItemStack extends AEStack implements IAEItemS return false; } - return this.getDefinition().equals( ( (AEItemStack) otherStack ).getDefinition() ); + return this.sharedStack == ( (AEItemStack) otherStack ).sharedStack; } @Override @@ -486,14 +345,19 @@ public final class AEItemStack extends AEStack implements IAEItemS { return false; } + int oldSize = otherStack.getCount(); - return this.getDefinition().isItem( otherStack ); + otherStack.setCount( 1 ); + boolean ret = ItemStack.areItemStacksEqual( this.getDefinition(), otherStack ); + otherStack.setCount( oldSize ); + + return ret; } @Override public int hashCode() { - return this.getDefinition().getMyHash(); + return this.sharedStack.hashCode(); } @Override @@ -501,40 +365,11 @@ public final class AEItemStack extends AEStack implements IAEItemS { if( ia instanceof AEItemStack ) { - return ( (AEItemStack) ia ).getDefinition().equals( this.def );// && def.tagCompound == ((AEItemStack) - // ia).def.tagCompound; + return this.isSameType( (AEItemStack) ia ); } else if( ia instanceof ItemStack ) { - final ItemStack is = (ItemStack) ia; - - if( is.getItem() == this.getDefinition().getItem() && is.getItemDamage() == this.getDefinition().getDamageValue() ) - { - final NBTTagCompound ta = this.getDefinition().getTagCompound(); - final NBTTagCompound tb = is.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( AESharedNBT.isShared( tb ) ) - { - return ta == tb; - } - - return Platform.itemComparisons().isNbtTagEqual( ta, tb ); - } + return this.isSameType( (ItemStack) ia ); } return false; } @@ -542,226 +377,77 @@ public final class AEItemStack extends AEStack implements IAEItemS @Override public String toString() { - return this.getItemStack().toString(); - } - - @Override - public int compareTo( final AEItemStack b ) - { - final int id = this.getDefinition().getItemID() - b.getDefinition().getItemID(); - if( id != 0 ) - { - return id; - } - - final int damageValue = this.getDefinition().getDamageValue() - b.getDefinition().getDamageValue(); - if( damageValue != 0 ) - { - return damageValue; - } - - final int displayDamage = this.getDefinition().getDisplayDamage() - b.getDefinition().getDisplayDamage(); - if( displayDamage != 0 ) - { - return displayDamage; - } - - return ( this.getDefinition().getTagCompound() == b.getDefinition().getTagCompound() ) ? 0 : this.compareNBT( b.getDefinition() ); - } - - private int compareNBT( final AEItemDef b ) - { - final int nbt = this.compare( ( this.getDefinition().getTagCompound() == null ? 0 : this.getDefinition().getTagCompound().getHash() ), - ( b.getTagCompound() == null ? 0 : b.getTagCompound().getHash() ) ); - if( nbt == 0 ) - { - return this.compare( System.identityHashCode( this.getDefinition().getTagCompound() ), System.identityHashCode( b.getTagCompound() ) ); - } - return nbt; - } - - private int compare( final int l, final int m ) - { - return l < m ? -1 : ( l > m ? 1 : 0 ); + return this.getDefinition().toString(); } @SideOnly( Side.CLIENT ) - public List getToolTip() + public List getToolTip() { - if( this.getDefinition().getTooltip() == null ) + if( this.tooltip == null ) { - final ItemStack is = this.getItemStack(); - is.setCount( 1 ); - this.getDefinition().setTooltip( Platform.getTooltip( is ) ); + this.tooltip = Platform.getTooltip( this.asItemStackRepresentation() ); } - - return this.getDefinition().getTooltip(); + return this.tooltip; } @SideOnly( Side.CLIENT ) public String getDisplayName() { - if( this.getDefinition().getDisplayName() == null ) + if( this.displayName == null ) { - final ItemStack is = this.getItemStack(); - is.setCount( 1 ); - this.getDefinition().setDisplayName( Platform.getItemDisplayName( is ) ); + this.displayName = Platform.getItemDisplayName( this.asItemStackRepresentation() ); } - - return this.getDefinition().getDisplayName(); + return this.displayName; } @SideOnly( Side.CLIENT ) public String getModID() { - if( this.getDefinition().getUniqueID() != null ) + if( this.uniqueID == null ) { - return this.getModName( this.getDefinition().getUniqueID() ); + this.uniqueID = Item.REGISTRY.getNameForObject( this.getDefinition().getItem() ); } - return this.getModName( this.getDefinition().setUniqueID( Item.REGISTRY.getNameForObject( this.getDefinition().getItem() ) ) ); - } - - private String getModName( final ResourceLocation uniqueIdentifier ) - { - if( uniqueIdentifier == null ) + if( this.uniqueID == null ) { return "** Null"; } - return uniqueIdentifier.getResourceDomain() == null ? "** Null" : uniqueIdentifier.getResourceDomain(); + return this.uniqueID.getResourceDomain() == null ? "** Null" : this.uniqueID.getResourceDomain(); } - IAEItemStack getLow( final FuzzyMode fuzzy, final boolean ignoreMeta ) + public Optional getOre() { - final AEItemStack bottom = new AEItemStack( this ); - final AEItemDef newDef = bottom.setDefinition( bottom.getDefinition().copy() ); - - if( ignoreMeta ) - { - newDef.setDisplayDamage( newDef.setDamageValue( 0 ) ); - newDef.reHash(); - return bottom; - } - - if( newDef.getItem().isDamageable() ) - { - if( fuzzy == FuzzyMode.IGNORE_ALL ) - { - newDef.setDisplayDamage( 0 ); - } - else if( fuzzy == FuzzyMode.PERCENT_99 ) - { - if( this.getDefinition().getDamageValue() == 0 ) - { - newDef.setDisplayDamage( 0 ); - } - else - { - newDef.setDisplayDamage( 1 ); - } - } - else - { - final int breakpoint = fuzzy.calculateBreakPoint( this.getDefinition().getMaxDamage() ); - newDef.setDisplayDamage( breakpoint <= this.getDefinition().getDisplayDamage() ? breakpoint : 0 ); - } - - newDef.setDamageValue( newDef.getDisplayDamage() ); - } - - newDef.setTagCompound( AEItemDef.LOW_TAG ); - newDef.reHash(); - return bottom; - } - - IAEItemStack getHigh( final FuzzyMode fuzzy, final boolean ignoreMeta ) - { - final AEItemStack top = new AEItemStack( this ); - final AEItemDef newDef = top.setDefinition( top.getDefinition().copy() ); - - if( ignoreMeta ) - { - newDef.setDisplayDamage( newDef.setDamageValue( Integer.MAX_VALUE ) ); - newDef.reHash(); - return top; - } - - if( newDef.getItem().isDamageable() ) - { - if( fuzzy == FuzzyMode.IGNORE_ALL ) - { - newDef.setDisplayDamage( this.getDefinition().getMaxDamage() + 1 ); - } - else if( fuzzy == FuzzyMode.PERCENT_99 ) - { - if( this.getDefinition().getDamageValue() == 0 ) - { - newDef.setDisplayDamage( 0 ); - } - else - { - newDef.setDisplayDamage( this.getDefinition().getMaxDamage() + 1 ); - } - } - else - { - final int breakpoint = fuzzy.calculateBreakPoint( this.getDefinition().getMaxDamage() ); - newDef.setDisplayDamage( this.getDefinition().getDisplayDamage() < breakpoint ? breakpoint - 1 : this.getDefinition().getMaxDamage() + 1 ); - } - - newDef.setDamageValue( newDef.getDisplayDamage() ); - } - - newDef.setTagCompound( AEItemDef.HIGH_TAG ); - newDef.reHash(); - return top; - } - - public boolean isOre() - { - return this.getDefinition().getIsOre() != null; + return this.oreReference; } @Override - void writeIdentity( final ByteBuf i ) throws IOException + protected void writeToStream( final ByteBuf data ) throws IOException { - i.writeShort( Item.REGISTRY.getIDForObject( this.getDefinition().getItem() ) ); - i.writeShort( this.getItemDamage() ); - } - - @Override - void readNBT( final ByteBuf i ) throws IOException - { - if( this.hasTagCompound() ) - { - final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - final DataOutputStream data = new DataOutputStream( bytes ); - - CompressedStreamTools.write( (NBTTagCompound) this.getTagCompound(), data ); - - final byte[] tagBytes = bytes.toByteArray(); - final int size = tagBytes.length; - - i.writeInt( size ); - i.writeBytes( tagBytes ); - } + ByteBufUtils.writeItemStack( data, this.getDefinition() ); } @Override public boolean hasTagCompound() { - return this.getDefinition().getTagCompound() != null; + return this.getDefinition().hasTagCompound(); } - AEItemDef getDefinition() + @Override + public ItemStack asItemStackRepresentation() { - return this.def; + return getDefinition().copy(); } - private AEItemDef setDefinition( final AEItemDef def ) + @Override + public ItemStack getDefinition() { - this.def = def; - return def; + return this.sharedStack.getDefinition(); } + + AESharedItemStack getSharedStack() + { + return this.sharedStack; + } + } diff --git a/src/api/java/appeng/api/storage/data/IAETagCompound.java b/src/main/java/appeng/util/item/AEItemStackRegistry.java similarity index 51% rename from src/api/java/appeng/api/storage/data/IAETagCompound.java rename to src/main/java/appeng/util/item/AEItemStackRegistry.java index bd4b57b8b..35f7ba769 100644 --- a/src/api/java/appeng/api/storage/data/IAETagCompound.java +++ b/src/main/java/appeng/util/item/AEItemStackRegistry.java @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2013 AlgorithmX2 + * Copyright (c) 2017 AlgorithmX2 * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -21,39 +21,51 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package appeng.api.storage.data; +package appeng.util.item; -import net.minecraft.nbt.NBTTagCompound; +import java.lang.ref.WeakReference; +import java.util.WeakHashMap; -import appeng.api.features.IItemComparison; +import javax.annotation.Nonnull; + +import net.minecraft.item.ItemStack; -/** - * Don't cast this... either compare with it, or copy it. - * - * Don't Implement. - */ -public interface IAETagCompound +public final class AEItemStackRegistry { + private static final WeakHashMap> REGISTRY = new WeakHashMap<>(); - /** - * @return a copy ( the copy will not be a IAETagCompound, it will be a NBTTagCompound ) - */ - NBTTagCompound getNBTTagCompoundCopy(); + private AEItemStackRegistry() + { + } - /** - * compare to other NBTTagCompounds or IAETagCompounds - * - * @param a compared object - * - * @return true, if they are the same. - */ - @Override - boolean equals( Object a ); + static synchronized AESharedItemStack getRegisteredStack( final @Nonnull ItemStack itemStack ) + { + if( itemStack.isEmpty() ) + { + throw new IllegalArgumentException( "stack cannot be empty" ); + } - /** - * @return the special comparison for this tag - */ - IItemComparison getSpecialComparison(); -} \ No newline at end of file + int oldStackSize = itemStack.getCount(); + itemStack.setCount( 1 ); + + AESharedItemStack search = new AESharedItemStack( itemStack ); + WeakReference weak = REGISTRY.get( search ); + AESharedItemStack ret = null; + + if( weak != null ) + { + ret = weak.get(); + } + + if( ret == null ) + { + ret = new AESharedItemStack( itemStack.copy() ); + REGISTRY.put( ret, new WeakReference<>( ret ) ); + } + itemStack.setCount( oldStackSize ); + + return ret; + } +} diff --git a/src/main/java/appeng/util/item/AESharedItemStack.java b/src/main/java/appeng/util/item/AESharedItemStack.java new file mode 100644 index 000000000..2014ec6fc --- /dev/null +++ b/src/main/java/appeng/util/item/AESharedItemStack.java @@ -0,0 +1,216 @@ +/* + * 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.item; + + +import java.util.Objects; + +import com.google.common.base.Preconditions; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import appeng.api.config.FuzzyMode; +import appeng.util.Platform; + + +final class AESharedItemStack implements Comparable +{ + private static final NBTTagCompound LOW_TAG = new NBTTagCompound(); + private static final NBTTagCompound HIGH_TAG = new NBTTagCompound(); + + private final ItemStack itemStack; + private final int itemId; + private final int itemDamage; + + public AESharedItemStack( final ItemStack itemStack ) + { + this.itemStack = itemStack; + this.itemId = Item.getIdFromItem( itemStack.getItem() ); + this.itemDamage = itemStack.getItemDamage(); + } + + ItemStack getDefinition() + { + return this.itemStack; + } + + int getItemDamage() + { + return this.itemDamage; + } + + @Override + public int hashCode() + { + return Objects.hash( itemStack.getItem(), this.itemDamage ); + } + + @Override + public boolean equals( final Object obj ) + { + if( obj instanceof AESharedItemStack ) + { + final AESharedItemStack other = (AESharedItemStack) obj; + + Preconditions.checkState( this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1" ); + Preconditions.checkArgument( other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1" ); + + if( this.itemStack == other.itemStack ) + { + return true; + } + return ItemStack.areItemStacksEqual( this.itemStack, other.itemStack ); + } + return false; + } + + @Override + public int compareTo( final AESharedItemStack b ) + { + Preconditions.checkState( this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1" ); + Preconditions.checkArgument( b.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1" ); + + if( this.itemStack == b.getDefinition() ) + { + return 0; + } + + final int id = this.itemId - b.itemId; + if( id != 0 ) + { + return id; + } + + final int damageValue = this.itemDamage - b.itemDamage; + if( damageValue != 0 ) + { + return damageValue; + } + + return this.compareNBT( b.getDefinition() ); + } + + private int compareNBT( final ItemStack b ) + { + if( Platform.itemComparisons().isNbtTagEqual( this.itemStack.getTagCompound(), b.getTagCompound() ) ) + { + return 0; + } + + if( this.itemStack.getTagCompound() == LOW_TAG || b.getTagCompound() == HIGH_TAG ) + { + return -1; + } + if( this.itemStack.getTagCompound() == HIGH_TAG || b.getTagCompound() == LOW_TAG ) + { + return 1; + } + + final int nbt = ( this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound().hashCode() : 0 ) - ( b.hasTagCompound() ? b.getTagCompound() + .hashCode() : 0 ); + if( nbt != 0 ) + { + return nbt; + } + + return System.identityHashCode( this.itemStack.getTagCompound() ) - System.identityHashCode( b.getTagCompound() ); + } + + public AESharedItemStack getLowerBound( final FuzzyMode fuzzy, final boolean ignoreMeta ) + { + Preconditions.checkState( this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1" ); + final ItemStack newDef = this.itemStack.copy(); + + if( ignoreMeta ) + { + newDef.setItemDamage( 0 ); + } + else + { + if( newDef.getItem().isDamageable() ) + { + if( fuzzy == FuzzyMode.IGNORE_ALL ) + { + newDef.setItemDamage( 0 ); + } + else if( fuzzy == FuzzyMode.PERCENT_99 ) + { + if( this.itemStack.getItemDamage() == 0 ) + { + newDef.setItemDamage( 0 ); + } + else + { + newDef.setItemDamage( 0 ); + } + } + else + { + final int breakpoint = fuzzy.calculateBreakPoint( this.itemStack.getMaxDamage() ); + newDef.setItemDamage( breakpoint <= this.itemDamage ? breakpoint : 0 ); + } + } + newDef.setTagCompound( LOW_TAG ); + } + + return new AESharedItemStack( newDef ); + } + + public AESharedItemStack getUpperBound( final FuzzyMode fuzzy, final boolean ignoreMeta ) + { + Preconditions.checkState( this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1" ); + final ItemStack newDef = this.itemStack.copy(); + + if( ignoreMeta ) + { + newDef.setItemDamage( Integer.MAX_VALUE ); + } + else + { + if( newDef.getItem().isDamageable() ) + { + if( fuzzy == FuzzyMode.IGNORE_ALL ) + { + newDef.setItemDamage( this.itemStack.getMaxDamage() + 1 ); + } + else if( fuzzy == FuzzyMode.PERCENT_99 ) + { + if( this.itemStack.getItemDamage() == 0 ) + { + newDef.setItemDamage( 0 ); + } + else + { + newDef.setItemDamage( this.itemStack.getMaxDamage() + 1 ); + } + } + else + { + final int breakpoint = fuzzy.calculateBreakPoint( this.itemStack.getMaxDamage() ); + newDef.setItemDamage( this.itemDamage < breakpoint ? breakpoint - 1 : this.itemStack.getMaxDamage() + 1 ); + } + } + newDef.setTagCompound( HIGH_TAG ); + } + + return new AESharedItemStack( newDef ); + } +} diff --git a/src/main/java/appeng/util/item/AESharedNBT.java b/src/main/java/appeng/util/item/AESharedNBT.java deleted file mode 100644 index ad9cce128..000000000 --- a/src/main/java/appeng/util/item/AESharedNBT.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * 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.item; - - -import java.lang.ref.WeakReference; -import java.util.WeakHashMap; - -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import appeng.api.AEApi; -import appeng.api.features.IItemComparison; -import appeng.api.storage.data.IAETagCompound; -import appeng.util.Platform; - - -/* - * this is used for the shared NBT Cache. - */ -public class AESharedNBT extends NBTTagCompound implements IAETagCompound -{ - - /* - * Shared Tag Compound Cache. - */ - private static final WeakHashMap> SHARED_TAG_COMPOUND = new WeakHashMap<>(); - private final Item item; - private final int meta; - private SharedSearchObject sso; - private int hash; - private IItemComparison comp; - - private AESharedNBT( final Item itemID, final int damageValue ) - { - this.item = itemID; - this.meta = damageValue; - } - - public AESharedNBT( final int fakeValue ) - { - this.item = null; - this.meta = 0; - this.hash = fakeValue; - } - - /* - * Debug purposes. - */ - public static int sharedTagLoad() - { - return SHARED_TAG_COMPOUND.size(); - } - - /* - * Returns an NBT Compound that is used for accelerating comparisons. - */ - static synchronized NBTTagCompound getSharedTagCompound( final NBTTagCompound tagCompound, final ItemStack s ) - { - if( tagCompound.hasNoTags() ) - { - return null; - } - - final Item item = s.getItem(); - int meta = -1; - if( s.getItem() != Items.AIR && s.isItemStackDamageable() && s.getHasSubtypes() ) - { - meta = s.getItemDamage(); - } - - if( isShared( tagCompound ) ) - { - return tagCompound; - } - - final SharedSearchObject sso = new SharedSearchObject( item, meta, tagCompound ); - - final WeakReference c = SHARED_TAG_COMPOUND.get( sso ); - if( c != null ) - { - final SharedSearchObject cg = c.get(); - if( cg != null ) - { - return cg.getShared(); // I don't think I really need to check this - } - // as its already certain to exist.. - } - - final AESharedNBT clone = AESharedNBT.createFromCompound( item, meta, tagCompound ); - sso.setCompound( (NBTTagCompound) sso.getCompound().copy() ); // prevent - // modification - // of data based - // on original - // item. - sso.setShared( clone ); - clone.sso = sso; - - SHARED_TAG_COMPOUND.put( sso, new WeakReference<>( sso ) ); - return clone; - } - - /* - * returns true if the compound is part of the shared compound system ( and can thus be compared directly ). - */ - public static boolean isShared( final NBTTagCompound ta ) - { - return ta instanceof AESharedNBT; - } - - private static AESharedNBT createFromCompound( final Item itemID, final int damageValue, final NBTTagCompound c ) - { - final AESharedNBT x = new AESharedNBT( itemID, damageValue ); - - // c.getTags() - for( final Object o : c.getKeySet() ) - { - final String name = (String) o; - x.setTag( name, c.getTag( name ).copy() ); - } - - x.hash = Platform.itemComparisons().createUnorderedNbtHash( c ); - - final ItemStack isc = new ItemStack( itemID, 1, damageValue ); - isc.setTagCompound( c ); - x.comp = AEApi.instance().registries().specialComparison().getSpecialComparison( isc ); - - return x; - } - - int getHash() - { - return this.hash; - } - - @Override - public NBTTagCompound getNBTTagCompoundCopy() - { - return (NBTTagCompound) this.copy(); - } - - @Override - public IItemComparison getSpecialComparison() - { - return this.comp; - } - - @Override - public boolean equals( final Object par1Obj ) - { - if( par1Obj instanceof AESharedNBT ) - { - return this == par1Obj; - } - return super.equals( par1Obj ); - } - - public boolean matches( final Item item, final int meta, final int orderlessHash ) - { - return item == this.item && this.meta == meta && this.hash == orderlessHash; - } - - public boolean comparePreciseWithRegistry( final AESharedNBT tagCompound ) - { - if( this == tagCompound ) - { - return true; - } - - if( this.comp != null && tagCompound.comp != null ) - { - return this.comp.sameAsPrecise( tagCompound.comp ); - } - - return false; - } - - public boolean compareFuzzyWithRegistry( final AESharedNBT tagCompound ) - { - if( this == tagCompound ) - { - return true; - } - if( tagCompound == null ) - { - return false; - } - - if( this.comp == tagCompound.comp ) - { - return true; - } - - if( this.comp != null ) - { - return this.comp.sameAsFuzzy( tagCompound.comp ); - } - - return false; - } -} diff --git a/src/main/java/appeng/util/item/AEStack.java b/src/main/java/appeng/util/item/AEStack.java index ee1ba6a79..f63fc9b3a 100644 --- a/src/main/java/appeng/util/item/AEStack.java +++ b/src/main/java/appeng/util/item/AEStack.java @@ -26,7 +26,7 @@ import io.netty.buffer.ByteBuf; import appeng.api.storage.data.IAEStack; -public abstract class AEStack implements IAEStack +public abstract class AEStack> implements IAEStack { private boolean isCraftable; @@ -106,6 +106,14 @@ public abstract class AEStack implements IAEStack implements IAEStack implements IAEStack { - private final NavigableMap records = new ConcurrentSkipListMap<>(); + private final NavigableMap records = new ConcurrentSkipListMap<>(); @Override public void add( final IAEItemStack option ) @@ -46,7 +46,7 @@ public final class ItemList implements IItemList return; } - final IAEItemStack st = this.records.get( option ); + final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() ); if( st != null ) { @@ -67,7 +67,7 @@ public final class ItemList implements IItemList return null; } - return this.records.get( itemStack ); + return this.records.get( ( (AEItemStack) itemStack ).getSharedStack() ); } @Override @@ -80,15 +80,13 @@ public final class ItemList implements IItemList final AEItemStack ais = (AEItemStack) filter; - if( ais.isOre() ) + return ais.getOre().map( or -> { - final OreReference or = ais.getDefinition().getIsOre(); - if( or.getAEEquivalents().size() == 1 ) { final IAEItemStack is = or.getAEEquivalents().get( 0 ); - return this.findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ); + return this.findFuzzyDamage( is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ); } else { @@ -96,14 +94,13 @@ public final class ItemList implements IItemList for( final IAEItemStack is : or.getAEEquivalents() ) { - output.addAll( this.findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) ); + output.addAll( this.findFuzzyDamage( is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) ); } return output; } - } - - return this.findFuzzyDamage( ais, fuzzy, false ); + } ) + .orElse( this.findFuzzyDamage( ais, fuzzy, false ) ); } @Override @@ -120,7 +117,7 @@ public final class ItemList implements IItemList return; } - final IAEItemStack st = this.records.get( option ); + final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() ); if( st != null ) { @@ -146,7 +143,7 @@ public final class ItemList implements IItemList return; } - final IAEItemStack st = this.records.get( option ); + final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() ); if( st != null ) { @@ -169,7 +166,7 @@ public final class ItemList implements IItemList return; } - final IAEItemStack st = this.records.get( option ); + final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() ); if( st != null ) { @@ -219,13 +216,14 @@ public final class ItemList implements IItemList private IAEItemStack putItemRecord( final IAEItemStack itemStack ) { - return this.records.put( itemStack, itemStack ); + return this.records.put( ( (AEItemStack) itemStack ).getSharedStack(), itemStack ); } - private Collection findFuzzyDamage( final AEItemStack filter, final FuzzyMode fuzzy, final boolean ignoreMeta ) + private Collection findFuzzyDamage( final IAEItemStack filter, final FuzzyMode fuzzy, final boolean ignoreMeta ) { - final IAEItemStack low = filter.getLow( fuzzy, ignoreMeta ); - final IAEItemStack high = filter.getHigh( fuzzy, ignoreMeta ); + final AEItemStack itemStack = (AEItemStack) filter; + final AESharedItemStack low = itemStack.getSharedStack().getLowerBound( fuzzy, ignoreMeta ); + final AESharedItemStack high = itemStack.getSharedStack().getUpperBound( fuzzy, ignoreMeta ); return this.records.subMap( low, true, high, true ).descendingMap().values(); } diff --git a/src/main/java/appeng/util/item/OreHelper.java b/src/main/java/appeng/util/item/OreHelper.java index a8cde0bdd..ee4836e3f 100644 --- a/src/main/java/appeng/util/item/OreHelper.java +++ b/src/main/java/appeng/util/item/OreHelper.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import com.google.common.cache.CacheBuilder; @@ -63,7 +64,7 @@ public class OreHelper * * @return true if an ore entry exists, false otherwise */ - public OreReference isOre( final ItemStack itemStack ) + public Optional getOre( final ItemStack itemStack ) { final ItemRef ir = new ItemRef( itemStack ); @@ -109,13 +110,13 @@ public class OreHelper } } - return this.references.get( ir ); + return Optional.ofNullable( this.references.get( ir ) ); } boolean sameOre( final AEItemStack aeItemStack, final IAEItemStack is ) { - final OreReference a = aeItemStack.getDefinition().getIsOre(); - final OreReference b = aeItemStack.getDefinition().getIsOre(); + final OreReference a = aeItemStack.getOre().orElse( null ); + final OreReference b = aeItemStack.getOre().orElse( null ); return this.sameOre( a, b ); } @@ -146,24 +147,21 @@ public class OreHelper boolean sameOre( final AEItemStack aeItemStack, final ItemStack o ) { - final OreReference a = aeItemStack.getDefinition().getIsOre(); - if( a == null ) + return aeItemStack.getOre().map( a -> { - return false; - } - - for( final String oreName : a.getEquivalents() ) - { - for( final ItemStack oreItem : this.oreDictCache.getUnchecked( oreName ) ) + for( final String oreName : a.getEquivalents() ) { - if( OreDictionary.itemMatches( oreItem, o, false ) ) + for( final ItemStack oreItem : this.oreDictCache.getUnchecked( oreName ) ) { - return true; + if( OreDictionary.itemMatches( oreItem, o, false ) ) + { + return true; + } } } - } - - return false; + return false; + } ) + .orElse( false ); } List getCachedOres( final String oreName ) diff --git a/src/main/java/appeng/util/item/SharedSearchObject.java b/src/main/java/appeng/util/item/SharedSearchObject.java deleted file mode 100644 index 5e8717b3c..000000000 --- a/src/main/java/appeng/util/item/SharedSearchObject.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.item; - - -import net.minecraft.item.Item; -import net.minecraft.nbt.NBTTagCompound; - -import appeng.util.Platform; - - -public class SharedSearchObject -{ - - private final int def; - private final int hash; - private AESharedNBT shared; - private NBTTagCompound compound; - - public SharedSearchObject( final Item itemID, final int damageValue, final NBTTagCompound tagCompound ) - { - this.def = ( damageValue << Platform.DEF_OFFSET ) | Item.REGISTRY.getIDForObject( itemID ); - this.hash = Platform.itemComparisons().createUnorderedNbtHash( tagCompound ); - this.setCompound( tagCompound ); - } - - @Override - public int hashCode() - { - return this.def ^ this.hash; - } - - @Override - public boolean equals( final Object obj ) - { - if( obj == null ) - { - return false; - } - if( this.getClass() != obj.getClass() ) - { - return false; - } - final SharedSearchObject other = (SharedSearchObject) obj; - if( this.def == other.def && this.hash == other.hash ) - { - return Platform.itemComparisons().isNbtTagEqual( this.getCompound(), other.getCompound() ); - } - return false; - } - - AESharedNBT getShared() - { - return this.shared; - } - - void setShared( final AESharedNBT shared ) - { - this.shared = shared; - } - - NBTTagCompound getCompound() - { - return this.compound; - } - - void setCompound( final NBTTagCompound compound ) - { - this.compound = compound; - } -}