Rework AEItemStack (#3091)
* Use itemstack as itemdef * HIGH_TAG/LOW_TAG should be compared both directions * Remove getTagCompound * Make Itemlist implementation independent * Cache item id for performance reasons * Add preconditions to saveguard against external meddling * Chache itemDamage * Remove IAEStackSearchKey for now, rename getDisplayStack
This commit is contained in:
parent
2ed7a5598a
commit
1e15b23506
75 changed files with 559 additions and 1512 deletions
|
@ -46,7 +46,7 @@ public interface IAEItemStack extends IAEStack<IAEItemStack>
|
|||
*
|
||||
* @return new ItemStack
|
||||
*/
|
||||
ItemStack getItemStack();
|
||||
ItemStack createItemStack();
|
||||
|
||||
/**
|
||||
* is there NBT Data for this item?
|
||||
|
@ -105,4 +105,11 @@ public interface IAEItemStack extends IAEStack<IAEItemStack>
|
|||
* @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();
|
||||
}
|
|
@ -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<StackType extends IAEStack>
|
||||
public interface IAEStack<StackType extends IAEStack<StackType>>
|
||||
{
|
||||
|
||||
/**
|
||||
|
@ -182,13 +183,6 @@ public interface IAEStack<StackType extends 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<StackType extends IAEStack>
|
|||
* @return ITEM or FLUID
|
||||
*/
|
||||
StorageChannel getChannel();
|
||||
|
||||
/**
|
||||
* Returns itemstack for display and similar purposes. Always has a count of 1.
|
||||
*
|
||||
* @return itemstack
|
||||
*/
|
||||
ItemStack asItemStackRepresentation();
|
||||
}
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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++;
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -50,7 +50,6 @@ public class ItemRepo
|
|||
|
||||
private final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
|
||||
private final ArrayList<IAEItemStack> view = new ArrayList<>();
|
||||
private final ArrayList<ItemStack> 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 )
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<ICraftingJob> craftingJob = this.getJob( x );
|
||||
|
||||
|
|
|
@ -334,7 +334,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
|||
|
||||
if( this.outputs != null && this.outputs.length > 0 )
|
||||
{
|
||||
return this.outputs[0].getItemStack();
|
||||
return this.outputs[0].createItemStack();
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
|
|
|
@ -88,12 +88,14 @@ class GrinderRecipeCategory implements IRecipeCategory<GrinderRecipeWrapper>, 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;
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -79,11 +79,11 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>, 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<IAEItemStack>, 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() )
|
||||
|
|
|
@ -51,7 +51,7 @@ public class SecurityStationInventory implements IMEInventoryHandler<IAEItemStac
|
|||
{
|
||||
if( this.hasPermission( src ) )
|
||||
{
|
||||
if( AEApi.instance().definitions().items().biometricCard().isSameAs( input.getItemStack() ) )
|
||||
if( AEApi.instance().definitions().items().biometricCard().isSameAs( input.createItemStack() ) )
|
||||
{
|
||||
if( this.canAccept( input ) )
|
||||
{
|
||||
|
@ -143,7 +143,7 @@ public class SecurityStationInventory implements IMEInventoryHandler<IAEItemStac
|
|||
if( input.getItem() instanceof IBiometricCard )
|
||||
{
|
||||
final IBiometricCard tbc = (IBiometricCard) input.getItem();
|
||||
final GameProfile newUser = tbc.getProfile( input.getItemStack() );
|
||||
final GameProfile newUser = tbc.getProfile( input.createItemStack() );
|
||||
|
||||
final int PlayerID = AEApi.instance().registries().players().getID( newUser );
|
||||
if( this.securityTile.getOwner() == PlayerID )
|
||||
|
@ -155,7 +155,7 @@ public class SecurityStationInventory implements IMEInventoryHandler<IAEItemStac
|
|||
{
|
||||
if( ais.isMeaningful() )
|
||||
{
|
||||
final GameProfile thisUser = tbc.getProfile( ais.getItemStack() );
|
||||
final GameProfile thisUser = tbc.getProfile( ais.createItemStack() );
|
||||
if( thisUser == newUser )
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -393,7 +393,7 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
|
|||
final double y = add.getY();
|
||||
final double z = add.getZ();
|
||||
|
||||
final EntityItem overflowEntity = new EntityItem( w, x, y, z, overflow.getItemStack() );
|
||||
final EntityItem overflowEntity = new EntityItem( w, x, y, z, overflow.createItemStack() );
|
||||
overflowEntity.motionX = 0;
|
||||
overflowEntity.motionY = 0;
|
||||
overflowEntity.motionZ = 0;
|
||||
|
|
|
@ -266,9 +266,9 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest
|
|||
{
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
return AEItemStack.create( d.addItems( items.getItemStack() ) );
|
||||
return AEItemStack.create( d.addItems( items.createItemStack() ) );
|
||||
}
|
||||
return AEItemStack.create( d.simulateAdd( items.getItemStack() ) );
|
||||
return AEItemStack.create( d.simulateAdd( items.createItemStack() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest
|
|||
|
||||
private void pushItemIntoTarget( final InventoryAdaptor d, final IEnergyGrid energy, final IMEInventory<IAEItemStack> 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() );
|
||||
|
|
|
@ -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() );
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -68,7 +68,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
|||
@Override
|
||||
public IAEItemStack injectItems( IAEItemStack iox, Actionable type, IActionSource src )
|
||||
{
|
||||
ItemStack orgInput = iox.getItemStack();
|
||||
ItemStack orgInput = iox.createItemStack();
|
||||
ItemStack remaining = orgInput;
|
||||
|
||||
int slotCount = this.itemHandler.getSlots();
|
||||
|
@ -99,7 +99,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
|||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, IActionSource src )
|
||||
{
|
||||
|
||||
ItemStack requestedItemStack = request.getItemStack();
|
||||
ItemStack requestedItemStack = request.createItemStack();
|
||||
int remainingSize = requestedItemStack.getCount();
|
||||
|
||||
// Use this to gather the requested items
|
||||
|
|
|
@ -160,11 +160,11 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> 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<T extends 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();
|
||||
|
|
|
@ -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<IAEItemStack> 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() )
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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() )
|
||||
{
|
||||
|
|
|
@ -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() )
|
||||
{
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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<String> 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 )
|
||||
|
|
|
@ -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<String> cA = ctA.getKeySet();
|
||||
final Set<String> 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<NBTBase> tag = this.tagList( lA );
|
||||
final List<NBTBase> 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<String> 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<NBTBase> 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<NBTBase> 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<NBTBase>) tagList.get( lB );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
AELog.debug( t );
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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<IAEFluidStack> 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<IAEFluidStack> 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<IAEFluidStack> 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<IAEFluidStack> 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<IAEFluidStack> 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;
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<IAEItemStack> implements IAEItemStack, Comparable<AEItemStack>
|
||||
public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack
|
||||
{
|
||||
private AESharedItemStack sharedStack;
|
||||
private Optional<OreReference> oreReference;
|
||||
|
||||
private AEItemDef def;
|
||||
@SideOnly( Side.CLIENT )
|
||||
private String displayName;
|
||||
@SideOnly( Side.CLIENT )
|
||||
private List<String> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<String> 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<OreReference> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<AESharedItemStack, WeakReference<AESharedItemStack>> 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();
|
||||
}
|
||||
int oldStackSize = itemStack.getCount();
|
||||
itemStack.setCount( 1 );
|
||||
|
||||
AESharedItemStack search = new AESharedItemStack( itemStack );
|
||||
WeakReference<AESharedItemStack> 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;
|
||||
}
|
||||
}
|
216
src/main/java/appeng/util/item/AESharedItemStack.java
Normal file
216
src/main/java/appeng/util/item/AESharedItemStack.java
Normal file
|
@ -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 <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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<AESharedItemStack>
|
||||
{
|
||||
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 );
|
||||
}
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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<SharedSearchObject, WeakReference<SharedSearchObject>> 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<SharedSearchObject> 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;
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ import io.netty.buffer.ByteBuf;
|
|||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
|
||||
public abstract class AEStack<StackType extends IAEStack> implements IAEStack<StackType>
|
||||
public abstract class AEStack<StackType extends IAEStack<StackType>> implements IAEStack<StackType>
|
||||
{
|
||||
|
||||
private boolean isCraftable;
|
||||
|
@ -106,6 +106,14 @@ public abstract class AEStack<StackType extends IAEStack> implements IAEStack<St
|
|||
return (StackType) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType empty()
|
||||
{
|
||||
final StackType dup = this.copy();
|
||||
dup.reset();
|
||||
return dup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMeaningful()
|
||||
{
|
||||
|
@ -144,15 +152,14 @@ public abstract class AEStack<StackType extends IAEStack> implements IAEStack<St
|
|||
|
||||
i.writeByte( mask );
|
||||
|
||||
this.writeIdentity( i );
|
||||
this.writeToStream( i );
|
||||
|
||||
this.readNBT( i );
|
||||
|
||||
// putPacketValue( i, priority );
|
||||
this.putPacketValue( i, this.stackSize );
|
||||
this.putPacketValue( i, this.countRequestable );
|
||||
}
|
||||
|
||||
protected abstract void writeToStream( final ByteBuf data ) throws IOException;
|
||||
|
||||
private byte getType( final long num )
|
||||
{
|
||||
if( num <= 255 )
|
||||
|
@ -175,10 +182,6 @@ public abstract class AEStack<StackType extends IAEStack> implements IAEStack<St
|
|||
|
||||
abstract boolean hasTagCompound();
|
||||
|
||||
abstract void writeIdentity( ByteBuf i ) throws IOException;
|
||||
|
||||
abstract void readNBT( ByteBuf i ) throws IOException;
|
||||
|
||||
private void putPacketValue( final ByteBuf tag, final long num )
|
||||
{
|
||||
if( num <= 255 )
|
||||
|
|
|
@ -36,7 +36,7 @@ import appeng.api.storage.data.IItemList;
|
|||
public final class ItemList implements IItemList<IAEItemStack>
|
||||
{
|
||||
|
||||
private final NavigableMap<IAEItemStack, IAEItemStack> records = new ConcurrentSkipListMap<>();
|
||||
private final NavigableMap<AESharedItemStack, IAEItemStack> records = new ConcurrentSkipListMap<>();
|
||||
|
||||
@Override
|
||||
public void add( final IAEItemStack option )
|
||||
|
@ -46,7 +46,7 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
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<IAEItemStack>
|
|||
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<IAEItemStack>
|
|||
|
||||
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<IAEItemStack>
|
|||
|
||||
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<IAEItemStack>
|
|||
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<IAEItemStack>
|
|||
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<IAEItemStack>
|
|||
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<IAEItemStack>
|
|||
|
||||
private IAEItemStack putItemRecord( final IAEItemStack itemStack )
|
||||
{
|
||||
return this.records.put( itemStack, itemStack );
|
||||
return this.records.put( ( (AEItemStack) itemStack ).getSharedStack(), itemStack );
|
||||
}
|
||||
|
||||
private Collection<IAEItemStack> findFuzzyDamage( final AEItemStack filter, final FuzzyMode fuzzy, final boolean ignoreMeta )
|
||||
private Collection<IAEItemStack> 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();
|
||||
}
|
||||
|
|
|
@ -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<OreReference> 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<ItemStack> getCachedOres( final String oreName )
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue