2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
package appeng.tile;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
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.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.block.AEBaseBlock;
|
|
|
|
import appeng.tile.events.TileEventType;
|
|
|
|
import appeng.tile.inventory.IAEAppEngInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
public abstract class AEBaseInvTile extends AEBaseTile implements ISidedInventory, IAEAppEngInventory
|
|
|
|
{
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@TileEvent( TileEventType.WORLD_NBT_READ )
|
|
|
|
public void readFromNBT_AEBaseInvTile( net.minecraft.nbt.NBTTagCompound data )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IInventory inv = this.getInternalInventory();
|
2014-09-24 02:26:27 +02:00
|
|
|
NBTTagCompound opt = data.getCompoundTag( "inv" );
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < inv.getSizeInventory(); x++ )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
NBTTagCompound item = opt.getCompoundTag( "item" + x );
|
|
|
|
inv.setInventorySlotContents( x, ItemStack.loadItemStackFromNBT( item ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public abstract IInventory getInternalInventory();
|
|
|
|
|
|
|
|
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
|
|
|
public void writeToNBT_AEBaseInvTile( net.minecraft.nbt.NBTTagCompound data )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IInventory inv = this.getInternalInventory();
|
2014-09-24 02:26:27 +02:00
|
|
|
NBTTagCompound opt = new NBTTagCompound();
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < inv.getSizeInventory(); x++ )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
NBTTagCompound item = new NBTTagCompound();
|
2014-12-29 15:13:47 +01:00
|
|
|
ItemStack is = this.getStackInSlot( x );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
is.writeToNBT( item );
|
|
|
|
opt.setTag( "item" + x, item );
|
|
|
|
}
|
|
|
|
data.setTag( "inv", opt );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSizeInventory()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getInternalInventory().getSizeInventory();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public ItemStack getStackInSlot( int i )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getInternalInventory().getStackInSlot( i );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public ItemStack decrStackSize( int i, int j )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getInternalInventory().decrStackSize( i, j );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public ItemStack getStackInSlotOnClosing( int i )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void setInventorySlotContents( int i, ItemStack itemstack )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.getInternalInventory().setInventorySlotContents( i, itemstack );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
/**
|
|
|
|
* Returns the name of the inventory
|
|
|
|
*/
|
2014-09-24 02:26:27 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public String getInventoryName()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.getCustomName();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
/**
|
|
|
|
* Returns if the inventory is named
|
|
|
|
*/
|
2014-09-24 02:26:27 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean hasCustomInventoryName()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.hasCustomName();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit()
|
|
|
|
{
|
|
|
|
return 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean isUseableByPlayer( EntityPlayer p )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-10 08:38:17 +01:00
|
|
|
final double squaredMCReach = 64.0D;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.worldObj.getTileEntity( this.xCoord, this.yCoord, this.zCoord ) == this && p.getDistanceSq( this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D ) <= squaredMCReach;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void openInventory()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void closeInventory()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean isItemValidForSlot( int i, ItemStack itemstack )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public abstract void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
final public int[] getAccessibleSlotsFromSide( int side )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
Block blk = this.worldObj.getBlock( this.xCoord, this.yCoord, this.zCoord );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( blk instanceof AEBaseBlock )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
ForgeDirection mySide = ForgeDirection.getOrientation( side );
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.getAccessibleSlotsBySide( ( (AEBaseBlock) blk ).mapRotation( this, mySide ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getAccessibleSlotsBySide( ForgeDirection.getOrientation( side ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean canInsertItem( int slotIndex, ItemStack insertingItem, int side )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.isItemValidForSlot( slotIndex, insertingItem );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean canExtractItem( int slotIndex, ItemStack extractedItem, int side )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return true;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public abstract int[] getAccessibleSlotsBySide( ForgeDirection whichSide );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|