package com.mrcrayfish.furniture.tileentity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInvBasic;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityLockable;
public class TileEntityEsky extends TileEntityLockable implements IInventory
{
public ItemStack[] inventory = new ItemStack[8];
@Override
public int getSizeInventory()
{
return inventory.length;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return inventory[slot];
}
@Override
public ItemStack decrStackSize(int slot, int count)
{
if (this.inventory[slot] != null)
{
ItemStack var3;
if (this.inventory[slot].stackSize <= count)
{
var3 = this.inventory[slot];
this.inventory[slot] = null;
this.markDirty();
return var3;
}
var3 = this.inventory[slot].splitStack(count);
if (this.inventory[slot].stackSize == 0)
{
this.inventory[slot] = null;
}
this.markDirty();
return var3;
}
return null;
}
@Override
public ItemStack removeStackFromSlot(int slot)
{
if (this.inventory[slot] != null)
{
ItemStack itemstack = this.inventory[slot];
this.inventory[slot] = null;
return itemstack;
}
return null;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack)
{
this.inventory[slot] = stack;
if (stack != null && stack.stackSize > this.getInventoryStackLimit())
{
stack.stackSize = this.getInventoryStackLimit();
}
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player)
{
return this.worldObj.getTileEntity(pos) != this ? false : player.getDistanceSq(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D) <= 64.0D;
}
@Override
public void openInventory(EntityPlayer player) {}
@Override
public void closeInventory(EntityPlayer player) {}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return false;
}
@Override
public int getField(int id)
{
return 0;
}
@Override
public void setField(int id, int value) {}
@Override
public int getFieldCount()
{
return 0;
}
@Override
public void clear()
{
for(int i = 0; i < inventory.length; i++)
{
inventory[i] = null;
}
}
@Override
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
if (compound.hasKey("Items"))
{
NBTTagList tagList = (NBTTagList) compound.getTag("Items");
this.inventory = new ItemStack[6];
for (int i = 0; i < tagList.tagCount(); ++i)
{
NBTTagCompound nbt = (NBTTagCompound) tagList.getCompoundTagAt(i);
byte slot = nbt.getByte("Slot");
if (slot >= 0 && slot < this.inventory.length)
{
this.inventory[slot] = ItemStack.loadItemStackFromNBT(nbt);
}
}
}
}
@Override
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
NBTTagList tagList = new NBTTagList();
for (int slot = 0; slot < this.inventory.length; ++slot)
{
if (this.inventory[slot] != null)
{
NBTTagCompound nbt = new NBTTagCompound();
nbt.setByte("Slot", (byte) slot);
this.inventory[slot].writeToNBT(nbt);
tagList.appendTag(nbt);
}
}
compound.setTag("Items", tagList);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
{
NBTTagCompound tagCom = pkt.getNbtCompound();
this.readFromNBT(tagCom);
}
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound tagCom = new NBTTagCompound();
this.writeToNBT(tagCom);
return new S35PacketUpdateTileEntity(pos, getBlockMetadata(), tagCom);
}
@Override
public String getGuiID()
{
return null;
}
@Override
public String getName()
{
return "Eski";
}
@Override
public boolean hasCustomName()
{
return false;
}
@Override
public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
{
return null;
}
}