Use IItemHandler instead of IInventory internally (#2971)

* Use IItemHandler instead of IInventory internally
This commit is contained in:
fscan
2017-07-28 22:04:32 +02:00
committed by yueh
parent c077840988
commit 52d28fabe3
156 changed files with 2410 additions and 4604 deletions
@@ -34,8 +34,6 @@ import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -48,6 +46,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.items.ItemHandlerHelper;
import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.items.MemoryCardMessages;
@@ -56,6 +55,7 @@ import appeng.api.util.AEColor;
import appeng.api.util.IOrientable;
import appeng.block.networking.BlockCableBus;
import appeng.helpers.ICustomCollision;
import appeng.tile.AEBaseInvTile;
import appeng.tile.AEBaseTile;
import appeng.tile.networking.TileCableBus;
import appeng.tile.storage.TileSkyChest;
@@ -115,7 +115,7 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity
public void setTileEntity( final Class<? extends AEBaseTile> c )
{
this.tileEntityType = c;
this.setInventory( IInventory.class.isAssignableFrom( c ) );
this.setInventory( AEBaseInvTile.class.isAssignableFrom( c ) );
}
@Override
@@ -241,9 +241,13 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity
public int getComparatorInputOverride( IBlockState state, final World w, final BlockPos pos )
{
final TileEntity te = this.getTileEntity( w, pos );
if( te instanceof IInventory )
if( te instanceof AEBaseInvTile )
{
return Container.calcRedstoneFromInventory( (IInventory) te );
AEBaseInvTile invTile = (AEBaseInvTile) te;
if( invTile.getInternalInventory().getSlots() > 0 )
{
return ItemHandlerHelper.calcRedstoneFromInventory( invTile.getInternalInventory() );
}
}
return 0;
}
@@ -18,6 +18,7 @@
package appeng.block.crafting;
public class BlockCraftingStorage extends BlockCraftingUnit
{
@@ -109,7 +109,7 @@ public class BlockCharger extends AEBaseTileBlock implements ICustomCollision
{
final TileCharger tc = (TileCharger) tile;
if( AEApi.instance().definitions().materials().certusQuartzCrystalCharged().isSameAs( tc.getStackInSlot( 0 ) ) )
if( AEApi.instance().definitions().materials().certusQuartzCrystalCharged().isSameAs( tc.getInternalInventory().getStackInSlot( 0 ) ) )
{
final double xOff = 0.0;
final double yOff = 0.0;
@@ -201,7 +201,7 @@ public class BlockCharger extends AEBaseTileBlock implements ICustomCollision
{
Matrix4f transform = new Matrix4f();
transform.translate( new Vector3f( 0.5f, 0.4f, 0.5f ) );
return new ImmutablePair<>( tile.getStackInSlot( 0 ), transform );
return new ImmutablePair<>( tile.getInternalInventory().getStackInSlot( 0 ), transform );
}
}
@@ -18,6 +18,7 @@
package appeng.block.networking;
public class BlockDenseEnergyCell extends BlockEnergyCell
{
@@ -108,7 +108,7 @@ public class BlockChest extends AEBaseTileBlock
}
else
{
final ItemStack cell = tg.getStackInSlot( 1 );
final ItemStack cell = tg.getCell();
if( !cell.isEmpty() )
{
final ICellHandler ch = AEApi.instance().registries().cell().getHandler( cell );
@@ -713,7 +713,7 @@ public abstract class AEBaseGui extends GuiContainer
this.itemRender.zLevel = 0.0F;
// Annoying but easier than trying to splice into render item
super.drawSlot( new Size1Slot( s ) );
super.drawSlot( new Size1Slot( (SlotME) s ) );
this.stackSizeRenderer.renderStackSize( this.fontRenderer, ( (SlotME) s ).getAEStack(), s.getStack(), s.xPos, s.yPos );
@@ -13,20 +13,21 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.SlotItemHandler;
/**
* A proxy for a slot that will always return an itemstack with size 1, if there is an item in the slot.
* Used to prevent the default item count from rendering.
*/
class Size1Slot extends Slot
class Size1Slot extends SlotItemHandler
{
private final Slot delegate;
private final SlotItemHandler delegate;
public Size1Slot( Slot delegate )
public Size1Slot( SlotItemHandler delegate )
{
super( delegate.inventory, delegate.getSlotIndex(), delegate.xPos, delegate.yPos );
super( delegate.getItemHandler(), delegate.getSlotIndex(), delegate.xPos, delegate.yPos );
this.delegate = delegate;
}
@@ -25,8 +25,8 @@ import org.lwjgl.input.Mouse;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.ActionItems;
import appeng.api.config.CopyMode;
@@ -137,8 +137,8 @@ public class GuiCellWorkbench extends GuiUpgradeable
this.copyMode.setState( this.workbench.getCopyMode() == CopyMode.CLEAR_ON_REMOVE );
boolean hasFuzzy = false;
final IInventory inv = this.workbench.getCellUpgradeInventory();
for( int x = 0; x < inv.getSizeInventory(); x++ )
final IItemHandler inv = this.workbench.getCellUpgradeInventory();
for( int x = 0; x < inv.getSlots(); x++ )
{
final ItemStack is = inv.getStackInSlot( x );
if( !is.isEmpty() && is.getItem() instanceof IUpgradeModule )
@@ -119,7 +119,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
if( lineObj instanceof ClientDCInternalInv )
{
final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
for( int z = 0; z < inv.getInventory().getSizeInventory(); z++ )
for( int z = 0; z < inv.getInventory().getSlots(); z++ )
{
this.inventorySlots.inventorySlots.add( new SlotDisconnected( inv, z, z * 18 + 8, 1 + offset ) );
}
@@ -175,7 +175,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
GlStateManager.color( 1, 1, 1, 1 );
final int width = inv.getInventory().getSizeInventory() * 18;
final int width = inv.getInventory().getSlots() * 18;
this.drawTexturedModalRect( offsetX + 7, offsetY + offset, 7, 139, width, 18 );
}
offset += 18;
@@ -227,12 +227,12 @@ public class GuiInterfaceTerminal extends AEBaseGui
final NBTTagCompound invData = in.getCompoundTag( key );
final ClientDCInternalInv current = this.getById( id, invData.getLong( "sortBy" ), invData.getString( "un" ) );
for( int x = 0; x < current.getInventory().getSizeInventory(); x++ )
for( int x = 0; x < current.getInventory().getSlots(); x++ )
{
final String which = Integer.toString( x );
if( invData.hasKey( which ) )
{
current.getInventory().setInventorySlotContents( x, new ItemStack( invData.getCompoundTag( which ) ) );
current.getInventory().setStackInSlot( x, new ItemStack( invData.getCompoundTag( which ) ) );
}
}
}
+2 -2
View File
@@ -21,13 +21,13 @@ package appeng.client.me;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.SlotItemHandler;
import appeng.api.storage.data.IAEItemStack;
public class SlotME extends Slot
public class SlotME extends SlotItemHandler
{
private final InternalSlotME mySlot;
@@ -200,7 +200,8 @@ class BiometricCardBakedModel implements IBakedModel
try
{
return BiometricCardBakedModel.this.modelCache.get( hash, () -> new BiometricCardBakedModel( BiometricCardBakedModel.this.format, BiometricCardBakedModel.this.baseModel, BiometricCardBakedModel.this.texture, hash, BiometricCardBakedModel.this.modelCache ) );
return BiometricCardBakedModel.this.modelCache.get( hash,
() -> new BiometricCardBakedModel( BiometricCardBakedModel.this.format, BiometricCardBakedModel.this.baseModel, BiometricCardBakedModel.this.texture, hash, BiometricCardBakedModel.this.modelCache ) );
}
catch( ExecutionException e )
{
@@ -19,6 +19,7 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.items.IItemHandler;
import appeng.api.features.IInscriberRecipe;
import appeng.client.render.FacingToRotation;
@@ -133,16 +134,18 @@ public class InscriberTESR extends TileEntitySpecialRenderer<TileInscriber>
// render items.
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
IItemHandler tileInv = tile.getInternalInventory();
int items = 0;
if( !tile.getStackInSlot( 0 ).isEmpty() )
if( !tileInv.getStackInSlot( 0 ).isEmpty() )
{
items++;
}
if( !tile.getStackInSlot( 1 ).isEmpty() )
if( !tileInv.getStackInSlot( 1 ).isEmpty() )
{
items++;
}
if( !tile.getStackInSlot( 2 ).isEmpty() )
if( !tileInv.getStackInSlot( 2 ).isEmpty() )
{
items++;
}
@@ -151,7 +154,7 @@ public class InscriberTESR extends TileEntitySpecialRenderer<TileInscriber>
if( relativeProgress > 1.0f || items == 0 )
{
ItemStack is = tile.getStackInSlot( 3 );
ItemStack is = tileInv.getStackInSlot( 3 );
if( is.isEmpty() )
{
@@ -166,9 +169,9 @@ public class InscriberTESR extends TileEntitySpecialRenderer<TileInscriber>
}
else
{
this.renderItem( tile.getStackInSlot( 0 ), press, tile, buffer, x, y, z );
this.renderItem( tile.getStackInSlot( 1 ), -press, tile, buffer, x, y, z );
this.renderItem( tile.getStackInSlot( 2 ), 0.0f, tile, buffer, x, y, z );
this.renderItem( tileInv.getStackInSlot( 0 ), press, tile, buffer, x, y, z );
this.renderItem( tileInv.getStackInSlot( 1 ), -press, tile, buffer, x, y, z );
this.renderItem( tileInv.getStackInSlot( 2 ), 0.0f, tile, buffer, x, y, z );
}
// Tessellator.getInstance().draw();
@@ -40,7 +40,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
@@ -78,13 +79,13 @@ import appeng.helpers.ICustomNameObject;
import appeng.helpers.InventoryAction;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorPlayerHand;
import appeng.util.inv.AdaptorItemHandler;
import appeng.util.inv.WrapperCursorItemHandler;
import appeng.util.item.AEItemStack;
public abstract class AEBaseContainer extends Container
{
private final InventoryPlayer invPlayer;
private final BaseActionSource mySrc;
private final HashSet<Integer> locked = new HashSet<>();
@@ -386,6 +387,8 @@ public abstract class AEBaseContainer extends Container
protected void bindPlayerInventory( final InventoryPlayer inventoryPlayer, final int offsetX, final int offsetY )
{
IItemHandler ih = new PlayerInvWrapper( inventoryPlayer );
// bind player inventory
for( int i = 0; i < 3; i++ )
{
@@ -393,11 +396,11 @@ public abstract class AEBaseContainer extends Container
{
if( this.locked.contains( j + i * 9 + 9 ) )
{
this.addSlotToContainer( new SlotDisabled( inventoryPlayer, j + i * 9 + 9, 8 + j * 18 + offsetX, offsetY + i * 18 ) );
this.addSlotToContainer( new SlotDisabled( ih, j + i * 9 + 9, 8 + j * 18 + offsetX, offsetY + i * 18 ) );
}
else
{
this.addSlotToContainer( new SlotPlayerInv( inventoryPlayer, j + i * 9 + 9, 8 + j * 18 + offsetX, offsetY + i * 18 ) );
this.addSlotToContainer( new SlotPlayerInv( ih, j + i * 9 + 9, 8 + j * 18 + offsetX, offsetY + i * 18 ) );
}
}
}
@@ -407,11 +410,11 @@ public abstract class AEBaseContainer extends Container
{
if( this.locked.contains( i ) )
{
this.addSlotToContainer( new SlotDisabled( inventoryPlayer, i, 8 + i * 18 + offsetX, 58 + offsetY ) );
this.addSlotToContainer( new SlotDisabled( ih, i, 8 + i * 18 + offsetX, 58 + offsetY ) );
}
else
{
this.addSlotToContainer( new SlotPlayerHotBar( inventoryPlayer, i, 8 + i * 18 + offsetX, 58 + offsetY ) );
this.addSlotToContainer( new SlotPlayerHotBar( ih, i, 8 + i * 18 + offsetX, 58 + offsetY ) );
}
}
}
@@ -862,7 +865,7 @@ public abstract class AEBaseContainer extends Container
ais.setStackSize( myItem.getMaxStackSize() );
final InventoryAdaptor adp = InventoryAdaptor.getAdaptor( player, EnumFacing.UP );
final InventoryAdaptor adp = InventoryAdaptor.getAdaptor( player );
myItem.setCount( (int) ais.getStackSize() );
myItem = adp.simulateAdd( myItem );
@@ -896,7 +899,7 @@ public abstract class AEBaseContainer extends Container
ais = Platform.poweredInsert( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() );
if( ais == null )
{
final InventoryAdaptor ia = new AdaptorPlayerHand( player );
final InventoryAdaptor ia = new AdaptorItemHandler( new WrapperCursorItemHandler( player.inventory ) );
final ItemStack fail = ia.removeItems( 1, extracted.getItemStack(), null );
if( fail.isEmpty() )
@@ -940,7 +943,7 @@ public abstract class AEBaseContainer extends Container
ais = Platform.poweredExtraction( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() );
if( ais != null )
{
final InventoryAdaptor ia = new AdaptorPlayerHand( player );
final InventoryAdaptor ia = new AdaptorItemHandler( new WrapperCursorItemHandler( player.inventory ) );
final ItemStack fail = ia.addItems( ais.getItemStack() );
if( !fail.isEmpty() )
@@ -1070,7 +1073,7 @@ public abstract class AEBaseContainer extends Container
ais.setStackSize( myItem.getMaxStackSize() );
final InventoryAdaptor adp = InventoryAdaptor.getAdaptor( player, EnumFacing.UP );
final InventoryAdaptor adp = InventoryAdaptor.getAdaptor( player );
myItem.setCount( (int) ais.getStackSize() );
myItem = adp.simulateAdd( myItem );
@@ -21,14 +21,13 @@ package appeng.container.implementations;
import java.util.Iterator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.EmptyHandler;
import appeng.api.AEApi;
import appeng.api.config.CopyMode;
@@ -43,16 +42,16 @@ import appeng.container.guisync.GuiSync;
import appeng.container.slot.OptionalSlotRestrictedInput;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.inventory.AppEngNullInventory;
import appeng.tile.misc.TileCellWorkbench;
import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.WrapperLazyItemHandler;
import appeng.util.iterators.NullIterator;
public class ContainerCellWorkbench extends ContainerUpgradeable
{
private final TileCellWorkbench workBench;
private final AppEngNullInventory nullInventory = new AppEngNullInventory();
@GuiSync( 2 )
public CopyMode copyMode = CopyMode.CLEAR_ON_REMOVE;
private ItemStack prevStack = ItemStack.EMPTY;
@@ -92,11 +91,11 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
@Override
protected void setupConfig()
{
final IInventory cell = this.getUpgradeable().getInventoryByName( "cell" );
final IItemHandler cell = this.getUpgradeable().getInventoryByName( "cell" );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.WORKBENCH_CELL, cell, 0, 152, 8, this.getPlayerInv() ) );
final IInventory inv = this.getUpgradeable().getInventoryByName( "config" );
final IInventory upgradeInventory = new Upgrades();
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
final WrapperLazyItemHandler upgradeInventory = new WrapperLazyItemHandler( this::getCellUpgradeInventory );
// null, 3 * 8 );
int offset = 0;
@@ -138,7 +137,7 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
if( this.prevStack != is )
{
this.prevStack = is;
this.lastUpgrades = this.getCellUpgradeInventory().getSizeInventory();
this.lastUpgrades = this.getCellUpgradeInventory().getSlots();
}
return this.lastUpgrades;
}
@@ -189,11 +188,11 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
return idx < this.availableUpgrades();
}
public IInventory getCellUpgradeInventory()
public IItemHandler getCellUpgradeInventory()
{
final IInventory upgradeInventory = this.workBench.getCellUpgradeInventory();
final IItemHandler upgradeInventory = this.workBench.getCellUpgradeInventory();
return upgradeInventory == null ? this.nullInventory : upgradeInventory;
return upgradeInventory == null ? EmptyHandler.INSTANCE : upgradeInventory;
}
@Override
@@ -209,11 +208,7 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
public void clear()
{
final IInventory inv = this.getUpgradeable().getInventoryByName( "config" );
for( int x = 0; x < inv.getSizeInventory(); x++ )
{
inv.setInventorySlotContents( x, ItemStack.EMPTY );
}
ItemHandlerUtil.clear( this.getUpgradeable().getInventoryByName( "config" ) );
this.detectAndSendChanges();
}
@@ -229,7 +224,7 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
public void partition()
{
final IInventory inv = this.getUpgradeable().getInventoryByName( "config" );
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
final IMEInventory<IAEItemStack> cellInv = AEApi.instance().registries().cell().getCellInventory(
this.getUpgradeable().getInventoryByName( "cell" ).getStackInSlot( 0 ), null, StorageChannel.ITEMS );
@@ -241,17 +236,17 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
i = list.iterator();
}
for( int x = 0; x < inv.getSizeInventory(); x++ )
for( int x = 0; x < inv.getSlots(); x++ )
{
if( i.hasNext() )
{
final ItemStack g = i.next().getItemStack();
g.setCount( 1 );
inv.setInventorySlotContents( x, g );
ItemHandlerUtil.setStackInSlot( inv, x, g );
}
else
{
inv.setInventorySlotContents( x, ItemStack.EMPTY );
ItemHandlerUtil.setStackInSlot( inv, x, ItemStack.EMPTY );
}
}
@@ -267,131 +262,4 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
{
this.copyMode = copyMode;
}
private class Upgrades implements IInventory
{
@Override
public int getSizeInventory()
{
return ContainerCellWorkbench.this.getCellUpgradeInventory().getSizeInventory();
}
@Override
public ItemStack getStackInSlot( final int i )
{
return ContainerCellWorkbench.this.getCellUpgradeInventory().getStackInSlot( i );
}
@Override
public ItemStack decrStackSize( final int i, final int j )
{
final IInventory inv = ContainerCellWorkbench.this.getCellUpgradeInventory();
final ItemStack is = inv.decrStackSize( i, j );
inv.markDirty();
return is;
}
@Override
public ItemStack removeStackFromSlot( final int i )
{
final IInventory inv = ContainerCellWorkbench.this.getCellUpgradeInventory();
final ItemStack is = inv.removeStackFromSlot( i );
inv.markDirty();
return is;
}
@Override
public void setInventorySlotContents( final int i, final ItemStack itemstack )
{
final IInventory inv = ContainerCellWorkbench.this.getCellUpgradeInventory();
inv.setInventorySlotContents( i, itemstack );
inv.markDirty();
}
@Override
public String getName()
{
return "Upgrades";
}
@Override
public boolean hasCustomName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public void markDirty()
{
}
@Override
public boolean isUsableByPlayer( EntityPlayer player )
{
return false;
}
@Override
public void openInventory( final EntityPlayer player )
{
}
@Override
public void closeInventory( final EntityPlayer player )
{
}
@Override
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
{
return ContainerCellWorkbench.this.getCellUpgradeInventory().isItemValidForSlot( i, itemstack );
}
@Override
public ITextComponent getDisplayName()
{
return null;
}
@Override
public int getField( final int id )
{
return 0;
}
@Override
public void setField( final int id, final int value )
{
}
@Override
public int getFieldCount()
{
return 0;
}
@Override
public void clear()
{
ContainerCellWorkbench.this.getCellUpgradeInventory().clear();
}
@Override
public boolean isEmpty()
{
// TODO Auto-generated method stub
return false;
}
}
}
}
@@ -36,8 +36,8 @@ public class ContainerChest extends AEBaseContainer
super( ip, chest, null );
this.chest = chest;
this.addSlotToContainer(
new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, this.chest, 1, 80, 37, this.getInventoryPlayer() ) );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, this.chest.getInternalInventory(), 1, 80, 37, this
.getInventoryPlayer() ) );
this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 );
}
@@ -20,6 +20,7 @@ package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.CondenserOutput;
import appeng.api.config.Settings;
@@ -48,11 +49,12 @@ public class ContainerCondenser extends AEBaseContainer implements IProgressProv
super( ip, condenser, null );
this.condenser = condenser;
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.TRASH, condenser, 0, 51, 52, ip ) );
this.addSlotToContainer( new SlotOutput( condenser, 1, 105, 52, -1 ) );
IItemHandler inv = condenser.getInternalInventory();
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.TRASH, inv, 0, 51, 52, ip ) );
this.addSlotToContainer( new SlotOutput( inv, 1, 105, 52, -1 ) );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_COMPONENT, condenser.getInternalInventory(), 2, 101, 26, ip ) )
.setStackLimit( 1 ) );
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_COMPONENT, inv, 2, 101, 26, ip ) ).setStackLimit( 1 ) );
this.bindPlayerInventory( ip, 0, 197 - /* height of player inventory */82 );
}
@@ -24,6 +24,8 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
import appeng.api.storage.ITerminalHost;
import appeng.container.ContainerNull;
@@ -32,8 +34,9 @@ import appeng.container.slot.SlotCraftingTerm;
import appeng.helpers.IContainerCraftingPacket;
import appeng.parts.reporting.PartCraftingTerminal;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.inv.WrapperInvItemHandler;
public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IContainerCraftingPacket
@@ -49,7 +52,7 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE
super( ip, monitorable, false );
this.ct = (PartCraftingTerminal) monitorable;
final IInventory crafting = this.ct.getInventoryByName( "crafting" );
final IItemHandler crafting = this.ct.getInventoryByName( "crafting" );
for( int y = 0; y < 3; y++ )
{
@@ -64,14 +67,15 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE
this.bindPlayerInventory( ip, 0, 0 );
this.onCraftMatrixChanged( crafting );
this.onCraftMatrixChanged( new WrapperInvItemHandler( crafting ) );
}
/**
* Callback for when the crafting matrix is changed.
*/
@Override
public void onCraftMatrixChanged( final IInventory par1IInventory )
public void onCraftMatrixChanged( IInventory inventory )
{
final ContainerNull cn = new ContainerNull();
final InventoryCrafting ic = new InventoryCrafting( cn, 3, 3 );
@@ -82,6 +86,7 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE
}
this.outputSlot.putStack( CraftingManager.findMatchingResult( ic, this.getPlayerInv().player.world ) );
super.onCraftMatrixChanged( inventory );
}
@Override
@@ -91,17 +96,17 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "player" ) )
{
return this.getInventoryPlayer();
return new PlayerInvWrapper( this.getInventoryPlayer() );
}
return this.ct.getInventoryByName( name );
}
@@ -37,9 +37,8 @@ public class ContainerDrive extends AEBaseContainer
{
for( int x = 0; x < 2; x++ )
{
this.addSlotToContainer(
new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, drive, x + y * 2, 71 + x * 18, 14 + y * 18, this
.getInventoryPlayer() ) );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, drive
.getInternalInventory(), x + y * 2, 71 + x * 18, 14 + y * 18, this.getInventoryPlayer() ) );
}
}
@@ -20,7 +20,7 @@ package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.FuzzyMode;
import appeng.api.config.SecurityPermissions;
@@ -58,7 +58,7 @@ public class ContainerFormationPlane extends ContainerUpgradeable
final int xo = 8;
final int yo = 23 + 6;
final IInventory config = this.getUpgradeable().getInventoryByName( "config" );
final IItemHandler config = this.getUpgradeable().getInventoryByName( "config" );
for( int y = 0; y < 7; y++ )
{
for( int x = 0; x < 9; x++ )
@@ -74,7 +74,7 @@ public class ContainerFormationPlane extends ContainerUpgradeable
}
}
final IInventory upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
@@ -20,6 +20,7 @@ package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.items.IItemHandler;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotInaccessible;
@@ -35,15 +36,17 @@ public class ContainerGrinder extends AEBaseContainer
{
super( ip, grinder, null );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, grinder, 0, 12, 17, this.getInventoryPlayer() ) );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, grinder, 1, 12 + 18, 17, this.getInventoryPlayer() ) );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, grinder, 2, 12 + 36, 17, this.getInventoryPlayer() ) );
IItemHandler inv = grinder.getInternalInventory();
this.addSlotToContainer( new SlotInaccessible( grinder, 6, 80, 40 ) );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, inv, 0, 12, 17, this.getInventoryPlayer() ) );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, inv, 1, 12 + 18, 17, this.getInventoryPlayer() ) );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, inv, 2, 12 + 36, 17, this.getInventoryPlayer() ) );
this.addSlotToContainer( new SlotOutput( grinder, 3, 112, 63, 2 * 16 + 15 ) );
this.addSlotToContainer( new SlotOutput( grinder, 4, 112 + 18, 63, 2 * 16 + 15 ) );
this.addSlotToContainer( new SlotOutput( grinder, 5, 112 + 36, 63, 2 * 16 + 15 ) );
this.addSlotToContainer( new SlotInaccessible( inv, 6, 80, 40 ) );
this.addSlotToContainer( new SlotOutput( inv, 3, 112, 63, 2 * 16 + 15 ) );
this.addSlotToContainer( new SlotOutput( inv, 4, 112 + 18, 63, 2 * 16 + 15 ) );
this.addSlotToContainer( new SlotOutput( inv, 5, 112 + 36, 63, 2 * 16 + 15 ) );
this.bindPlayerInventory( ip, 0, 176 - /* height of player inventory */82 );
}
@@ -20,7 +20,7 @@ package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.FullnessMode;
import appeng.api.config.OperationMode;
@@ -59,7 +59,7 @@ public class ContainerIOPort extends ContainerUpgradeable
int offX = 19;
int offY = 17;
final IInventory cells = this.getUpgradeable().getInventoryByName( "cells" );
final IItemHandler cells = this.getUpgradeable().getInventoryByName( "cells" );
for( int y = 0; y < 3; y++ )
{
@@ -82,7 +82,7 @@ public class ContainerIOPort extends ContainerUpgradeable
}
}
final IInventory upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
@@ -22,6 +22,7 @@ package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.definitions.IItemDefinition;
@@ -60,14 +61,16 @@ public class ContainerInscriber extends ContainerUpgradeable implements IProgres
super( ip, te );
this.ti = te;
this.addSlotToContainer(
this.top = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, this.ti, 0, 45, 16, this.getInventoryPlayer() ) );
this.addSlotToContainer(
this.bottom = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, this.ti, 1, 45, 62, this.getInventoryPlayer() ) );
this.addSlotToContainer(
this.middle = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_INPUT, this.ti, 2, 63, 39, this.getInventoryPlayer() ) );
IItemHandler inv = te.getInternalInventory();
this.addSlotToContainer( new SlotOutput( this.ti, 3, 113, 40, -1 ) );
this.addSlotToContainer(
this.top = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, inv, 0, 45, 16, this.getInventoryPlayer() ) );
this.addSlotToContainer(
this.bottom = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, inv, 1, 45, 62, this.getInventoryPlayer() ) );
this.addSlotToContainer(
this.middle = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_INPUT, inv, 2, 63, 39, this.getInventoryPlayer() ) );
this.addSlotToContainer( new SlotOutput( inv, 3, 113, 40, -1 ) );
}
@Override
@@ -112,8 +115,8 @@ public class ContainerInscriber extends ContainerUpgradeable implements IProgres
@Override
public boolean isValidForSlot( final Slot s, final ItemStack is )
{
final ItemStack top = this.ti.getStackInSlot( 0 );
final ItemStack bot = this.ti.getStackInSlot( 1 );
final ItemStack top = this.ti.getInternalInventory().getStackInSlot( 0 );
final ItemStack bot = this.ti.getInternalInventory().getStackInSlot( 1 );
if( s == this.middle )
{
@@ -132,12 +135,12 @@ public class ContainerInscriber extends ContainerUpgradeable implements IProgres
{
final boolean matchA = ( top.isEmpty() && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( top,
recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) ) && // and...
( bot.isEmpty() && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( bot,
( bot.isEmpty() && !recipe.getBottomOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( bot,
recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) );
final boolean matchB = ( bot.isEmpty() && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( bot,
recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) ) && // and...
( top.isEmpty() && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( top,
( top.isEmpty() && !recipe.getBottomOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( top,
recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) );
if( matchA || matchB )
@@ -26,10 +26,9 @@ import java.util.Map.Entry;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
@@ -49,9 +48,11 @@ import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.misc.TileInterface;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorIInventory;
import appeng.util.inv.AdaptorPlayerHand;
import appeng.util.inv.WrapperInvSlot;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.AdaptorItemHandler;
import appeng.util.inv.WrapperFilteredItemHandler;
import appeng.util.inv.WrapperRangeItemHandler;
import appeng.util.inv.filter.IAEItemFilter;
public final class ContainerInterfaceTerminal extends AEBaseContainer
@@ -172,7 +173,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
for( final Entry<IInterfaceHost, InvTracker> en : this.diList.entrySet() )
{
final InvTracker inv = en.getValue();
for( int x = 0; x < inv.server.getSizeInventory(); x++ )
for( int x = 0; x < inv.server.getSlots(); x++ )
{
if( this.isDifferent( inv.server.getStackInSlot( x ), inv.client.getStackInSlot( x ) ) )
{
@@ -206,12 +207,10 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
final ItemStack is = inv.server.getStackInSlot( slot );
final boolean hasItemInHand = !player.inventory.getItemStack().isEmpty();
final InventoryAdaptor playerHand = new AdaptorPlayerHand( player );
final InventoryAdaptor playerHand = InventoryAdaptor.getAdaptor( player );
final WrapperInvSlot slotInv = new PatternInvSlot( inv.server );
final IInventory theSlot = slotInv.getWrapper( slot );
final InventoryAdaptor interfaceSlot = new AdaptorIInventory( theSlot );
final IItemHandler theSlot = new WrapperFilteredItemHandler( new WrapperRangeItemHandler( inv.server, slot, slot + 1 ), new PatternSlotFilter() );
final InventoryAdaptor interfaceSlot = new AdaptorItemHandler( theSlot );
switch( action )
{
@@ -229,7 +228,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
inSlot = inSlot.copy();
final ItemStack inHand = player.inventory.getItemStack().copy();
theSlot.setInventorySlotContents( 0, ItemStack.EMPTY );
ItemHandlerUtil.setStackInSlot( theSlot, 0, ItemStack.EMPTY );
player.inventory.setItemStack( ItemStack.EMPTY );
player.inventory.setItemStack( interfaceSlot.addItems( inHand.copy() ) );
@@ -241,14 +240,13 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
else
{
player.inventory.setItemStack( inHand );
theSlot.setInventorySlotContents( 0, inSlot );
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot );
}
}
}
else
{
final IInventory mySlot = slotInv.getWrapper( slot );
mySlot.setInventorySlotContents( 0, playerHand.addItems( mySlot.getStackInSlot( 0 ) ) );
ItemHandlerUtil.setStackInSlot( theSlot, 0, playerHand.addItems( theSlot.getStackInSlot( 0 ) ) );
}
break;
@@ -282,17 +280,17 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
break;
case SHIFT_CLICK:
final IInventory mySlot = slotInv.getWrapper( slot );
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( player, EnumFacing.UP );
mySlot.setInventorySlotContents( 0, playerInv.addItems( mySlot.getStackInSlot( 0 ) ) );
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( player );
ItemHandlerUtil.setStackInSlot( theSlot, 0, playerInv.addItems( theSlot.getStackInSlot( 0 ) ) );
break;
case MOVE_REGION:
final InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor( player, EnumFacing.UP );
for( int x = 0; x < inv.server.getSizeInventory(); x++ )
final InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor( player );
for( int x = 0; x < inv.server.getSlots(); x++ )
{
inv.server.setInventorySlotContents( x, playerInvAd.addItems( inv.server.getStackInSlot( x ) ) );
ItemHandlerUtil.setStackInSlot( inv.server, x, playerInvAd.addItems( inv.server.getStackInSlot( x ) ) );
}
break;
@@ -351,7 +349,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
{
final InvTracker inv = en.getValue();
this.byId.put( inv.which, inv );
this.addItems( data, inv, 0, inv.server.getSizeInventory() );
this.addItems( data, inv, 0, inv.server.getSlots() );
}
}
@@ -388,7 +386,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
final ItemStack is = inv.server.getStackInSlot( x + offset );
// "update" client side.
inv.client.setInventorySlotContents( x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy() );
ItemHandlerUtil.setStackInSlot( inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy() );
if( !is.isEmpty() )
{
@@ -407,30 +405,30 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
private final long sortBy;
private final long which = autoBase++;
private final String unlocalizedName;
private final IInventory client;
private final IInventory server;
private final IItemHandler client;
private final IItemHandler server;
public InvTracker( final DualityInterface dual, final IInventory patterns, final String unlocalizedName )
public InvTracker( final DualityInterface dual, final IItemHandler patterns, final String unlocalizedName )
{
this.server = patterns;
this.client = new AppEngInternalInventory( null, this.server.getSizeInventory() );
this.client = new AppEngInternalInventory( null, this.server.getSlots() );
this.unlocalizedName = unlocalizedName;
this.sortBy = dual.getSortValue();
}
}
private static class PatternInvSlot extends WrapperInvSlot
private static class PatternSlotFilter implements IAEItemFilter
{
public PatternInvSlot( final IInventory inv )
@Override
public boolean allowExtract( IItemHandler inv, int slot, int amount )
{
super( inv );
return true;
}
@Override
public boolean isItemValid( final ItemStack itemstack )
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
{
return !itemstack.isEmpty() && itemstack.getItem() instanceof ItemEncodedPattern;
return !stack.isEmpty() && stack.getItem() instanceof ItemEncodedPattern;
}
}
}
@@ -22,9 +22,9 @@ package appeng.container.implementations;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.FuzzyMode;
import appeng.api.config.LevelType;
@@ -75,7 +75,7 @@ public class ContainerLevelEmitter extends ContainerUpgradeable
@Override
protected void setupConfig()
{
final IInventory upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
if( this.availableUpgrades() > 0 )
{
this.addSlotToContainer(
@@ -101,7 +101,7 @@ public class ContainerLevelEmitter extends ContainerUpgradeable
.setNotDraggable() );
}
final IInventory inv = this.getUpgradeable().getInventoryByName( "config" );
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
final int y = 40;
final int x = 80 + 44;
this.addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) );
@@ -20,9 +20,9 @@ package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
@@ -54,7 +54,7 @@ public class ContainerMAC extends ContainerUpgradeable implements IProgressProvi
public boolean isValidItemForSlot( final int slotIndex, final ItemStack i )
{
final IInventory mac = this.getUpgradeable().getInventoryByName( "mac" );
final IItemHandler mac = this.getUpgradeable().getInventoryByName( "mac" );
final ItemStack is = mac.getStackInSlot( 10 );
if( is.isEmpty() )
@@ -88,7 +88,7 @@ public class ContainerMAC extends ContainerUpgradeable implements IProgressProvi
int offX = 29;
int offY = 30;
final IInventory mac = this.getUpgradeable().getInventoryByName( "mac" );
final IItemHandler mac = this.getUpgradeable().getInventoryByName( "mac" );
for( int y = 0; y < 3; y++ )
{
@@ -109,7 +109,7 @@ public class ContainerMAC extends ContainerUpgradeable implements IProgressProvi
offX = 122;
offY = 17;
final IInventory upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
@@ -49,9 +49,8 @@ public class ContainerNetworkTool extends AEBaseContainer
{
for( int x = 0; x < 3; x++ )
{
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, te, y * 3 + x, 80 - 18 + x * 18, 37 - 18 + y * 18, this
.getInventoryPlayer() ) ) );
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, te
.getInventory(), y * 3 + x, 80 - 18 + x * 18, 37 - 18 + y * 18, this.getInventoryPlayer() ) ) );
}
}
@@ -27,7 +27,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
@@ -38,7 +37,8 @@ import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
@@ -61,11 +61,12 @@ import appeng.helpers.IContainerCraftingPacket;
import appeng.items.storage.ItemViewCell;
import appeng.parts.reporting.PartPatternTerminal;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorPlayerHand;
import appeng.util.inv.AdaptorItemHandler;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.inv.WrapperCursorItemHandler;
import appeng.util.item.AEItemStack;
@@ -74,7 +75,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
private final PartPatternTerminal patternTerminal;
private final AppEngInternalInventory cOut = new AppEngInternalInventory( null, 1 );
private final IInventory crafting;
private final IItemHandler crafting;
private final SlotFakeCraftingMatrix[] craftingSlots = new SlotFakeCraftingMatrix[9];
private final OptionalSlotFake[] outputSlots = new OptionalSlotFake[3];
private final SlotPatternTerm craftSlot;
@@ -90,8 +91,8 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
super( ip, monitorable, false );
this.patternTerminal = (PartPatternTerminal) monitorable;
final IInventory patternInv = this.getPatternTerminal().getInventoryByName( "pattern" );
final IInventory output = this.getPatternTerminal().getInventoryByName( "output" );
final IItemHandler patternInv = this.getPatternTerminal().getInventoryByName( "pattern" );
final IItemHandler output = this.getPatternTerminal().getInventoryByName( "output" );
this.crafting = this.getPatternTerminal().getInventoryByName( "crafting" );
@@ -166,7 +167,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
}
final ItemStack is = CraftingManager.findMatchingResult( ic, this.getPlayerInv().player.world );
this.cOut.setInventorySlotContents( 0, is );
this.cOut.setStackInSlot( 0, is );
return is;
}
@@ -177,7 +178,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
}
@@ -355,8 +356,8 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
if( packetPatternSlot.slotItem != null && this.getCellInventory() != null )
{
final IAEItemStack out = packetPatternSlot.slotItem.copy();
InventoryAdaptor inv = new AdaptorPlayerHand( this.getPlayerInv().player );
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( this.getPlayerInv().player, EnumFacing.UP );
InventoryAdaptor inv = new AdaptorItemHandler( new WrapperCursorItemHandler( this.getPlayerInv().player.inventory ) );
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( this.getPlayerInv().player );
if( packetPatternSlot.shift )
{
@@ -527,11 +528,11 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "player" ) )
{
return this.getInventoryPlayer();
return new PlayerInvWrapper( this.getInventoryPlayer() );
}
return this.getPatternTerminal().getInventoryByName( name );
}
@@ -33,9 +33,8 @@ public class ContainerQNB extends AEBaseContainer
{
super( ip, quantumBridge, null );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, quantumBridge, 0, 80, 37, this.getInventoryPlayer() ) )
.setStackLimit( 1 ) );
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, quantumBridge
.getInternalInventory(), 0, 80, 37, this.getInventoryPlayer() ) ).setStackLimit( 1 ) );
this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 );
}
@@ -19,34 +19,31 @@
package appeng.container.implementations;
import javax.annotation.Nonnull;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.container.AEBaseContainer;
import appeng.container.slot.QuartzKnifeOutput;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.items.contents.QuartzKnifeObj;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
public class ContainerQuartzKnife extends AEBaseContainer implements IAEAppEngInventory, IInventory
public class ContainerQuartzKnife extends AEBaseContainer
{
private final QuartzKnifeObj toolInv;
private final AppEngInternalInventory inSlot = new AppEngInternalInventory( this, 1 );
private final SlotRestrictedInput metals;
private final QuartzKnifeOutput output;
private final IItemHandler inSlot = new AppEngInternalInventory( null, 1, 1 );
private String myName = "";
public ContainerQuartzKnife( final InventoryPlayer ip, final QuartzKnifeObj te )
@@ -54,11 +51,8 @@ public class ContainerQuartzKnife extends AEBaseContainer implements IAEAppEngIn
super( ip, null, null );
this.toolInv = te;
this.metals = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.METAL_INGOTS, this.inSlot, 0, 94, 44, ip );
this.addSlotToContainer( this.metals );
this.output = new QuartzKnifeOutput( this, 0, 134, 44, -1 );
this.addSlotToContainer( this.output );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.METAL_INGOTS, this.inSlot, 0, 94, 44, ip ) );
this.addSlotToContainer( new QuartzKniveSlot( this.inSlot, 0, 134, 44, -1 ) );
this.lockPlayerInventorySlot( ip.currentItem );
@@ -106,179 +100,73 @@ public class ContainerQuartzKnife extends AEBaseContainer implements IAEAppEngIn
}
}
@Override
public void saveChanges()
private class QuartzKniveSlot extends SlotOutput
{
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
}
@Override
public int getSizeInventory()
{
return 1;
}
@Override
public ItemStack getStackInSlot( final int var1 )
{
final ItemStack input = this.inSlot.getStackInSlot( 0 );
if( input == ItemStack.EMPTY )
QuartzKniveSlot( IItemHandler a, int b, int c, int d, int i )
{
super( a, b, c, d, i );
}
@Override
public ItemStack getStack()
{
final IItemHandler baseInv = getItemHandler();
final ItemStack input = baseInv.getStackInSlot( 0 );
if( input == ItemStack.EMPTY )
{
return ItemStack.EMPTY;
}
if( SlotRestrictedInput.isMetalIngot( input ) )
{
if( ContainerQuartzKnife.this.myName.length() > 0 )
{
return AEApi.instance().definitions().materials().namePress().maybeStack( 1 ).map( namePressStack ->
{
final NBTTagCompound compound = Platform.openNbtData( namePressStack );
compound.setString( "InscribeName", ContainerQuartzKnife.this.myName );
return namePressStack;
} ).orElse( ItemStack.EMPTY );
}
}
return ItemStack.EMPTY;
}
if( SlotRestrictedInput.isMetalIngot( input ) )
@Override
@Nonnull
public ItemStack decrStackSize( int amount )
{
if( this.myName.length() > 0 )
ItemStack ret = getStack();
if( !ret.isEmpty() )
{
return AEApi.instance().definitions().materials().namePress().maybeStack( 1 ).map( namePressStack ->
makePlate();
}
return ret;
}
@Override
public void putStack( final ItemStack stack )
{
if( stack.isEmpty() )
{
makePlate();
}
}
private void makePlate()
{
if( !getItemHandler().extractItem( 0, 1, false ).isEmpty() )
{
final ItemStack item = ContainerQuartzKnife.this.toolInv.getItemStack();
item.damageItem( 1, getPlayerInv().player );
if( item.getCount() == 0 )
{
final NBTTagCompound compound = Platform.openNbtData( namePressStack );
compound.setString( "InscribeName", this.myName );
return namePressStack;
} ).orElse( ItemStack.EMPTY );
getPlayerInv().mainInventory.add( getPlayerInv().currentItem, ItemStack.EMPTY );
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( getPlayerInv().player, item, null ) );
}
}
}
return ItemStack.EMPTY;
}
@Override
public ItemStack decrStackSize( final int var1, final int var2 )
{
final ItemStack is = this.getStackInSlot( 0 );
if( !is.isEmpty() )
{
if( this.makePlate() )
{
return is;
}
}
return ItemStack.EMPTY;
}
private boolean makePlate()
{
if( this.inSlot.decrStackSize( 0, 1 ) != null )
{
final ItemStack item = this.toolInv.getItemStack();
item.damageItem( 1, this.getPlayerInv().player );
if( item.getCount() == 0 )
{
this.getPlayerInv().mainInventory.add( this.getPlayerInv().currentItem, ItemStack.EMPTY );
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( this.getPlayerInv().player, item, null ) );
}
return true;
}
return false;
}
@Override
public ItemStack removeStackFromSlot( final int var1 )
{
return ItemStack.EMPTY;
}
@Override
public void setInventorySlotContents( final int var1, final ItemStack var2 )
{
if( var2.isEmpty() && Platform.isServer() )
{
this.makePlate();
}
}
@Override
public String getName()
{
return "Quartz Knife Output";
}
@Override
public boolean hasCustomName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public void markDirty()
{
}
@Override
public boolean isUsableByPlayer( EntityPlayer player )
{
return false;
}
@Override
public void openInventory( final EntityPlayer player )
{
}
@Override
public void closeInventory( final EntityPlayer player )
{
}
@Override
public boolean isItemValidForSlot( final int var1, final ItemStack var2 )
{
return false;
}
@Override
public ITextComponent getDisplayName()
{
return null;
}
@Override
public int getField( final int id )
{
return 0;
}
@Override
public void setField( final int id, final int value )
{
}
@Override
public int getFieldCount()
{
return 0;
}
@Override
public void clear()
{
this.inSlot.setInventorySlotContents( 0, ItemStack.EMPTY );
}
@Override
public boolean isEmpty()
{
// TODO Auto-generated method stub
return false;
}
}
@@ -22,8 +22,8 @@ package appeng.container.implementations;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
@@ -35,9 +35,9 @@ import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.tile.misc.TileSecurityStation;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
public class ContainerSecurityStation extends ContainerMEMonitorable implements IAEAppEngInventory
@@ -142,7 +142,7 @@ public class ContainerSecurityStation extends ContainerMEMonitorable implements
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
if( !this.wirelessOut.getHasStack() )
{
@@ -41,7 +41,7 @@ public class ContainerSkyChest extends AEBaseContainer
{
for( int x = 0; x < 9; x++ )
{
this.addSlotToContainer( new SlotNormal( this.chest, y * 9 + x, 8 + 18 * x, 24 + 18 * y ) );
this.addSlotToContainer( new SlotNormal( this.chest.getInternalInventory(), y * 9 + x, 8 + 18 * x, 24 + 18 * y ) );
}
}
@@ -57,9 +57,10 @@ public class ContainerSpatialIOPort extends AEBaseContainer
this.network = spatialIOPort.getGridNode( AEPartLocation.INTERNAL ).getGrid();
}
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS, spatialIOPort
.getInternalInventory(), 0, 52, 48, this.getInventoryPlayer() ) );
this.addSlotToContainer(
new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS, spatialIOPort, 0, 52, 48, this.getInventoryPlayer() ) );
this.addSlotToContainer( new SlotOutput( spatialIOPort, 1, 113, 48, SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS.IIcon ) );
new SlotOutput( spatialIOPort.getInternalInventory(), 1, 113, 48, SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS.IIcon ) );
this.bindPlayerInventory( ip, 0, 197 - /* height of player inventory */82 );
}
@@ -22,8 +22,8 @@ package appeng.container.implementations;
import java.util.Iterator;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
@@ -41,6 +41,7 @@ import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.parts.misc.PartStorageBus;
import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.iterators.NullIterator;
@@ -73,7 +74,7 @@ public class ContainerStorageBus extends ContainerUpgradeable
final int xo = 8;
final int yo = 23 + 6;
final IInventory config = this.getUpgradeable().getInventoryByName( "config" );
final IItemHandler config = this.getUpgradeable().getInventoryByName( "config" );
for( int y = 0; y < 7; y++ )
{
for( int x = 0; x < 9; x++ )
@@ -89,7 +90,7 @@ public class ContainerStorageBus extends ContainerUpgradeable
}
}
final IInventory upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
@@ -143,17 +144,13 @@ public class ContainerStorageBus extends ContainerUpgradeable
public void clear()
{
final IInventory inv = this.getUpgradeable().getInventoryByName( "config" );
for( int x = 0; x < inv.getSizeInventory(); x++ )
{
inv.setInventorySlotContents( x, ItemStack.EMPTY );
}
ItemHandlerUtil.clear( this.getUpgradeable().getInventoryByName( "config" ) );
this.detectAndSendChanges();
}
public void partition()
{
final IInventory inv = this.getUpgradeable().getInventoryByName( "config" );
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
final IMEInventory<IAEItemStack> cellInv = this.storageBus.getInternalHandler();
@@ -164,17 +161,17 @@ public class ContainerStorageBus extends ContainerUpgradeable
i = list.iterator();
}
for( int x = 0; x < inv.getSizeInventory(); x++ )
for( int x = 0; x < inv.getSlots(); x++ )
{
if( i.hasNext() && this.isSlotEnabled( ( x / 9 ) - 2 ) )
{
final ItemStack g = i.next().getItemStack();
g.setCount( 1 );
inv.setInventorySlotContents( x, g );
ItemHandlerUtil.setStackInSlot( inv, x, g );
}
else
{
inv.setInventorySlotContents( x, ItemStack.EMPTY );
ItemHandlerUtil.setStackInSlot( inv, x, ItemStack.EMPTY );
}
}
@@ -25,6 +25,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.FuzzyMode;
import appeng.api.config.RedstoneMode;
@@ -112,9 +113,8 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl
{
for( int u = 0; u < 3; u++ )
{
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, this.tbInventory, u + v * 3, 186 + u * 18, this
.getHeight() - 82 + v * 18, this.getInventoryPlayer() ) ).setPlayerSide() );
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, this.tbInventory
.getInternalInventory(), u + v * 3, 186 + u * 18, this.getHeight() - 82 + v * 18, this.getInventoryPlayer() ) ).setPlayerSide() );
}
}
}
@@ -138,7 +138,7 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl
{
this.setupUpgrades();
final IInventory inv = this.getUpgradeable().getInventoryByName( "config" );
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
final int y = 40;
final int x = 80;
this.addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) );
@@ -159,7 +159,7 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl
protected void setupUpgrades()
{
final IInventory upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
if( this.availableUpgrades() > 0 )
{
this.addSlotToContainer(
@@ -45,7 +45,8 @@ public class ContainerVibrationChamber extends AEBaseContainer implements IProgr
super( ip, vibrationChamber, null );
this.vibrationChamber = vibrationChamber;
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.FUEL, vibrationChamber, 0, 80, 37, this.getInventoryPlayer() ) );
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.FUEL, vibrationChamber.getInternalInventory(), 0, 80, 37, this
.getInventoryPlayer() ) );
this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 );
}
@@ -43,9 +43,8 @@ public class ContainerWireless extends AEBaseContainer
super( ip, te, null );
this.wirelessTerminal = te;
this.addSlotToContainer(
this.boosterSlot = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.RANGE_BOOSTER, this.wirelessTerminal, 0, 80, 47, this
.getInventoryPlayer() ) );
this.addSlotToContainer( this.boosterSlot = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.RANGE_BOOSTER, this.wirelessTerminal
.getInternalInventory(), 0, 80, 47, this.getInventoryPlayer() ) );
this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 );
}
@@ -20,11 +20,14 @@ package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.util.NonNullList;
import net.minecraftforge.items.IItemHandler;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.WrapperInvItemHandler;
public class AppEngCraftingSlot extends AppEngSlot
@@ -33,7 +36,7 @@ public class AppEngCraftingSlot extends AppEngSlot
/**
* The craft matrix inventory linked to this result slot.
*/
private final IInventory craftMatrix;
private final IItemHandler craftMatrix;
/**
* The player that is using the GUI where this slot resides.
@@ -45,7 +48,7 @@ public class AppEngCraftingSlot extends AppEngSlot
*/
private int amountCrafted;
public AppEngCraftingSlot( final EntityPlayer par1EntityPlayer, final IInventory par2IInventory, final IInventory par3IInventory, final int par4, final int par5, final int par6 )
public AppEngCraftingSlot( final EntityPlayer par1EntityPlayer, final IItemHandler par2IInventory, final IItemHandler par3IInventory, final int par4, final int par5, final int par6 )
{
super( par3IInventory, par4, par5, par6 );
this.thePlayer = par1EntityPlayer;
@@ -136,22 +139,19 @@ public class AppEngCraftingSlot extends AppEngSlot
@Override
public ItemStack onTake( final EntityPlayer playerIn, final ItemStack stack )
{
net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent( playerIn, stack, this.craftMatrix );
net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent( playerIn, stack, new WrapperInvItemHandler( this.craftMatrix ) );
this.onCrafting( stack );
net.minecraftforge.common.ForgeHooks.setCraftingPlayer( playerIn );
final InventoryCrafting ic = new InventoryCrafting( this.getContainer(), 3, 3 );
for( int x = 0; x < this.craftMatrix.getSizeInventory(); x++ )
for( int x = 0; x < this.craftMatrix.getSlots(); x++ )
{
ic.setInventorySlotContents( x, this.craftMatrix.getStackInSlot( x ) );
}
final NonNullList<ItemStack> aitemstack = CraftingManager.getRemainingItems( ic, playerIn.world );
for( int x = 0; x < this.craftMatrix.getSizeInventory(); x++ )
{
this.craftMatrix.setInventorySlotContents( x, ic.getStackInSlot( x ) );
}
ItemHandlerUtil.copy( ic, this.craftMatrix, false );
net.minecraftforge.common.ForgeHooks.setCraftingPlayer( null );
@@ -162,14 +162,14 @@ public class AppEngCraftingSlot extends AppEngSlot
if( !itemstack1.isEmpty() )
{
this.craftMatrix.decrStackSize( i, 1 );
this.craftMatrix.extractItem( i, 1, false );
}
if( !itemstack2.isEmpty() )
{
if( this.craftMatrix.getStackInSlot( i ).isEmpty() )
{
this.craftMatrix.setInventorySlotContents( i, itemstack2 );
ItemHandlerUtil.setStackInSlot( this.craftMatrix, i, itemstack2 );
}
else if( !this.thePlayer.inventory.addItemStackToInventory( itemstack2 ) )
{
@@ -23,17 +23,22 @@ import javax.annotation.Nonnull;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.container.AEBaseContainer;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.helpers.ItemHandlerUtil;
public class AppEngSlot extends Slot
{
private static IInventory emptyInventory = new InventoryBasic( "[Null]", true, 0 );
private final IItemHandler itemHandler;
private final int index;
private final int defX;
private final int defY;
@@ -44,9 +49,12 @@ public class AppEngSlot extends Slot
private hasCalculatedValidness isValid;
private boolean isDisplay = false;
public AppEngSlot( final IInventory inv, final int idx, final int x, final int y )
public AppEngSlot( final IItemHandler inv, final int idx, final int x, final int y )
{
super( inv, idx, x, y );
super( emptyInventory, idx, x, y );
this.itemHandler = inv;
this.index = idx;
this.defX = x;
this.defY = y;
this.setIsValid( hasCalculatedValidness.NotAvailable );
@@ -75,11 +83,11 @@ public class AppEngSlot extends Slot
}
@Override
public boolean isItemValid( final ItemStack par1ItemStack )
public boolean isItemValid( @Nonnull final ItemStack par1ItemStack )
{
if( this.isSlotEnabled() )
{
return super.isItemValid( par1ItemStack );
return ItemHandlerUtil.isItemValidForSlot( this.itemHandler, this.index, par1ItemStack );
}
return false;
}
@@ -93,7 +101,7 @@ public class AppEngSlot extends Slot
return ItemStack.EMPTY;
}
if( this.inventory.getSizeInventory() <= this.getSlotIndex() )
if( this.itemHandler.getSlots() <= this.getSlotIndex() )
{
return ItemStack.EMPTY;
}
@@ -103,15 +111,17 @@ public class AppEngSlot extends Slot
this.setDisplay( false );
return this.getDisplayStack();
}
return super.getStack();
return this.itemHandler.getStackInSlot( index );
}
@Override
public void putStack( final ItemStack par1ItemStack )
public void putStack( final ItemStack stack )
{
if( this.isSlotEnabled() )
{
super.putStack( par1ItemStack );
ItemHandlerUtil.setStackInSlot( this.itemHandler, index, stack );
this.onSlotChanged();
if( this.getContainer() != null )
{
@@ -120,31 +130,53 @@ public class AppEngSlot extends Slot
}
}
public IItemHandler getItemHandler()
{
return this.itemHandler;
}
@Override
public void onSlotChanged()
{
if( this.inventory instanceof AppEngInternalInventory )
{
( (AppEngInternalInventory) this.inventory ).markDirty( this.getSlotIndex() );
}
else
{
super.onSlotChanged();
}
ItemHandlerUtil.markDirty( this.itemHandler, this.index );
this.setIsValid( hasCalculatedValidness.NotAvailable );
}
@Override
public int getSlotStackLimit()
{
return this.itemHandler.getSlotLimit( this.index );
}
@Override
public int getItemStackLimit( @Nonnull ItemStack stack )
{
return Math.min( getSlotStackLimit(), stack.getMaxStackSize() );
}
@Override
public boolean canTakeStack( final EntityPlayer par1EntityPlayer )
{
if( this.isSlotEnabled() )
{
return super.canTakeStack( par1EntityPlayer );
return !this.itemHandler.extractItem( index, 1, true ).isEmpty();
}
return false;
}
@Override
@Nonnull
public ItemStack decrStackSize( int amount )
{
return this.itemHandler.extractItem( index, amount, false );
}
@Override
public boolean isSameInventory( Slot other )
{
return other instanceof AppEngSlot && ( (AppEngSlot) other ).itemHandler == this.itemHandler;
}
@Override
@SideOnly( Side.CLIENT )
public boolean isEnabled()
@@ -159,7 +191,7 @@ public class AppEngSlot extends Slot
public ItemStack getDisplayStack()
{
return super.getStack();
return this.itemHandler.getStackInSlot( index );
}
public float getOpacityOfIcon()
@@ -21,8 +21,8 @@ package appeng.container.slot;
import javax.annotation.Nonnull;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class OptionalSlotFake extends SlotFake
@@ -34,7 +34,7 @@ public class OptionalSlotFake extends SlotFake
private final IOptionalSlotHost host;
private boolean renderDisabled = true;
public OptionalSlotFake( final IInventory inv, final IOptionalSlotHost containerBus, final int idx, final int x, final int y, final int offX, final int offY, final int groupNum )
public OptionalSlotFake( final IItemHandler inv, final IOptionalSlotHost containerBus, final int idx, final int x, final int y, final int offX, final int offY, final int groupNum )
{
super( inv, idx, x + offX * 18, y + offY * 18 );
this.srcX = x;
@@ -19,14 +19,14 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class OptionalSlotFakeTypeOnly extends OptionalSlotFake
{
public OptionalSlotFakeTypeOnly( final IInventory inv, final IOptionalSlotHost containerBus, final int idx, final int x, final int y, final int offX, final int offY, final int groupNum )
public OptionalSlotFakeTypeOnly( final IItemHandler inv, final IOptionalSlotHost containerBus, final int idx, final int x, final int y, final int offX, final int offY, final int groupNum )
{
super( inv, containerBus, idx, x, y, offX, offY, groupNum );
}
@@ -19,7 +19,7 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.items.IItemHandler;
public class OptionalSlotNormal extends AppEngSlot
@@ -28,7 +28,7 @@ public class OptionalSlotNormal extends AppEngSlot
private final int groupNum;
private final IOptionalSlotHost host;
public OptionalSlotNormal( final IInventory inv, final IOptionalSlotHost containerBus, final int slot, final int xPos, final int yPos, final int groupNum )
public OptionalSlotNormal( final IItemHandler inv, final IOptionalSlotHost containerBus, final int slot, final int xPos, final int yPos, final int groupNum )
{
super( inv, slot, xPos, yPos );
this.groupNum = groupNum;
@@ -20,7 +20,7 @@ package appeng.container.slot;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.items.IItemHandler;
public class OptionalSlotRestrictedInput extends SlotRestrictedInput
@@ -29,7 +29,7 @@ public class OptionalSlotRestrictedInput extends SlotRestrictedInput
private final int groupNum;
private final IOptionalSlotHost host;
public OptionalSlotRestrictedInput( final PlacableItemType valid, final IInventory i, final IOptionalSlotHost host, final int slotIndex, final int x, final int y, final int grpNum, final InventoryPlayer invPlayer )
public OptionalSlotRestrictedInput( final PlacableItemType valid, final IItemHandler i, final IOptionalSlotHost host, final int slotIndex, final int x, final int y, final int grpNum, final InventoryPlayer invPlayer )
{
super( valid, i, slotIndex, x, y, invPlayer );
this.groupNum = grpNum;
@@ -19,34 +19,38 @@
package appeng.container.slot;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.container.AEBaseContainer;
import appeng.util.inv.WrapperInvItemHandler;
public class SlotCraftingMatrix extends AppEngSlot
{
private final AEBaseContainer c;
private final IInventory wrappedInventory;
private final Container c;
public SlotCraftingMatrix( final Container c, final IInventory par1iInventory, final int par2, final int par3, final int par4 )
public SlotCraftingMatrix( final AEBaseContainer c, final IItemHandler par1iInventory, final int par2, final int par3, final int par4 )
{
super( par1iInventory, par2, par3, par4 );
this.c = c;
this.wrappedInventory = new WrapperInvItemHandler( par1iInventory );
}
@Override
public void clearStack()
{
super.clearStack();
this.c.onCraftMatrixChanged( this.inventory );
this.c.onCraftMatrixChanged( this.wrappedInventory );
}
@Override
public void putStack( final ItemStack par1ItemStack )
{
super.putStack( par1ItemStack );
this.c.onCraftMatrixChanged( this.inventory );
this.c.onCraftMatrixChanged( this.wrappedInventory );
}
@Override
@@ -59,7 +63,7 @@ public class SlotCraftingMatrix extends AppEngSlot
public ItemStack decrStackSize( final int par1 )
{
final ItemStack is = super.decrStackSize( par1 );
this.c.onCraftMatrixChanged( this.inventory );
this.c.onCraftMatrixChanged( this.wrappedInventory );
return is;
}
}
@@ -24,12 +24,12 @@ import java.util.Arrays;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Actionable;
import appeng.api.networking.energy.IEnergySource;
@@ -44,22 +44,25 @@ import appeng.helpers.InventoryAction;
import appeng.items.storage.ItemViewCell;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorPlayerHand;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.AdaptorItemHandler;
import appeng.util.inv.WrapperCursorItemHandler;
import appeng.util.inv.WrapperInvItemHandler;
import appeng.util.item.AEItemStack;
public class SlotCraftingTerm extends AppEngCraftingSlot
{
private final IInventory craftInv;
private final IInventory pattern;
private final IItemHandler craftInv;
private final IItemHandler pattern;
private final BaseActionSource mySrc;
private final IEnergySource energySrc;
private final IStorageMonitorable storage;
private final IContainerCraftingPacket container;
public SlotCraftingTerm( final EntityPlayer player, final BaseActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IInventory cMatrix, final IInventory secondMatrix, final IInventory output, final int x, final int y, final IContainerCraftingPacket ccp )
public SlotCraftingTerm( final EntityPlayer player, final BaseActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IItemHandler cMatrix, final IItemHandler secondMatrix, final IItemHandler output, final int x, final int y, final IContainerCraftingPacket ccp )
{
super( player, cMatrix, output, 0, x, y );
this.energySrc = energySrc;
@@ -70,7 +73,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
this.container = ccp;
}
public IInventory getCraftingMatrix()
public IItemHandler getCraftingMatrix()
{
return this.craftInv;
}
@@ -105,18 +108,18 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
InventoryAdaptor ia = null;
if( action == InventoryAction.CRAFT_SHIFT ) // craft into player inventory...
{
ia = InventoryAdaptor.getAdaptor( who, null );
ia = InventoryAdaptor.getAdaptor( who );
maxTimesToCraft = (int) Math.floor( (double) this.getStack().getMaxStackSize() / (double) howManyPerCraft );
}
else if( action == InventoryAction.CRAFT_STACK ) // craft into hand, full stack
{
ia = new AdaptorPlayerHand( who );
ia = new AdaptorItemHandler( new WrapperCursorItemHandler( who.inventory ) );
maxTimesToCraft = (int) Math.floor( (double) this.getStack().getMaxStackSize() / (double) howManyPerCraft );
}
else
// pick up what was crafted...
{
ia = new AdaptorPlayerHand( who );
ia = new AdaptorItemHandler( new WrapperCursorItemHandler( who.inventory ) );
maxTimesToCraft = 1;
}
@@ -162,7 +165,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
if( !is.isEmpty() && Platform.itemComparisons().isEqualItem( request, is ) )
{
final ItemStack[] set = new ItemStack[this.getPattern().getSizeInventory()];
final ItemStack[] set = new ItemStack[this.getPattern().getSlots()];
// Safeguard for empty slots in the inventory for now
Arrays.fill( set, ItemStack.EMPTY );
@@ -199,7 +202,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
{
super.onTake( p, is );
// actually necessary to cleanup this case...
p.openContainer.onCraftMatrixChanged( this.craftInv );
p.openContainer.onCraftMatrixChanged( new WrapperInvItemHandler( this.craftInv ) );
return request;
}
}
@@ -210,7 +213,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
if( inv != null )
{
for( int x = 0; x < this.getPattern().getSizeInventory(); x++ )
for( int x = 0; x < this.getPattern().getSlots(); x++ )
{
if( !this.getPattern().getStackInSlot( x ).isEmpty() )
{
@@ -229,8 +232,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
this.postCraft( p, inv, set, is );
}
// shouldn't be necessary...
p.openContainer.onCraftMatrixChanged( this.craftInv );
p.openContainer.onCraftMatrixChanged( new WrapperInvItemHandler( this.craftInv ) );
return is;
}
@@ -256,11 +258,11 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
if( Platform.isServer() )
{
// set new items onto the crafting table...
for( int x = 0; x < this.craftInv.getSizeInventory(); x++ )
for( int x = 0; x < this.craftInv.getSlots(); x++ )
{
if( this.craftInv.getStackInSlot( x ).isEmpty() )
{
this.craftInv.setInventorySlotContents( x, set[x] );
ItemHandlerUtil.setStackInSlot( this.craftInv, x, set[x] );
}
else if( !set[x].isEmpty() )
{
@@ -280,7 +282,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
}
}
IInventory getPattern()
IItemHandler getPattern()
{
return this.pattern;
}
@@ -20,14 +20,14 @@ package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class SlotDisabled extends AppEngSlot
{
public SlotDisabled( final IInventory par1iInventory, final int slotIndex, final int x, final int y )
public SlotDisabled( final IItemHandler par1iInventory, final int slotIndex, final int x, final int y )
{
super( par1iInventory, slotIndex, x, y );
}
@@ -20,14 +20,14 @@ package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class SlotFake extends AppEngSlot
{
public SlotFake( final IInventory inv, final int idx, final int x, final int y )
public SlotFake( final IItemHandler inv, final int idx, final int x, final int y )
{
super( inv, idx, x, y );
}
@@ -19,13 +19,13 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.items.IItemHandler;
public class SlotFakeBlacklist extends SlotFakeTypeOnly
{
public SlotFakeBlacklist( final IInventory inv, final int idx, final int x, final int y )
public SlotFakeBlacklist( final IItemHandler inv, final int idx, final int x, final int y )
{
super( inv, idx, x, y );
}
@@ -19,13 +19,13 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.items.IItemHandler;
public class SlotFakeCraftingMatrix extends SlotFake
{
public SlotFakeCraftingMatrix( final IInventory inv, final int idx, final int x, final int y )
public SlotFakeCraftingMatrix( final IItemHandler inv, final int idx, final int x, final int y )
{
super( inv, idx, x, y );
}
@@ -19,14 +19,14 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class SlotFakeTypeOnly extends SlotFake
{
public SlotFakeTypeOnly( final IInventory inv, final int idx, final int x, final int y )
public SlotFakeTypeOnly( final IItemHandler inv, final int idx, final int x, final int y )
{
super( inv, idx, x, y );
}
@@ -20,8 +20,8 @@ package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class SlotInaccessible extends AppEngSlot
@@ -29,7 +29,7 @@ public class SlotInaccessible extends AppEngSlot
private ItemStack dspStack = ItemStack.EMPTY;
public SlotInaccessible( final IInventory i, final int slotIdx, final int x, final int y )
public SlotInaccessible( final IItemHandler i, final int slotIdx, final int x, final int y )
{
super( i, slotIdx, x, y );
}
@@ -19,13 +19,13 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.items.IItemHandler;
public class SlotInaccessibleHD extends SlotInaccessible
{
public SlotInaccessibleHD( final IInventory i, final int slotIdx, final int x, final int y )
public SlotInaccessibleHD( final IItemHandler i, final int slotIdx, final int x, final int y )
{
super( i, slotIdx, x, y );
}
@@ -19,8 +19,8 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.container.implementations.ContainerMAC;
@@ -30,7 +30,7 @@ public class SlotMACPattern extends AppEngSlot
private final ContainerMAC mac;
public SlotMACPattern( final ContainerMAC mac, final IInventory i, final int slotIdx, final int x, final int y )
public SlotMACPattern( final ContainerMAC mac, final IItemHandler i, final int slotIdx, final int x, final int y )
{
super( i, slotIdx, x, y );
this.mac = mac;
@@ -19,13 +19,13 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.items.IItemHandler;
public class SlotNormal extends AppEngSlot
{
public SlotNormal( final IInventory inv, final int slot, final int xPos, final int yPos )
public SlotNormal( final IItemHandler inv, final int slot, final int xPos, final int yPos )
{
super( inv, slot, xPos, yPos );
}
@@ -19,14 +19,14 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class SlotOutput extends AppEngSlot
{
public SlotOutput( final IInventory a, final int b, final int c, final int d, final int i )
public SlotOutput( final IItemHandler a, final int b, final int c, final int d, final int i )
{
super( a, b, c, d );
this.setIIcon( i );
@@ -19,13 +19,13 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.items.IItemHandler;
public class SlotPatternOutputs extends OptionalSlotFake
{
public SlotPatternOutputs( final IInventory inv, final IOptionalSlotHost containerBus, final int idx, final int x, final int y, final int offX, final int offY, final int groupNum )
public SlotPatternOutputs( final IItemHandler inv, final IOptionalSlotHost containerBus, final int idx, final int x, final int y, final int offX, final int offY, final int groupNum )
{
super( inv, containerBus, idx, x, y, offX, offY, groupNum );
}
@@ -22,8 +22,8 @@ package appeng.container.slot;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.networking.energy.IEnergySource;
@@ -40,7 +40,7 @@ public class SlotPatternTerm extends SlotCraftingTerm
private final int groupNum;
private final IOptionalSlotHost host;
public SlotPatternTerm( final EntityPlayer player, final BaseActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IInventory cMatrix, final IInventory secondMatrix, final IInventory output, final int x, final int y, final IOptionalSlotHost h, final int groupNumber, final IContainerCraftingPacket c )
public SlotPatternTerm( final EntityPlayer player, final BaseActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IItemHandler cMatrix, final IItemHandler secondMatrix, final IItemHandler output, final int x, final int y, final IOptionalSlotHost h, final int groupNumber, final IContainerCraftingPacket c )
{
super( player, mySrc, energySrc, storage, cMatrix, secondMatrix, output, x, y, c );
@@ -19,13 +19,13 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.items.IItemHandler;
public class SlotPlayerHotBar extends AppEngSlot
{
public SlotPlayerHotBar( final IInventory par1iInventory, final int par2, final int par3, final int par4 )
public SlotPlayerHotBar( final IItemHandler par1iInventory, final int par2, final int par3, final int par4 )
{
super( par1iInventory, par2, par3, par4 );
this.setPlayerSide( true );
@@ -19,7 +19,7 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.items.IItemHandler;
// there is nothing special about this slot, its simply used to represent the players inventory, vs a container slot.
@@ -27,7 +27,7 @@ import net.minecraft.inventory.IInventory;
public class SlotPlayerInv extends AppEngSlot
{
public SlotPlayerInv( final IInventory par1iInventory, final int par2, final int par3, final int par4 )
public SlotPlayerInv( final IItemHandler par1iInventory, final int par2, final int par3, final int par4 )
{
super( par1iInventory, par2, par3, par4 );
@@ -22,11 +22,11 @@ package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.AEApi;
@@ -59,7 +59,7 @@ public class SlotRestrictedInput extends AppEngSlot
private boolean allowEdit = true;
private int stackLimit = -1;
public SlotRestrictedInput( final PlacableItemType valid, final IInventory i, final int slotIndex, final int x, final int y, final InventoryPlayer p )
public SlotRestrictedInput( final PlacableItemType valid, final IItemHandler i, final int slotIndex, final int x, final int y, final InventoryPlayer p )
{
super( i, slotIndex, x, y );
this.which = valid;
@@ -106,12 +106,13 @@ public class SlotRestrictedInput extends AppEngSlot
{
return false;
}
if( i.getItem() == Items.AIR )
{
return false;
}
if( !this.inventory.isItemValidForSlot( this.getSlotIndex(), i ) )
if( !super.isItemValid( i ) )
{
return false;
}
@@ -30,7 +30,6 @@ import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.AEApi;
@@ -30,14 +30,13 @@ import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.config.Actionable;
@@ -58,6 +57,8 @@ import appeng.helpers.IContainerCraftingPacket;
import appeng.items.storage.ItemViewCell;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.WrapperInvItemHandler;
import appeng.util.item.AEItemStack;
import appeng.util.prioritylist.IPartitionList;
@@ -128,8 +129,8 @@ public class PacketJEIRecipe extends AppEngPacket
final IStorageGrid inv = grid.getCache( IStorageGrid.class );
final IEnergyGrid energy = grid.getCache( IEnergyGrid.class );
final ISecurityGrid security = grid.getCache( ISecurityGrid.class );
final IInventory craftMatrix = cct.getInventoryByName( "crafting" );
final IInventory playerInventory = cct.getInventoryByName( "player" );
final IItemHandler craftMatrix = cct.getInventoryByName( "crafting" );
final IItemHandler playerInventory = cct.getInventoryByName( "player" );
final Actionable realForFake = cct.useRealItems() ? Actionable.MODULATE : Actionable.SIMULATE;
@@ -156,7 +157,7 @@ public class PacketJEIRecipe extends AppEngPacket
final IItemList all = storage.getStorageList();
final IPartitionList<IAEItemStack> filter = ItemViewCell.createFilter( cct.getViewCells() );
for( int x = 0; x < craftMatrix.getSizeInventory(); x++ )
for( int x = 0; x < craftMatrix.getSlots(); x++ )
{
final ItemStack patternItem = testInv.getStackInSlot( x );
@@ -176,11 +177,11 @@ public class PacketJEIRecipe extends AppEngPacket
cct.getActionSource() );
if( out != null )
{
craftMatrix.setInventorySlotContents( x, out.getItemStack() );
ItemHandlerUtil.setStackInSlot( craftMatrix, x, out.getItemStack() );
}
else
{
craftMatrix.setInventorySlotContents( x, ItemStack.EMPTY );
ItemHandlerUtil.setStackInSlot( craftMatrix, x, ItemStack.EMPTY );
}
currentItem = craftMatrix.getStackInSlot( x );
@@ -224,10 +225,10 @@ public class PacketJEIRecipe extends AppEngPacket
whichItem = this.extractItemFromPlayerInventory( player, realForFake, patternItem );
}
craftMatrix.setInventorySlotContents( x, whichItem );
ItemHandlerUtil.setStackInSlot( craftMatrix, x, whichItem );
}
}
con.onCraftMatrixChanged( craftMatrix );
con.onCraftMatrixChanged( new WrapperInvItemHandler( craftMatrix ) );
}
}
}
@@ -245,7 +246,7 @@ public class PacketJEIRecipe extends AppEngPacket
*/
private ItemStack extractItemFromPlayerInventory( final EntityPlayer player, final Actionable mode, final ItemStack patternItem )
{
final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player, EnumFacing.UP );
final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player );
final AEItemStack request = AEItemStack.create( patternItem );
final boolean isSimulated = mode == Actionable.SIMULATE;
final boolean checkFuzzy = request.isOre() || patternItem.getItemDamage() == OreDictionary.WILDCARD_VALUE || patternItem.hasTagCompound() || patternItem
@@ -77,7 +77,8 @@ public class PacketPartPlacement extends AppEngPacket
final EntityPlayerMP sender = (EntityPlayerMP) player;
AppEng.proxy.updateRenderMode( sender );
PartPlacement.setEyeHeight( this.eyeHeight );
PartPlacement.place( sender.getHeldItem( this.hand ), new BlockPos( this.x, this.y, this.z ), EnumFacing.VALUES[this.face], sender, this.hand, sender.world,
PartPlacement.place( sender.getHeldItem( this.hand ), new BlockPos( this.x, this.y, this.z ), EnumFacing.VALUES[this.face], sender, this.hand,
sender.world,
PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0 );
AppEng.proxy.updateRenderMode( null );
}
@@ -26,7 +26,7 @@ import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.storage.data.IAEItemStack;
@@ -72,7 +72,7 @@ public class PacketPatternSlot extends AppEngPacket
}
// api
public PacketPatternSlot( final IInventory pat, final IAEItemStack slotItem, final boolean shift ) throws IOException
public PacketPatternSlot( final IItemHandler pat, final IAEItemStack slotItem, final boolean shift ) throws IOException
{
this.slotItem = slotItem;
@@ -33,8 +33,6 @@ import com.google.common.collect.ImmutableSet;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -49,7 +47,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.items.wrapper.RangedWrapper;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
@@ -97,15 +95,14 @@ import appeng.parts.automation.StackUpgradeInventory;
import appeng.parts.automation.UpgradeInventory;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorIInventory;
import appeng.util.inv.AdaptorItemHandler;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.IInventoryDestination;
import appeng.util.inv.WrapperInvSlot;
import appeng.util.inv.InvOperation;
import appeng.util.item.AEItemStack;
@@ -117,7 +114,6 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
public static final int NUMBER_OF_PATTERN_SLOTS = 9;
private static final Collection<Block> BAD_BLOCKS = new HashSet<>( 100 );
private final int[] sides = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
private final IAEItemStack[] requireWork = { null, null, null, null, null, null, null, null, null };
private final MultiCraftingTracker craftingTracker;
private final AENetworkProxy gridProxy;
@@ -128,7 +124,6 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, NUMBER_OF_CONFIG_SLOTS );
private final AppEngInternalInventory storage = new AppEngInternalInventory( this, NUMBER_OF_STORAGE_SLOTS );
private final AppEngInternalInventory patterns = new AppEngInternalInventory( this, NUMBER_OF_PATTERN_SLOTS );
private final WrapperInvSlot slotInv = new WrapperInvSlot( this.storage );
private final MEMonitorPassThrough<IAEItemStack> items = new MEMonitorPassThrough<>( new NullInventory<IAEItemStack>(), StorageChannel.ITEMS );
private final MEMonitorPassThrough<IAEFluidStack> fluids = new MEMonitorPassThrough<>( new NullInventory<IAEFluidStack>(), StorageChannel.FLUIDS );
private final UpgradeInventory upgrades;
@@ -138,7 +133,6 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
private List<ItemStack> waitingToSend = null;
private IMEInventory<IAEItemStack> destination;
private boolean isWorking = false;
private IItemHandler itemHandler = null;
private final Accessor accessor = new Accessor();
public DualityInterface( final AENetworkProxy networkProxy, final IInterfaceHost ih )
@@ -168,7 +162,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
{
if( this.isWorking )
{
@@ -335,7 +329,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
{
final Boolean[] accountedFor = { false, false, false, false, false, false, false, false, false }; // 9...
assert ( accountedFor.length == this.patterns.getSizeInventory() );
assert ( accountedFor.length == this.patterns.getSlots() );
if( !this.gridProxy.isReady() )
{
@@ -409,7 +403,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
IAEItemStack req = this.config.getAEStackInSlot( slot );
if( req != null && req.getStackSize() <= 0 )
{
this.config.setInventorySlotContents( slot, ItemStack.EMPTY );
this.config.setStackInSlot( slot, ItemStack.EMPTY );
req = null;
}
@@ -517,12 +511,12 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
// return after.stackSize != stack.stackSize;
}
public IInventory getConfig()
public IItemHandler getConfig()
{
return this.config;
}
public IInventory getPatterns()
public IItemHandler getPatterns()
{
return this.patterns;
}
@@ -553,24 +547,19 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
return new DimensionalCoord( this.iHost.getTileEntity() );
}
public IInventory getInternalInventory()
public IItemHandler getInternalInventory()
{
return this.storage;
}
public void markDirty()
{
for( int slot = 0; slot < this.storage.getSizeInventory(); slot++ )
for( int slot = 0; slot < this.storage.getSlots(); slot++ )
{
this.onChangeInventory( this.storage, slot, InvOperation.markDirty, ItemStack.EMPTY, ItemStack.EMPTY );
this.storage.markDirty( slot );
}
}
public int[] getSlotsForFace( final EnumFacing side )
{
return this.sides;
}
@Override
public TickingRequest getTickingRequest( final IGridNode node )
{
@@ -759,7 +748,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
private InventoryAdaptor getAdaptor( final int slot )
{
return new AdaptorIInventory( this.slotInv.getWrapper( slot ) );
return new AdaptorItemHandler( new RangedWrapper( this.storage, slot, slot + 1 ) );
}
private boolean handleCrafting( final int x, final InventoryAdaptor d, final IAEItemStack itemStack )
@@ -813,7 +802,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "storage" ) )
{
@@ -838,7 +827,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
return null;
}
public IInventory getStorage()
public IItemHandler getStorage()
{
return this.storage;
}
@@ -1185,21 +1174,11 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor( directedTile, direction.getOpposite() );
if( directedTile instanceof ICraftingMachine || adaptor != null )
{
if( directedTile instanceof IInventory && ( (IInventory) directedTile ).getSizeInventory() == 0 )
if( adaptor != null && !adaptor.hasSlots() )
{
continue;
}
if( directedTile instanceof ISidedInventory )
{
final int[] sides = ( (ISidedInventory) directedTile ).getSlotsForFace( direction.getOpposite() );
if( sides == null || sides.length == 0 )
{
continue;
}
}
final IBlockState directedBlockState = hostWorld.getBlockState( targ );
final Block directedBlock = directedBlockState.getBlock();
ItemStack what = new ItemStack( directedBlock, 1, directedBlock.getMetaFromState( directedBlockState ) );
@@ -1285,11 +1264,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
{
if( capabilityClass == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
{
if( this.itemHandler == null )
{
this.itemHandler = new InvWrapper( this.storage );
}
return (T) this.itemHandler;
return (T) storage;
}
else if( capabilityClass == Capabilities.STORAGE_MONITORABLE_ACCESSOR )
{
@@ -1312,7 +1287,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
public InterfaceInventory( final DualityInterface tileInterface )
{
super( new AdaptorIInventory( tileInterface.storage ) );
super( new AdaptorItemHandler( tileInterface.storage ) );
this.setActionSource( new MachineSource( DualityInterface.this.iHost ) );
}
@@ -19,8 +19,8 @@
package appeng.helpers;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.BaseActionSource;
@@ -39,7 +39,7 @@ public interface IContainerCraftingPacket
*
* @return the inventory of the part/tile by name.
*/
IInventory getInventoryByName( String string );
IItemHandler getInventoryByName( String string );
/**
* @return who are we?
@@ -21,9 +21,9 @@ package appeng.integration.modules.theoneprobe.tile;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import mcjty.theoneprobe.api.ElementAlignment;
import mcjty.theoneprobe.api.IProbeHitData;
@@ -43,7 +43,7 @@ public class ChargerInfoProvider implements ITileProbInfoProvider
if( tile instanceof TileCharger )
{
final TileCharger charger = (TileCharger) tile;
final IInventory chargerInventory = charger.getInternalInventory();
final IItemHandler chargerInventory = charger.getInternalInventory();
final ItemStack chargingItem = chargerInventory.getStackInSlot( 0 );
if( !chargingItem.isEmpty() )
@@ -26,9 +26,9 @@ import javax.annotation.Nonnull;
import net.minecraft.client.Minecraft;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.items.IItemHandler;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
@@ -64,7 +64,7 @@ public final class ChargerWailaDataProvider extends BaseWailaDataProvider
if( te instanceof TileCharger )
{
final TileCharger charger = (TileCharger) te;
final IInventory chargerInventory = charger.getInternalInventory();
final IItemHandler chargerInventory = charger.getInternalInventory();
final ItemStack chargingItem = chargerInventory.getStackInSlot( 0 );
if( !chargingItem.isEmpty() )
@@ -38,7 +38,7 @@ public class CellConfig extends AppEngInternalInventory
}
@Override
public void markDirty()
protected void onContentsChanged( int slot )
{
this.writeToNBT( Platform.openNbtData( this.is ), "list" );
}
@@ -37,7 +37,7 @@ public final class CellUpgrades extends StackUpgradeInventory
}
@Override
public void markDirty()
protected void onContentsChanged( int slot )
{
this.writeToNBT( Platform.openNbtData( this.is ), "upgrades" );
}
@@ -19,18 +19,20 @@
package appeng.items.contents;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.items.IItemHandler;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.api.networking.IGridHost;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.inv.filter.IAEItemFilter;
public class NetworkToolViewer implements INetworkTool
public class NetworkToolViewer implements INetworkTool, IAEAppEngInventory
{
private final AppEngInternalInventory inv;
@@ -41,7 +43,8 @@ public class NetworkToolViewer implements INetworkTool
{
this.is = is;
this.gh = gHost;
this.inv = new AppEngInternalInventory( null, 9 );
this.inv = new AppEngInternalInventory( this, 9 );
this.inv.setFilter( new NetworkToolInventoryFilter() );
if( is.hasTagCompound() ) // prevent crash when opening network status screen.
{
this.inv.readFromNBT( Platform.openNbtData( is ), "inv" );
@@ -49,85 +52,17 @@ public class NetworkToolViewer implements INetworkTool
}
@Override
public int getSizeInventory()
public void saveChanges()
{
return this.inv.getSizeInventory();
inv.markDirty( -1 );
}
@Override
public ItemStack getStackInSlot( final int i )
public void onChangeInventory( IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack )
{
return this.inv.getStackInSlot( i );
}
@Override
public ItemStack decrStackSize( final int i, final int j )
{
return this.inv.decrStackSize( i, j );
}
@Override
public ItemStack removeStackFromSlot( int i )
{
return this.inv.removeStackFromSlot( i );
}
@Override
public void setInventorySlotContents( final int i, final ItemStack itemstack )
{
this.inv.setInventorySlotContents( i, itemstack );
}
@Override
public String getName()
{
return this.inv.getName();
}
@Override
public boolean hasCustomName()
{
return this.inv.hasCustomName();
}
@Override
public int getInventoryStackLimit()
{
return this.inv.getInventoryStackLimit();
}
@Override
public void markDirty()
{
this.inv.markDirty();
this.inv.writeToNBT( Platform.openNbtData( this.is ), "inv" );
}
@Override
public boolean isUsableByPlayer( final EntityPlayer entityplayer )
{
return this.inv.isUsableByPlayer( entityplayer );
}
@Override
public void openInventory( final EntityPlayer player )
{
this.inv.openInventory( player );
}
@Override
public void closeInventory( final EntityPlayer player )
{
this.inv.closeInventory( player );
}
@Override
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
{
return this.inv.isItemValidForSlot( i,
itemstack ) && itemstack.getItem() instanceof IUpgradeModule && ( (IUpgradeModule) itemstack.getItem() ).getType( itemstack ) != null;
}
@Override
public ItemStack getItemStack()
{
@@ -140,39 +75,29 @@ public class NetworkToolViewer implements INetworkTool
return this.gh;
}
@Override
public int getField( final int id )
private static class NetworkToolInventoryFilter implements IAEItemFilter
{
return this.inv.getField( id );
@Override
public boolean allowExtract( IItemHandler inv, int slot, int amount )
{
return true;
}
@Override
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
{
return stack.getItem() instanceof IUpgradeModule && ( (IUpgradeModule) stack.getItem() ).getType( stack ) != null;
}
}
public IItemHandler getInternalInventory()
{
return inv;
}
@Override
public void setField( final int id, final int value )
public IItemHandler getInventory()
{
this.inv.setField( id, value );
}
@Override
public int getFieldCount()
{
return this.inv.getFieldCount();
}
@Override
public void clear()
{
this.inv.clear();
}
@Override
public ITextComponent getDisplayName()
{
return this.inv.getDisplayName();
}
@Override
public boolean isEmpty()
{
return false;
return this.inv;
}
}
@@ -38,7 +38,6 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@@ -51,6 +50,7 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.config.Upgrades;
@@ -68,6 +68,7 @@ import appeng.core.features.MaterialStackSrc;
import appeng.items.AEBaseItem;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorItemHandler;
public final class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule
@@ -289,7 +290,7 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
if( player.isSneaking() )
{
final TileEntity te = world.getTileEntity( pos );
IInventory upgrades = null;
IItemHandler upgrades = null;
if( te instanceof IPartHost )
{
@@ -311,17 +312,14 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
if( u != null )
{
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( upgrades, EnumFacing.UP );
if( ad != null )
if( player.world.isRemote )
{
if( player.world.isRemote )
{
return EnumActionResult.PASS;
}
player.inventory.setInventorySlotContents( player.inventory.currentItem, ad.addItems( player.getHeldItem( hand ) ) );
return EnumActionResult.SUCCESS;
return EnumActionResult.PASS;
}
final InventoryAdaptor ad = new AdaptorItemHandler( upgrades );
player.inventory.setInventorySlotContents( player.inventory.currentItem, ad.addItems( player.getHeldItem( hand ) ) );
return EnumActionResult.SUCCESS;
}
}
}
@@ -25,7 +25,6 @@ import java.util.Set;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
@@ -35,6 +34,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
@@ -188,13 +188,13 @@ public final class ItemBasicStorageCell extends AEBaseItem implements IStorageCe
}
@Override
public IInventory getUpgradesInventory( final ItemStack is )
public IItemHandler getUpgradesInventory( final ItemStack is )
{
return new CellUpgrades( is, 2 );
}
@Override
public IInventory getConfigInventory( final ItemStack is )
public IItemHandler getConfigInventory( final ItemStack is )
{
return new CellConfig( is );
}
@@ -239,7 +239,7 @@ public final class ItemBasicStorageCell extends AEBaseItem implements IStorageCe
final IMEInventoryHandler inv = AEApi.instance().registries().cell().getCellInventory( stack, null, StorageChannel.ITEMS );
if( inv != null && playerInventory.getCurrentItem() == stack )
{
final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player, EnumFacing.UP );
final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player );
final IItemList<IAEItemStack> list = inv.getAvailableItems( StorageChannel.ITEMS.createList() );
if( list.isEmpty() && ia != null )
{
@@ -253,8 +253,8 @@ public final class ItemBasicStorageCell extends AEBaseItem implements IStorageCe
}
// drop upgrades
final IInventory upgradesInventory = this.getUpgradesInventory( stack );
for( int upgradeIndex = 0; upgradeIndex < upgradesInventory.getSizeInventory(); upgradeIndex++ )
final IItemHandler upgradesInventory = this.getUpgradesInventory( stack );
for( int upgradeIndex = 0; upgradeIndex < upgradesInventory.getSlots(); upgradeIndex++ )
{
final ItemStack upgradeStack = upgradesInventory.getStackInSlot( upgradeIndex );
final ItemStack leftStack = ia.addItems( upgradeStack );
@@ -22,11 +22,11 @@ package appeng.items.storage;
import java.util.List;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
@@ -53,13 +53,13 @@ public class ItemCreativeStorageCell extends AEBaseItem implements ICellWorkbenc
}
@Override
public IInventory getUpgradesInventory( final ItemStack is )
public IItemHandler getUpgradesInventory( final ItemStack is )
{
return null;
}
@Override
public IInventory getConfigInventory( final ItemStack is )
public IItemHandler getConfigInventory( final ItemStack is )
{
return new CellConfig( is );
}
@@ -19,8 +19,8 @@
package appeng.items.storage;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
@@ -65,14 +65,14 @@ public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
final ICellWorkbenchItem vc = (ICellWorkbenchItem) currentViewCell.getItem();
final IInventory upgrades = vc.getUpgradesInventory( currentViewCell );
final IInventory config = vc.getConfigInventory( currentViewCell );
final IItemHandler upgrades = vc.getUpgradesInventory( currentViewCell );
final IItemHandler config = vc.getConfigInventory( currentViewCell );
final FuzzyMode fzMode = vc.getFuzzyMode( currentViewCell );
boolean hasInverter = false;
boolean hasFuzzy = false;
for( int x = 0; x < upgrades.getSizeInventory(); x++ )
for( int x = 0; x < upgrades.getSlots(); x++ )
{
final ItemStack is = upgrades.getStackInSlot( x );
if( !is.isEmpty() && is.getItem() instanceof IUpgradeModule )
@@ -94,7 +94,7 @@ public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem
}
}
for( int x = 0; x < config.getSizeInventory(); x++ )
for( int x = 0; x < config.getSlots(); x++ )
{
final ItemStack is = config.getStackInSlot( x );
if( !is.isEmpty() )
@@ -129,13 +129,13 @@ public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem
}
@Override
public IInventory getUpgradesInventory( final ItemStack is )
public IItemHandler getUpgradesInventory( final ItemStack is )
{
return new CellUpgrades( is, 2 );
}
@Override
public IInventory getConfigInventory( final ItemStack is )
public IItemHandler getConfigInventory( final ItemStack is )
{
return new CellConfig( is );
}
@@ -37,7 +37,6 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemSnowball;
import net.minecraft.item.ItemStack;
@@ -50,6 +49,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.AEApi;
@@ -516,13 +516,13 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
}
@Override
public IInventory getUpgradesInventory( final ItemStack is )
public IItemHandler getUpgradesInventory( final ItemStack is )
{
return new CellUpgrades( is, 2 );
}
@Override
public IInventory getConfigInventory( final ItemStack is )
public IItemHandler getConfigInventory( final ItemStack is )
{
return new CellConfig( is );
}
@@ -31,7 +31,6 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
@@ -46,6 +45,7 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
@@ -445,13 +445,13 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell
}
@Override
public IInventory getUpgradesInventory( final ItemStack is )
public IItemHandler getUpgradesInventory( final ItemStack is )
{
return new CellUpgrades( is, 4 );
}
@Override
public IInventory getConfigInventory( final ItemStack is )
public IItemHandler getConfigInventory( final ItemStack is )
{
return new CellConfig( is );
}
@@ -24,7 +24,6 @@ import java.util.Set;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
@@ -33,6 +32,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
@@ -152,13 +152,13 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell,
}
@Override
public IInventory getUpgradesInventory( final ItemStack is )
public IItemHandler getUpgradesInventory( final ItemStack is )
{
return new CellUpgrades( is, 2 );
}
@Override
public IInventory getConfigInventory( final ItemStack is )
public IItemHandler getConfigInventory( final ItemStack is )
{
return new CellConfig( is );
}
@@ -27,7 +27,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import appeng.api.config.PowerUnits;
@@ -21,11 +21,11 @@ package appeng.me.storage;
import java.util.HashSet;
import net.minecraft.inventory.IInventory;
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;
import appeng.api.AEApi;
@@ -534,13 +534,13 @@ public class CellInventory implements ICellInventory
}
@Override
public IInventory getConfigInventory()
public IItemHandler getConfigInventory()
{
return this.cellType.getConfigInventory( this.i );
}
@Override
public IInventory getUpgradesInventory()
public IItemHandler getUpgradesInventory()
{
return this.cellType.getUpgradesInventory( this.i );
}
@@ -19,9 +19,9 @@
package appeng.me.storage;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
@@ -52,14 +52,14 @@ public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> imple
{
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
final IInventory upgrades = ci.getUpgradesInventory();
final IInventory config = ci.getConfigInventory();
final IItemHandler upgrades = ci.getUpgradesInventory();
final IItemHandler config = ci.getConfigInventory();
final FuzzyMode fzMode = ci.getFuzzyMode();
boolean hasInverter = false;
boolean hasFuzzy = false;
for( int x = 0; x < upgrades.getSizeInventory(); x++ )
for( int x = 0; x < upgrades.getSlots(); x++ )
{
final ItemStack is = upgrades.getStackInSlot( x );
if( !is.isEmpty() && is.getItem() instanceof IUpgradeModule )
@@ -81,7 +81,7 @@ public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> imple
}
}
for( int x = 0; x < config.getSizeInventory(); x++ )
for( int x = 0; x < config.getSlots(); x++ )
{
final ItemStack is = config.getStackInSlot( x );
if( !is.isEmpty() )
+7 -7
View File
@@ -34,7 +34,6 @@ import net.minecraft.crash.CrashReportCategory;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@@ -45,6 +44,7 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.Upgrades;
@@ -344,7 +344,7 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
return null;
}
@@ -372,15 +372,15 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
pHost.setPriority( compound.getInteger( "priority" ) );
}
final IInventory inv = this.getInventoryByName( "config" );
final IItemHandler inv = this.getInventoryByName( "config" );
if( inv instanceof AppEngInternalAEInventory )
{
final AppEngInternalAEInventory target = (AppEngInternalAEInventory) inv;
final AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSizeInventory() );
final AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSlots() );
tmp.readFromNBT( compound, "config" );
for( int x = 0; x < tmp.getSizeInventory(); x++ )
for( int x = 0; x < tmp.getSlots(); x++ )
{
target.setInventorySlotContents( x, tmp.getStackInSlot( x ) );
target.setStackInSlot( x, tmp.getStackInSlot( x ) );
}
}
}
@@ -408,7 +408,7 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
output.setInteger( "priority", pHost.getPriority() );
}
final IInventory inv = this.getInventoryByName( "config" );
final IItemHandler inv = this.getInventoryByName( "config" );
if( inv instanceof AppEngInternalAEInventory )
{
( (AppEngInternalAEInventory) inv ).writeToNBT( output, "config" );
@@ -25,7 +25,7 @@ import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import appeng.api.config.Upgrades;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.util.inv.IAEAppEngInventory;
public class BlockUpgradeInventory extends UpgradeInventory
@@ -23,7 +23,7 @@ import net.minecraft.item.ItemStack;
import appeng.api.config.Upgrades;
import appeng.api.definitions.IItemDefinition;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.util.inv.IAEAppEngInventory;
public final class DefinitionUpgradeInventory extends UpgradeInventory
@@ -26,7 +26,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemFirework;
@@ -43,6 +42,7 @@ import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
@@ -78,8 +78,8 @@ import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.storage.MEInventoryHandler;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.prioritylist.FuzzyPriorityList;
import appeng.util.prioritylist.PrecisePriorityList;
@@ -119,7 +119,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
final int slotsToUse = 18 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
for( int x = 0; x < this.Config.getSizeInventory() && x < slotsToUse; x++ )
for( int x = 0; x < this.Config.getSlots() && x < slotsToUse; x++ )
{
final IAEItemStack is = this.Config.getAEStackInSlot( x );
if( is != null )
@@ -161,7 +161,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
@@ -195,7 +195,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "config" ) )
{
@@ -456,7 +456,6 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
EnumHand hand = player.getActiveHand();
player.setHeldItem( hand, is );
// TODO: LIMIT FIREWORKS
/*
* if( i instanceof ItemFirework )
@@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -34,6 +33,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.FuzzyMode;
import appeng.api.config.LevelType;
@@ -76,8 +76,8 @@ import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.parts.PartModel;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherHost, IStackWatcherHost, ICraftingWatcherHost, IMEMonitorHandlerReceiver<IAEItemStack>, ICraftingProvider
@@ -479,7 +479,7 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
if( inv == this.config )
{
@@ -522,7 +522,7 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "config" ) )
{
@@ -19,11 +19,11 @@
package appeng.parts.automation;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Upgrades;
@@ -69,7 +69,7 @@ public abstract class PartSharedItemBus extends PartUpgradeable implements IGrid
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "config" ) )
{
@@ -125,7 +125,7 @@ public abstract class PartSharedItemBus extends PartUpgradeable implements IGrid
protected int availableSlots()
{
return Math.min( 1 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 4, this.getConfig().getSizeInventory() );
return Math.min( 1 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 4, this.getConfig().getSlots() );
}
protected int calculateItemsToSend()
@@ -21,17 +21,17 @@ package appeng.parts.automation;
import java.util.List;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Upgrades;
import appeng.api.util.IConfigManager;
import appeng.parts.PartBasicState;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
public abstract class PartUpgradeable extends PartBasicState implements IAEAppEngInventory, IConfigManagerHost
@@ -59,7 +59,7 @@ public abstract class PartUpgradeable extends PartBasicState implements IAEAppEn
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
if( inv == this.upgrades )
{
@@ -155,7 +155,7 @@ public abstract class PartUpgradeable extends PartBasicState implements IAEAppEn
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "upgrades" ) )
{
@@ -22,8 +22,8 @@ package appeng.parts.automation;
import net.minecraft.item.ItemStack;
import appeng.api.config.Upgrades;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
public class StackUpgradeInventory extends UpgradeInventory
@@ -20,17 +20,18 @@ package appeng.parts.automation;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Upgrades;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.inv.filter.IAEItemFilter;
public abstract class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory
@@ -47,9 +48,10 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
public UpgradeInventory( final IAEAppEngInventory parent, final int s )
{
super( null, s );
super( null, s, 1 );
this.setTileEntity( this );
this.parent = parent;
this.setFilter( new UpgradeInvFilter() );
}
@Override
@@ -58,31 +60,6 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
return true;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
{
if( itemstack.isEmpty() )
{
return false;
}
final Item it = itemstack.getItem();
if( it instanceof IUpgradeModule )
{
final Upgrades u = ( (IUpgradeModule) it ).getType( itemstack );
if( u != null )
{
return this.getInstalledUpgrades( u ) < this.getMaxInstalled( u );
}
}
return false;
}
public int getInstalledUpgrades( final Upgrades u )
{
if( !this.cached )
@@ -171,7 +148,7 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
this.cached = false;
if( this.parent != null && Platform.isServer() )
@@ -179,4 +156,33 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
this.parent.onChangeInventory( inv, slot, mc, removedStack, newStack );
}
}
private class UpgradeInvFilter implements IAEItemFilter
{
@Override
public boolean allowExtract( IItemHandler inv, int slot, int amount )
{
return true;
}
@Override
public boolean allowInsert( IItemHandler inv, int slot, ItemStack itemstack )
{
if( itemstack.isEmpty() )
{
return false;
}
final Item it = itemstack.getItem();
if( it instanceof IUpgradeModule )
{
final Upgrades u = ( (IUpgradeModule) it ).getType( itemstack );
if( u != null )
{
return getInstalledUpgrades( u ) < getMaxInstalled( u );
}
}
return false;
}
}
}
@@ -25,8 +25,6 @@ import java.util.List;
import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -35,8 +33,8 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Actionable;
import appeng.api.config.Upgrades;
@@ -67,13 +65,13 @@ import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.parts.PartBasicState;
import appeng.parts.PartModel;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.IInventoryDestination;
import appeng.util.inv.InvOperation;
public class PartInterface extends PartBasicState implements IGridTickable, IStorageMonitorable, IInventoryDestination, IInterfaceHost, ISidedInventory, IAEAppEngInventory, IPriorityHost
public class PartInterface extends PartBasicState implements IGridTickable, IStorageMonitorable, IInventoryDestination, IInterfaceHost, IAEAppEngInventory, IPriorityHost
{
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/interface_base" );
@@ -166,7 +164,7 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
return this.duality.getInventoryByName( name );
}
@@ -218,103 +216,7 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto
}
@Override
public int getSizeInventory()
{
return this.duality.getStorage().getSizeInventory();
}
@Override
public ItemStack getStackInSlot( final int i )
{
return this.duality.getStorage().getStackInSlot( i );
}
@Override
public ItemStack decrStackSize( final int i, final int j )
{
return this.duality.getStorage().decrStackSize( i, j );
}
@Override
public ItemStack removeStackFromSlot( final int i )
{
return this.duality.getStorage().removeStackFromSlot( i );
}
@Override
public void setInventorySlotContents( final int i, final ItemStack itemstack )
{
this.duality.getStorage().setInventorySlotContents( i, itemstack );
}
@Override
public String getName()
{
return this.duality.getStorage().getName();
}
@Override
public boolean hasCustomName()
{
return this.duality.getStorage().hasCustomName();
}
@Override
public int getInventoryStackLimit()
{
return this.duality.getStorage().getInventoryStackLimit();
}
@Override
public void markDirty()
{
this.duality.getStorage().markDirty();
}
@Override
public boolean isUsableByPlayer( final EntityPlayer entityplayer )
{
return this.duality.getStorage().isUsableByPlayer( entityplayer );
}
@Override
public void openInventory( final EntityPlayer player )
{
this.duality.getStorage().openInventory( player );
}
@Override
public void closeInventory( final EntityPlayer player )
{
this.duality.getStorage().closeInventory( player );
}
@Override
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
{
return this.duality.getStorage().isItemValidForSlot( i, itemstack );
}
@Override
public int[] getSlotsForFace( final EnumFacing side )
{
return this.duality.getSlotsForFace( side );
}
@Override
public boolean canInsertItem( final int i, final ItemStack itemstack, final EnumFacing j )
{
return true;
}
@Override
public boolean canExtractItem( final int i, final ItemStack itemstack, final EnumFacing j )
{
return true;
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
this.duality.onChangeInventory( inv, slot, mc, removedStack, newStack );
}
@@ -385,36 +287,6 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto
this.duality.setPriority( newValue );
}
@Override
public int getField( final int id )
{
return 0;
}
@Override
public void setField( final int id, final int value )
{
}
@Override
public int getFieldCount()
{
return 0;
}
@Override
public void clear()
{
}
@Override
public ITextComponent getDisplayName()
{
return null;
}
@Override
public IPartModel getStaticModels()
{
@@ -443,12 +315,4 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto
{
return this.duality.getCapability( capabilityClass, this.getSide().getFacing() );
}
@Override
public boolean isEmpty()
{
// TODO Auto-generated method stub
return false;
}
}
@@ -24,7 +24,6 @@ import java.util.Collections;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@@ -85,8 +84,8 @@ import appeng.me.storage.MEMonitorIInventory;
import appeng.parts.PartModel;
import appeng.parts.automation.PartUpgradeable;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.prioritylist.FuzzyPriorityList;
import appeng.util.prioritylist.PrecisePriorityList;
@@ -170,7 +169,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
@@ -204,7 +203,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "config" ) )
{
@@ -449,7 +448,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
final int slotsToUse = 18 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
for( int x = 0; x < this.Config.getSizeInventory() && x < slotsToUse; x++ )
for( int x = 0; x < this.Config.getSlots() && x < slotsToUse; x++ )
{
final IAEItemStack is = this.Config.getAEStackInSlot( x );
if( is != null )
@@ -1,21 +1,19 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
*
* * This file is part of Applied Energistics 2.
* * Copyright (c) 2013 - 2017, 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>.
* 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.parts.p2p;
@@ -30,7 +28,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import appeng.api.config.PowerUnits;
+50 -267
View File
@@ -19,22 +19,16 @@
package appeng.parts.p2p;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.EmptyHandler;
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkBootingStatusChange;
@@ -49,19 +43,15 @@ import appeng.core.settings.TickRates;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.cache.helpers.TunnelCollection;
import appeng.tile.inventory.AppEngNullInventory;
import appeng.util.Platform;
import appeng.util.inv.AdaptorIInventory;
import appeng.util.inv.WrapperChainedInventory;
import appeng.util.inv.WrapperMCISidedInventory;
import appeng.util.inv.WrapperChainedItemHandler;
// TODO: BC Integration
//@Interface( iface = "buildcraft.api.transport.IPipeConnection", iname = IntegrationType.BuildCraftTransport )
public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPipeConnection, */ISidedInventory, IGridTickable, IItemHandler
public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IItemHandler, IGridTickable
{
private static final float POWER_DRAIN = 2.0f;
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_items" );
private boolean partVisited = false;
@PartModels
public static List<IPartModel> getModels()
@@ -69,10 +59,9 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
return MODELS.getModels();
}
private final LinkedList<IInventory> which = new LinkedList<>();
private int oldSize = 0;
private boolean requested;
private IInventory cachedInv;
private IItemHandler cachedInv;
public PartP2PItems( final ItemStack is )
{
@@ -90,7 +79,7 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
}
}
private IInventory getDestination()
private IItemHandler getDestination()
{
this.requested = true;
@@ -99,7 +88,7 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
return this.cachedInv;
}
final List<IInventory> outs = new LinkedList<>();
final List<IItemHandler> outs = new ArrayList<IItemHandler>();
final TunnelCollection<PartP2PItems> itemTunnels;
try
@@ -108,13 +97,13 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
}
catch( final GridAccessException e )
{
return new AppEngNullInventory();
return EmptyHandler.INSTANCE;
}
for( final PartP2PItems t : itemTunnels )
{
final IInventory inv = t.getOutputInv();
if( inv != null )
final IItemHandler inv = t.getOutputInv();
if( inv != null && inv != this )
{
if( Platform.getRandomInt() % 2 == 0 )
{
@@ -127,44 +116,28 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
}
}
return this.cachedInv = new WrapperChainedInventory( outs );
return this.cachedInv = new WrapperChainedItemHandler( outs.toArray( new IItemHandler[outs.size()] ) );
}
private IInventory getOutputInv()
private IItemHandler getOutputInv()
{
IInventory output = null;
if( this.getProxy().isActive() )
IItemHandler ret = null;
if( !partVisited )
{
final TileEntity te = this.getTile().getWorld().getTileEntity( this.getTile().getPos().offset( this.getSide().getFacing() ) );
if( this.which.contains( this ) )
partVisited = true;
if( this.getProxy().isActive() )
{
return null;
}
final EnumFacing facing = this.getSide().getFacing();
final TileEntity te = this.getTile().getWorld().getTileEntity( this.getTile().getPos().offset( facing ) );
this.which.add( this );
if( output == null )
{
if( te instanceof TileEntityChest )
if( te != null && te.hasCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite() ) )
{
output = Platform.GetChestInv( te );
}
else if( te instanceof ISidedInventory )
{
output = new WrapperMCISidedInventory( (ISidedInventory) te, this.getSide().getFacing().getOpposite() );
}
else if( te instanceof IInventory )
{
output = (IInventory) te;
ret = te.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite() );
}
}
this.which.pop();
partVisited = false;
}
return output;
return ret;
}
@Override
@@ -180,7 +153,7 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
if( this.requested && this.cachedInv != null )
{
( (WrapperChainedInventory) this.cachedInv ).cycleOrder();
( (WrapperChainedItemHandler) this.cachedInv ).cycleOrder();
}
this.requested = false;
@@ -194,7 +167,7 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
{
this.cachedInv = null;
final int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSizeInventory();
this.oldSize = this.getDestination().getSlots();
if( olderSize != this.oldSize )
{
this.getHost().notifyNeighbors();
@@ -209,7 +182,7 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
{
this.cachedInv = null;
final int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSizeInventory();
this.oldSize = this.getDestination().getSlots();
if( olderSize != this.oldSize )
{
this.getHost().notifyNeighbors();
@@ -224,7 +197,7 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
{
this.cachedInv = null;
final int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSizeInventory();
this.oldSize = this.getDestination().getSlots();
if( olderSize != this.oldSize )
{
this.getHost().notifyNeighbors();
@@ -239,7 +212,7 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
{
this.cachedInv = null;
final int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSizeInventory();
this.oldSize = this.getDestination().getSlots();
if( olderSize != this.oldSize )
{
this.getHost().notifyNeighbors();
@@ -255,164 +228,6 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
}
}
@Override
public int[] getSlotsForFace( final EnumFacing side )
{
final int[] slots = new int[this.getSizeInventory()];
for( int x = 0; x < this.getSizeInventory(); x++ )
{
slots[x] = x;
}
return slots;
}
@Override
public int getSizeInventory()
{
return this.getDestination().getSizeInventory();
}
/**
* Returns the number of slots available
*
* @return The number of slots available
**/
@Override
public int getSlots()
{
return this.getSizeInventory();
}
@Override
public ItemStack getStackInSlot( final int i )
{
return this.getDestination().getStackInSlot( i );
}
/**
* Inserts an ItemStack into the given slot and return the remainder.
* The ItemStack should not be modified in this function!
* Note: This behaviour is subtly different from IFluidHandlers.fill()
*
* @param slot Slot to insert into.
* @param stack ItemStack to insert.
* @param simulate If true, the insertion is only simulated
* @return The remaining ItemStack that was not inserted (if the entire stack is accepted, then return
* ItemStack.EMPTY).
* May be the same as the input ItemStack if unchanged, otherwise a new ItemStack.
**/
@Nonnull
@Override
public ItemStack insertItem( int slot, @Nonnull ItemStack stack, boolean simulate )
{
if( this.isItemValidForSlot( slot, stack ) )
{
AdaptorIInventory adaptor = new AdaptorIInventory( this.getDestination() );
if( simulate )
{
return adaptor.simulateAdd( stack );
}
else
{
return adaptor.addItems( stack );
}
}
return stack;
}
/**
* Extracts an ItemStack from the given slot. The returned value must be null
* if nothing is extracted, otherwise it's stack size must not be greater than amount or the
* itemstacks getMaxStackSize().
*
* @param slot Slot to extract from.
* @param amount Amount to extract (may be greater than the current stacks max limit)
* @param simulate If true, the extraction is only simulated
* @return ItemStack extracted from the slot, must be ItemStack.EMPTY, if nothing can be extracted
**/
@Nonnull
@Override
public ItemStack extractItem( int slot, int amount, boolean simulate )
{
return ItemStack.EMPTY;
}
/**
* Retrieves the maximum stack size allowed to exist in the given slot.
*
* @param slot Slot to query.
* @return The maximum stack size allowed in the slot.
*/
@Override
public int getSlotLimit( int slot )
{
if( slot >= 0 && slot < this.getDestination().getSizeInventory() )
{
return this.getDestination().getInventoryStackLimit();
}
return 0;
}
@Override
public ItemStack decrStackSize( final int i, final int j )
{
return this.getDestination().decrStackSize( i, j );
}
@Override
public ItemStack removeStackFromSlot( final int i )
{
return ItemStack.EMPTY;
}
@Override
public void setInventorySlotContents( final int i, final ItemStack itemstack )
{
this.getDestination().setInventorySlotContents( i, itemstack );
}
@Override
public String getName()
{
return null;
}
@Override
public boolean hasCustomName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return this.getDestination().getInventoryStackLimit();
}
@Override
public void markDirty()
{
// eh?
}
@Override
public boolean isUsableByPlayer( final EntityPlayer entityplayer )
{
return false;
}
@Override
public void openInventory( final EntityPlayer p )
{
}
@Override
public void closeInventory( final EntityPlayer p )
{
}
@Override
public boolean hasCapability( Capability<?> capabilityClass )
{
@@ -424,6 +239,7 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
return super.hasCapability( capabilityClass );
}
@SuppressWarnings( "unchecked" )
@Override
public <T> T getCapability( Capability<T> capabilityClass )
{
@@ -436,76 +252,43 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
}
@Override
public boolean isItemValidForSlot( final int i, final net.minecraft.item.ItemStack itemstack )
public int getSlots()
{
return this.getDestination().isItemValidForSlot( i, itemstack );
return this.getDestination().getSlots();
}
@Override
public boolean canInsertItem( final int i, final ItemStack itemstack, final EnumFacing j )
public ItemStack getStackInSlot( final int i )
{
return this.getDestination().isItemValidForSlot( i, itemstack );
return this.getDestination().getStackInSlot( i );
}
@Override
public boolean canExtractItem( final int i, final ItemStack itemstack, final EnumFacing j )
public ItemStack insertItem( final int slot, final ItemStack stack, boolean simulate )
{
return false;
return this.getDestination().insertItem( slot, stack, simulate );
}
@Override
public ItemStack extractItem( final int slot, final int amount, boolean simulate )
{
return this.getDestination().extractItem( slot, amount, simulate );
}
@Override
public int getSlotLimit( int slot )
{
return this.getDestination().getSlotLimit( slot );
}
public float getPowerDrainPerTick()
{
return 2.0f;
}
@Override
public int getField( final int id )
{
return 0;
}
// @Override
// @Method( iname = IntegrationType.BuildCraftTransport )
// public ConnectOverride overridePipeConnection( PipeType type, ForgeDirection with )
// {
// return 0;
// }
@Override
public void setField( final int id, final int value )
{
}
@Override
public int getFieldCount()
{
return 0;
}
@Override
public void clear()
{
// probably not...
}
@Override
public ITextComponent getDisplayName()
{
return null;
return POWER_DRAIN;
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( this.isPowered(), this.isActive() );
return MODELS.getModel( isPowered(), isActive() );
}
@Override
public boolean isEmpty()
{
// TODO Auto-generated method stub
return false;
}
}
@@ -22,11 +22,11 @@ package appeng.parts.reporting;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Settings;
import appeng.api.config.SortDir;
@@ -41,11 +41,11 @@ import appeng.api.util.IConfigManager;
import appeng.core.sync.GuiBridge;
import appeng.me.GridAccessException;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
/**
@@ -170,13 +170,13 @@ public abstract class AbstractPartTerminal extends AbstractPartDisplay implement
}
@Override
public IInventory getViewCellStorage()
public IItemHandler getViewCellStorage()
{
return this.viewCell;
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
this.getHost().markForSave();
}
@@ -25,7 +25,6 @@ import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
@@ -162,7 +161,7 @@ public class PartConversionMonitor extends AbstractPartMonitor
if( retrieved != null )
{
ItemStack newItems = retrieved.getItemStack();
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor( player, EnumFacing.UP );
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor( player );
newItems = adaptor.addItems( newItems );
if( !newItems.isEmpty() )
{
@@ -22,10 +22,10 @@ package appeng.parts.reporting;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.items.IItemHandler;
import appeng.api.parts.IPartModel;
import appeng.core.AppEng;
@@ -105,7 +105,7 @@ public class PartCraftingTerminal extends AbstractPartTerminal
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "crafting" ) )
{
@@ -22,10 +22,10 @@ package appeng.parts.reporting;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.items.IItemHandler;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.networking.crafting.ICraftingPatternDetails;
@@ -37,7 +37,7 @@ import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.parts.PartModel;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.inv.InvOperation;
public class PartPatternTerminal extends AbstractPartTerminal
@@ -120,7 +120,7 @@ public class PartPatternTerminal extends AbstractPartTerminal
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
if( inv == this.pattern && slot == 1 )
{
@@ -134,16 +134,16 @@ public class PartPatternTerminal extends AbstractPartTerminal
this.setCraftingRecipe( details.isCraftable() );
this.setSubstitution( details.canSubstitute() );
for( int x = 0; x < this.crafting.getSizeInventory() && x < details.getInputs().length; x++ )
for( int x = 0; x < this.crafting.getSlots() && x < details.getInputs().length; x++ )
{
final IAEItemStack item = details.getInputs()[x];
this.crafting.setInventorySlotContents( x, item == null ? ItemStack.EMPTY : item.getItemStack() );
this.crafting.setStackInSlot( x, item == null ? ItemStack.EMPTY : item.getItemStack() );
}
for( int x = 0; x < this.output.getSizeInventory() && x < details.getOutputs().length; x++ )
for( int x = 0; x < this.output.getSlots() && x < details.getOutputs().length; x++ )
{
final IAEItemStack item = details.getOutputs()[x];
this.output.setInventorySlotContents( x, item == null ? ItemStack.EMPTY : item.getItemStack() );
this.output.setStackInSlot( x, item == null ? ItemStack.EMPTY : item.getItemStack() );
}
}
}
@@ -160,7 +160,7 @@ public class PartPatternTerminal extends AbstractPartTerminal
{
if( this.craftingMode )
{
for( int x = 0; x < this.crafting.getSizeInventory(); x++ )
for( int x = 0; x < this.crafting.getSlots(); x++ )
{
final ItemStack is = this.crafting.getStackInSlot( x );
if( !is.isEmpty() )
@@ -193,7 +193,7 @@ public class PartPatternTerminal extends AbstractPartTerminal
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "crafting" ) )
{
@@ -232,7 +232,7 @@ public class RecipeResourceCopier
{
final Enumeration<JarEntry> entries = jar.entries(); // gives ALL entries in jar
final Collection<String> result = new HashSet<>( INITIAL_RESOURCE_CAPACITY ); // avoid
// duplicates
// duplicates
// in case it is a
// subdirectory
+64 -172
View File
@@ -19,223 +19,119 @@
package appeng.tile;
import java.util.EnumMap;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import net.minecraftforge.items.wrapper.EmptyHandler;
import appeng.block.AEBaseBlock;
import appeng.tile.events.TileEventType;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
public abstract class AEBaseInvTile extends AEBaseTile implements ISidedInventory, IAEAppEngInventory
public abstract class AEBaseInvTile extends AEBaseTile implements IAEAppEngInventory
{
private EnumMap<EnumFacing, IItemHandler> sidedItemHandler = new EnumMap<>( EnumFacing.class );
private IItemHandler itemHandler;
@Override
public String getName()
{
return this.getCustomInventoryName();
}
@TileEvent( TileEventType.WORLD_NBT_READ )
public void readFromNBT_AEBaseInvTile( final net.minecraft.nbt.NBTTagCompound data )
{
final IInventory inv = this.getInternalInventory();
final NBTTagCompound opt = data.getCompoundTag( "inv" );
for( int x = 0; x < inv.getSizeInventory(); x++ )
final IItemHandler inv = this.getInternalInventory();
if( inv != EmptyHandler.INSTANCE )
{
final NBTTagCompound item = opt.getCompoundTag( "item" + x );
inv.setInventorySlotContents( x, new ItemStack( item ) );
final NBTTagCompound opt = data.getCompoundTag( "inv" );
for( int x = 0; x < inv.getSlots(); x++ )
{
final NBTTagCompound item = opt.getCompoundTag( "item" + x );
ItemHandlerUtil.setStackInSlot( inv, x, new ItemStack( item ) );
}
}
}
public abstract IInventory getInternalInventory();
public abstract @Nonnull IItemHandler getInternalInventory();
@TileEvent( TileEventType.WORLD_NBT_WRITE )
public void writeToNBT_AEBaseInvTile( final net.minecraft.nbt.NBTTagCompound data )
{
final IInventory inv = this.getInternalInventory();
final NBTTagCompound opt = new NBTTagCompound();
for( int x = 0; x < inv.getSizeInventory(); x++ )
final IItemHandler inv = this.getInternalInventory();
if( inv != EmptyHandler.INSTANCE )
{
final NBTTagCompound item = new NBTTagCompound();
final ItemStack is = this.getStackInSlot( x );
final NBTTagCompound opt = new NBTTagCompound();
for( int x = 0; x < inv.getSlots(); x++ )
{
final NBTTagCompound item = new NBTTagCompound();
final ItemStack is = inv.getStackInSlot( x );
if( !is.isEmpty() )
{
is.writeToNBT( item );
}
opt.setTag( "item" + x, item );
}
data.setTag( "inv", opt );
}
}
@Override
public void getDrops( final World w, final BlockPos pos, final List<ItemStack> drops )
{
final IItemHandler inv = getInternalInventory();
for( int l = 0; l < inv.getSlots(); l++ )
{
final ItemStack is = inv.getStackInSlot( l );
if( !is.isEmpty() )
{
is.writeToNBT( item );
drops.add( is );
}
opt.setTag( "item" + x, item );
}
data.setTag( "inv", opt );
}
@Override
public int getSizeInventory()
{
return this.getInternalInventory().getSizeInventory();
}
@Override
public ItemStack getStackInSlot( final int i )
{
return this.getInternalInventory().getStackInSlot( i );
}
@Override
public ItemStack decrStackSize( final int i, final int j )
{
return this.getInternalInventory().decrStackSize( i, j );
}
@Override
public ItemStack removeStackFromSlot( final int i )
{
return ItemStack.EMPTY;
}
@Override
public void setInventorySlotContents( final int i, @Nullable final ItemStack itemstack )
{
this.getInternalInventory().setInventorySlotContents( i, itemstack );
}
/**
* Returns if the inventory is named
*/
@Override
public boolean hasCustomInventoryName()
{
return super.hasCustomInventoryName();
}
@Override
public boolean hasCustomName()
{
return this.hasCustomInventoryName();
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
@Override
public boolean isUsableByPlayer( final EntityPlayer p )
{
final double squaredMCReach = 64.0D;
return this.world.getTileEntity( this.pos ) == this && p.getDistanceSq( this.pos.getX() + 0.5D, this.pos.getY() + 0.5D,
this.pos.getZ() + 0.5D ) <= squaredMCReach;
}
@Override
public void openInventory( final EntityPlayer player )
{
}
;
@Override
public void closeInventory( final EntityPlayer player )
{
}
@Override
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
{
return true;
}
@Override
public abstract void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added );
@Override
public int[] getSlotsForFace( final EnumFacing side )
{
final Block blk = this.world.getBlockState( this.pos ).getBlock();
if( blk instanceof AEBaseBlock )
{
return this.getAccessibleSlotsBySide( ( (AEBaseBlock) blk ).mapRotation( this, side ) );
}
return this.getAccessibleSlotsBySide( side );
}
@Override
public boolean canInsertItem( final int slotIndex, final ItemStack insertingItem, final EnumFacing side )
{
return this.isItemValidForSlot( slotIndex, insertingItem );
}
@Override
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final EnumFacing side )
{
return true;
}
@Override
public void clear()
{
this.getInternalInventory().clear();
}
@Override
public int getField( final int id )
{
return 0;
}
@Override
public void setField( final int id, final int value )
{
}
@Override
public int getFieldCount()
{
return 0;
}
public abstract void onChangeInventory( IItemHandler inv, int slot, InvOperation mc, ItemStack removed, ItemStack added );
@Override
public ITextComponent getDisplayName()
{
if( this.hasCustomName() )
if( this.hasCustomInventoryName() )
{
return new TextComponentString( this.getCustomInventoryName() );
}
return new TextComponentTranslation( this.getBlockType().getUnlocalizedName() );
}
public abstract int[] getAccessibleSlotsBySide( EnumFacing whichSide );
protected @Nonnull IItemHandler getItemHandlerForSide( @Nonnull EnumFacing side )
{
return getInternalInventory();
}
@Override
public boolean hasCapability( Capability<?> capability, EnumFacing facing )
{
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability( capability, facing );
if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
{
if( facing == null )
{
return getInternalInventory() != EmptyHandler.INSTANCE;
}
else
{
return getItemHandlerForSide( facing ) != EmptyHandler.INSTANCE;
}
}
return super.hasCapability( capability, facing );
}
@SuppressWarnings( "unchecked" )
@@ -246,15 +142,11 @@ public abstract class AEBaseInvTile extends AEBaseTile implements ISidedInventor
{
if( facing == null )
{
if( this.itemHandler == null )
{
this.itemHandler = new InvWrapper( this.getInternalInventory() );
}
return (T) this.itemHandler;
return (T) getInternalInventory();
}
else
{
return (T) this.sidedItemHandler.computeIfAbsent( facing, side -> new SidedInvWrapper( this, side ) );
return (T) getItemHandlerForSide( facing );
}
}
return super.getCapability( capability, facing );
+6 -18
View File
@@ -36,7 +36,6 @@ import io.netty.buffer.Unpooled;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
@@ -45,6 +44,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.implementations.tiles.ISegmentedInventory;
import appeng.api.util.ICommonTile;
@@ -508,15 +508,15 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
if( this instanceof ISegmentedInventory )
{
final IInventory inv = ( (ISegmentedInventory) this ).getInventoryByName( "config" );
final IItemHandler inv = ( (ISegmentedInventory) this ).getInventoryByName( "config" );
if( inv instanceof AppEngInternalAEInventory )
{
final AppEngInternalAEInventory target = (AppEngInternalAEInventory) inv;
final AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSizeInventory() );
final AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSlots() );
tmp.readFromNBT( compound, "config" );
for( int x = 0; x < tmp.getSizeInventory(); x++ )
for( int x = 0; x < tmp.getSlots(); x++ )
{
target.setInventorySlotContents( x, tmp.getStackInSlot( x ) );
target.setStackInSlot( x, tmp.getStackInSlot( x ) );
}
}
}
@@ -534,19 +534,7 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
@Override
public void getDrops( final World w, final BlockPos pos, final List<ItemStack> drops )
{
if( this instanceof IInventory )
{
final IInventory inv = (IInventory) this;
for( int l = 0; l < inv.getSizeInventory(); l++ )
{
final ItemStack is = inv.getStackInSlot( l );
if( !is.isEmpty() )
{
drops.add( is );
}
}
}
}
public void getNoDrops( final World w, final BlockPos pos, final List<ItemStack> drops )
@@ -594,7 +582,7 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
if( this instanceof ISegmentedInventory )
{
final IInventory inv = ( (ISegmentedInventory) this ).getInventoryByName( "config" );
final IItemHandler inv = ( (ISegmentedInventory) this ).getInventoryByName( "config" );
if( inv instanceof AppEngInternalAEInventory )
{
( (AppEngInternalAEInventory) inv ).writeToNBT( output, "config" );

Some files were not shown because too many files have changed in this diff Show More