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