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.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.SPacketUpdateTileEntity; 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 tagCompound) { super.readFromNBT(tagCompound); if (tagCompound.hasKey("Items")) { NBTTagList tagList = (NBTTagList) tagCompound.getTag("Items"); this.inventory = new ItemStack[8]; 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 NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); 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); } } tagCompound.setTag("Items", tagList); return tagCompound; } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { this.readFromNBT(pkt.getNbtCompound()); } @Override public SPacketUpdateTileEntity getUpdatePacket() { return new SPacketUpdateTileEntity(pos, getBlockMetadata(), this.writeToNBT(new NBTTagCompound())); } @Override public NBTTagCompound getUpdateTag() { return this.writeToNBT(new NBTTagCompound()); } @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; } }