001package net.minecraft.inventory;
002
003import net.minecraft.entity.player.EntityPlayer;
004import net.minecraft.item.ItemStack;
005import net.minecraft.nbt.NBTTagCompound;
006import net.minecraft.nbt.NBTTagList;
007import net.minecraft.tileentity.TileEntityEnderChest;
008
009public class InventoryEnderChest extends InventoryBasic
010{
011    private TileEntityEnderChest associatedChest;
012
013    public InventoryEnderChest()
014    {
015        super("container.enderchest", false, 27);
016    }
017
018    public void setAssociatedChest(TileEntityEnderChest par1TileEntityEnderChest)
019    {
020        this.associatedChest = par1TileEntityEnderChest;
021    }
022
023    public void loadInventoryFromNBT(NBTTagList par1NBTTagList)
024    {
025        int i;
026
027        for (i = 0; i < this.getSizeInventory(); ++i)
028        {
029            this.setInventorySlotContents(i, (ItemStack)null);
030        }
031
032        for (i = 0; i < par1NBTTagList.tagCount(); ++i)
033        {
034            NBTTagCompound nbttagcompound = (NBTTagCompound)par1NBTTagList.tagAt(i);
035            int j = nbttagcompound.getByte("Slot") & 255;
036
037            if (j >= 0 && j < this.getSizeInventory())
038            {
039                this.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(nbttagcompound));
040            }
041        }
042    }
043
044    public NBTTagList saveInventoryToNBT()
045    {
046        NBTTagList nbttaglist = new NBTTagList("EnderItems");
047
048        for (int i = 0; i < this.getSizeInventory(); ++i)
049        {
050            ItemStack itemstack = this.getStackInSlot(i);
051
052            if (itemstack != null)
053            {
054                NBTTagCompound nbttagcompound = new NBTTagCompound();
055                nbttagcompound.setByte("Slot", (byte)i);
056                itemstack.writeToNBT(nbttagcompound);
057                nbttaglist.appendTag(nbttagcompound);
058            }
059        }
060
061        return nbttaglist;
062    }
063
064    /**
065     * Do not make give this method the name canInteractWith because it clashes with Container
066     */
067    public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
068    {
069        return this.associatedChest != null && !this.associatedChest.isUseableByPlayer(par1EntityPlayer) ? false : super.isUseableByPlayer(par1EntityPlayer);
070    }
071
072    public void openChest()
073    {
074        if (this.associatedChest != null)
075        {
076            this.associatedChest.openChest();
077        }
078
079        super.openChest();
080    }
081
082    public void closeChest()
083    {
084        if (this.associatedChest != null)
085        {
086            this.associatedChest.closeChest();
087        }
088
089        super.closeChest();
090        this.associatedChest = null;
091    }
092
093    public boolean func_94041_b(int par1, ItemStack par2ItemStack)
094    {
095        return true;
096    }
097}