package wehavecookies56.kk.entities.tileentities;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
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.util.IChatComponent;
import net.minecraftforge.common.util.Constants;
public class TileEntityKKChest extends TileEntity implements IInventory
{
int Direction;
public int getFacingDirection()
{
return this.Direction;
}
public void setFacingDirection(int par1)
{
this.Direction = par1;
}
private ItemStack[] inv;
public TileEntityKKChest(){
inv = new ItemStack[9];
}
@Override
public int getSizeInventory() {
return inv.length;
}
@Override
public ItemStack getStackInSlot(int slot) {
return inv[slot];
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
inv[slot] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
stack.stackSize = getInventoryStackLimit();
}
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
ItemStack stack = getStackInSlot(slot);
if (stack != null) {
setInventorySlotContents(slot, null);
}
return stack;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return worldObj.getTileEntity(pos) == this &&
player.getDistanceSq(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5) < 64;
}
public ItemStack decrStackSize(int slot, int amount) {
ItemStack stack = getStackInSlot(slot);
if(stack != null) {
if(stack.stackSize>amount) {
stack = stack.splitStack(amount);
markDirty();
} else {
setInventorySlotContents(slot, null);
}
}
return stack;
}
@Override
public void openInventory(EntityPlayer player) {}
@Override
public void closeInventory(EntityPlayer player) {}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
setFacingDirection(tagCompound.getInteger("Direction"));
NBTTagList tagList = (NBTTagList) tagCompound.getTag("Inventory");
for (int i = 0; i < tagList.tagCount(); i++) {
NBTTagCompound tag = tagList.getCompoundTagAt(i);
byte slot = tag.getByte("Slot");
if (slot >= 0 && slot < inv.length) {
inv[slot] = ItemStack.loadItemStackFromNBT(tag);
}
}
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inv.length; i++) {
ItemStack stack = inv[i];
if (stack != null) {
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) i);
stack.writeToNBT(tag);
itemList.appendTag(tag);
}
}
tagCompound.setTag("Inventory", itemList);
tagCompound.setInteger("Direction", this.Direction);
}
@Override
public String getName() {
// TODO Auto-generated method stub
return "kkchest";
}
@Override
public boolean hasCustomName() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
// TODO Auto-generated method stub
return true;
}
@Override
public IChatComponent getDisplayName() {
// TODO Auto-generated method stub
return null;
}
@Override
public int getField(int id) {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setField(int id, int value) {
// TODO Auto-generated method stub
}
@Override
public int getFieldCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void clear() {
// TODO Auto-generated method stub
}
}