2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile;
|
|
|
|
|
2014-03-14 03:59:37 +01:00
|
|
|
import net.minecraft.block.Block;
|
2013-12-27 23:59:59 +01:00
|
|
|
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;
|
2014-03-14 03:59:37 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
import appeng.block.AEBaseBlock;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.tile.events.AETileEventHandler;
|
|
|
|
import appeng.tile.events.TileEventType;
|
|
|
|
import appeng.tile.inventory.IAEAppEngInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
|
|
|
|
|
|
|
public abstract class AEBaseInvTile extends AEBaseTile implements ISidedInventory, IAEAppEngInventory
|
|
|
|
{
|
|
|
|
|
|
|
|
public AEBaseInvTile() {
|
2014-01-26 07:46:16 +01:00
|
|
|
addNewHandler( new AETileEventHandler( TileEventType.WORLD_NBT ) {
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(net.minecraft.nbt.NBTTagCompound data)
|
|
|
|
{
|
|
|
|
IInventory inv = getInternalInventory();
|
|
|
|
NBTTagCompound opt = data.getCompoundTag( "inv" );
|
|
|
|
for (int x = 0; x < inv.getSizeInventory(); x++)
|
|
|
|
{
|
|
|
|
NBTTagCompound item = opt.getCompoundTag( "item" + x );
|
|
|
|
inv.setInventorySlotContents( x, ItemStack.loadItemStackFromNBT( item ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(net.minecraft.nbt.NBTTagCompound data)
|
|
|
|
{
|
|
|
|
IInventory inv = getInternalInventory();
|
|
|
|
NBTTagCompound opt = new NBTTagCompound();
|
|
|
|
for (int x = 0; x < inv.getSizeInventory(); x++)
|
|
|
|
{
|
|
|
|
NBTTagCompound item = new NBTTagCompound();
|
|
|
|
ItemStack is = getStackInSlot( x );
|
|
|
|
if ( is != null )
|
|
|
|
is.writeToNBT( item );
|
2014-02-09 02:34:52 +01:00
|
|
|
opt.setTag( "item" + x, item );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
data.setTag( "inv", opt );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSizeInventory()
|
|
|
|
{
|
|
|
|
return getInternalInventory().getSizeInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlot(int i)
|
|
|
|
{
|
|
|
|
return getInternalInventory().getStackInSlot( i );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack decrStackSize(int i, int j)
|
|
|
|
{
|
|
|
|
return getInternalInventory().decrStackSize( i, j );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlotOnClosing(int i)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInventorySlotContents(int i, ItemStack itemstack)
|
|
|
|
{
|
|
|
|
getInternalInventory().setInventorySlotContents( i, itemstack );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public String getInventoryName()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return getClass().getSimpleName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public boolean hasCustomInventoryName()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void openInventory()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void closeInventory()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public int getInventoryStackLimit()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
return 64;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public boolean isUseableByPlayer(EntityPlayer p)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
return this.worldObj.getTileEntity( this.xCoord, this.yCoord, this.zCoord ) != this ? false : p.getDistanceSq( (double) this.xCoord + 0.5D,
|
|
|
|
(double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D ) <= 32.0D;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canInsertItem(int i, ItemStack itemstack, int j)
|
|
|
|
{
|
|
|
|
return isItemValidForSlot( i, itemstack );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract IInventory getInternalInventory();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public abstract void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added);
|
|
|
|
|
2014-03-14 03:59:37 +01:00
|
|
|
public abstract int[] getAccessibleSlotsBySide(ForgeDirection whichSide);
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-03-14 03:59:37 +01:00
|
|
|
@Override
|
|
|
|
final public int[] getAccessibleSlotsFromSide(int side)
|
|
|
|
{
|
|
|
|
Block blk = worldObj.getBlock( xCoord, yCoord, zCoord );
|
|
|
|
if ( blk instanceof AEBaseBlock )
|
|
|
|
{
|
|
|
|
ForgeDirection mySide = ForgeDirection.getOrientation( side );
|
|
|
|
return getAccessibleSlotsBySide( ((AEBaseBlock) blk).mapRotation( this, mySide ) );
|
|
|
|
}
|
|
|
|
return getAccessibleSlotsBySide( ForgeDirection.getOrientation( side ) );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|