package net.minecraft.inventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntityEnderChest; public class InventoryEnderChest extends InventoryBasic { private TileEntityEnderChest associatedChest; private static final String __OBFID = "CL_00001759"; public InventoryEnderChest() { super("container.enderchest", false, 27); } public void setChestTileEntity(TileEntityEnderChest chestTileEntity) { this.associatedChest = chestTileEntity; } public void loadInventoryFromNBT(NBTTagList p_70486_1_) { int i; for (i = 0; i < this.getSizeInventory(); ++i) { this.setInventorySlotContents(i, (ItemStack)null); } for (i = 0; i < p_70486_1_.tagCount(); ++i) { NBTTagCompound nbttagcompound = p_70486_1_.getCompoundTagAt(i); int j = nbttagcompound.getByte("Slot") & 255; if (j >= 0 && j < this.getSizeInventory()) { this.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(nbttagcompound)); } } } public NBTTagList saveInventoryToNBT() { NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < this.getSizeInventory(); ++i) { ItemStack itemstack = this.getStackInSlot(i); if (itemstack != null) { NBTTagCompound nbttagcompound = new NBTTagCompound(); nbttagcompound.setByte("Slot", (byte)i); itemstack.writeToNBT(nbttagcompound); nbttaglist.appendTag(nbttagcompound); } } return nbttaglist; } /** * Do not make give this method the name canInteractWith because it clashes with Container */ public boolean isUseableByPlayer(EntityPlayer player) { return this.associatedChest != null && !this.associatedChest.func_145971_a(player) ? false : super.isUseableByPlayer(player); } public void openChest() { if (this.associatedChest != null) { this.associatedChest.func_145969_a(); } super.openChest(); } public void closeChest() { if (this.associatedChest != null) { this.associatedChest.func_145970_b(); } super.closeChest(); this.associatedChest = null; } }