219 lines
5.2 KiB
Java
219 lines
5.2 KiB
Java
/*
|
|
* This file is part of Applied Energistics 2.
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
*
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
*/
|
|
|
|
package appeng.tile;
|
|
|
|
|
|
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.ChatComponentText;
|
|
import net.minecraft.util.ChatComponentTranslation;
|
|
import net.minecraft.util.EnumFacing;
|
|
import net.minecraft.util.IChatComponent;
|
|
import appeng.block.AEBaseBlock;
|
|
import appeng.tile.events.TileEventType;
|
|
import appeng.tile.inventory.IAEAppEngInventory;
|
|
import appeng.tile.inventory.InvOperation;
|
|
|
|
|
|
public abstract class AEBaseInvTile extends AEBaseTile implements ISidedInventory, IAEAppEngInventory
|
|
{
|
|
|
|
@TileEvent( TileEventType.WORLD_NBT_READ )
|
|
public void readFromNBT_AEBaseInvTile( net.minecraft.nbt.NBTTagCompound data )
|
|
{
|
|
IInventory inv = this.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 ) );
|
|
}
|
|
}
|
|
|
|
public abstract IInventory getInternalInventory();
|
|
|
|
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
|
public void writeToNBT_AEBaseInvTile( net.minecraft.nbt.NBTTagCompound data )
|
|
{
|
|
IInventory inv = this.getInternalInventory();
|
|
NBTTagCompound opt = new NBTTagCompound();
|
|
for( int x = 0; x < inv.getSizeInventory(); x++ )
|
|
{
|
|
NBTTagCompound item = new NBTTagCompound();
|
|
ItemStack is = this.getStackInSlot( x );
|
|
if( is != null )
|
|
{
|
|
is.writeToNBT( item );
|
|
}
|
|
opt.setTag( "item" + x, item );
|
|
}
|
|
data.setTag( "inv", opt );
|
|
}
|
|
|
|
@Override
|
|
public int getSizeInventory()
|
|
{
|
|
return this.getInternalInventory().getSizeInventory();
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getStackInSlot( int i )
|
|
{
|
|
return this.getInternalInventory().getStackInSlot( i );
|
|
}
|
|
|
|
@Override
|
|
public ItemStack decrStackSize( int i, int j )
|
|
{
|
|
return this.getInternalInventory().decrStackSize( i, j );
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getStackInSlotOnClosing( int i )
|
|
{
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public void setInventorySlotContents( int i, @Nullable ItemStack itemstack )
|
|
{
|
|
this.getInternalInventory().setInventorySlotContents( i, itemstack );
|
|
}
|
|
|
|
/**
|
|
* Returns the name of the inventory
|
|
*/
|
|
@Override
|
|
public String getName()
|
|
{
|
|
return this.getCustomName();
|
|
}
|
|
|
|
/**
|
|
* Returns if the inventory is named
|
|
*/
|
|
@Override
|
|
public boolean hasCustomName()
|
|
{
|
|
return getInternalInventory().hasCustomName();
|
|
}
|
|
|
|
@Override
|
|
public int getInventoryStackLimit()
|
|
{
|
|
return 64;
|
|
}
|
|
|
|
@Override
|
|
public boolean isUseableByPlayer( EntityPlayer p )
|
|
{
|
|
final double squaredMCReach = 64.0D;
|
|
|
|
return this.worldObj.getTileEntity( pos ) == this && p.getDistanceSq( pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D ) <= squaredMCReach;
|
|
}
|
|
|
|
@Override
|
|
public void openInventory(EntityPlayer player) {
|
|
|
|
};
|
|
|
|
@Override
|
|
public void closeInventory(
|
|
EntityPlayer player )
|
|
{
|
|
|
|
}
|
|
|
|
@Override
|
|
public boolean isItemValidForSlot( int i, ItemStack itemstack )
|
|
{
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public abstract void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added );
|
|
|
|
@Override
|
|
public int[] getSlotsForFace(
|
|
EnumFacing side )
|
|
{
|
|
Block blk = this.worldObj.getBlockState( pos ).getBlock();
|
|
if( blk instanceof AEBaseBlock )
|
|
{
|
|
return this.getAccessibleSlotsBySide( ( (AEBaseBlock) blk ).mapRotation( this, side ) );
|
|
}
|
|
return this.getAccessibleSlotsBySide( side );
|
|
}
|
|
|
|
@Override
|
|
public boolean canInsertItem( int slotIndex, ItemStack insertingItem, EnumFacing side )
|
|
{
|
|
return this.isItemValidForSlot( slotIndex, insertingItem );
|
|
}
|
|
|
|
@Override
|
|
public boolean canExtractItem( int slotIndex, ItemStack extractedItem, EnumFacing side )
|
|
{
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void clear()
|
|
{
|
|
this.getInternalInventory().clear();
|
|
}
|
|
|
|
@Override
|
|
public int getField(
|
|
int id )
|
|
{
|
|
return 0;
|
|
}
|
|
@Override
|
|
public void setField(
|
|
int id,
|
|
int value )
|
|
{
|
|
|
|
}
|
|
|
|
@Override
|
|
public int getFieldCount()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public IChatComponent getDisplayName()
|
|
{
|
|
if ( hasCustomName() )
|
|
return new ChatComponentText(getName());
|
|
return new ChatComponentTranslation( getBlockType().getUnlocalizedName() );
|
|
}
|
|
|
|
|
|
public abstract int[] getAccessibleSlotsBySide( EnumFacing whichSide );
|
|
}
|