001 package net.minecraft.inventory;
002
003 import net.minecraft.entity.player.EntityPlayer;
004 import net.minecraft.item.ItemStack;
005
006 public class InventoryLargeChest implements IInventory
007 {
008 /** Name of the chest. */
009 private String name;
010
011 /** Inventory object corresponding to double chest upper part */
012 private IInventory upperChest;
013
014 /** Inventory object corresponding to double chest lower part */
015 private IInventory lowerChest;
016
017 public InventoryLargeChest(String par1Str, IInventory par2IInventory, IInventory par3IInventory)
018 {
019 this.name = par1Str;
020
021 if (par2IInventory == null)
022 {
023 par2IInventory = par3IInventory;
024 }
025
026 if (par3IInventory == null)
027 {
028 par3IInventory = par2IInventory;
029 }
030
031 this.upperChest = par2IInventory;
032 this.lowerChest = par3IInventory;
033 }
034
035 /**
036 * Returns the number of slots in the inventory.
037 */
038 public int getSizeInventory()
039 {
040 return this.upperChest.getSizeInventory() + this.lowerChest.getSizeInventory();
041 }
042
043 public boolean func_90010_a(IInventory par1IInventory)
044 {
045 return this.upperChest == par1IInventory || this.lowerChest == par1IInventory;
046 }
047
048 /**
049 * Returns the name of the inventory.
050 */
051 public String getInvName()
052 {
053 return this.name;
054 }
055
056 /**
057 * Returns the stack in slot i
058 */
059 public ItemStack getStackInSlot(int par1)
060 {
061 return par1 >= this.upperChest.getSizeInventory() ? this.lowerChest.getStackInSlot(par1 - this.upperChest.getSizeInventory()) : this.upperChest.getStackInSlot(par1);
062 }
063
064 /**
065 * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
066 * new stack.
067 */
068 public ItemStack decrStackSize(int par1, int par2)
069 {
070 return par1 >= this.upperChest.getSizeInventory() ? this.lowerChest.decrStackSize(par1 - this.upperChest.getSizeInventory(), par2) : this.upperChest.decrStackSize(par1, par2);
071 }
072
073 /**
074 * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
075 * like when you close a workbench GUI.
076 */
077 public ItemStack getStackInSlotOnClosing(int par1)
078 {
079 return par1 >= this.upperChest.getSizeInventory() ? this.lowerChest.getStackInSlotOnClosing(par1 - this.upperChest.getSizeInventory()) : this.upperChest.getStackInSlotOnClosing(par1);
080 }
081
082 /**
083 * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
084 */
085 public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
086 {
087 if (par1 >= this.upperChest.getSizeInventory())
088 {
089 this.lowerChest.setInventorySlotContents(par1 - this.upperChest.getSizeInventory(), par2ItemStack);
090 }
091 else
092 {
093 this.upperChest.setInventorySlotContents(par1, par2ItemStack);
094 }
095 }
096
097 /**
098 * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
099 * this more of a set than a get?*
100 */
101 public int getInventoryStackLimit()
102 {
103 return this.upperChest.getInventoryStackLimit();
104 }
105
106 /**
107 * Called when an the contents of an Inventory change, usually
108 */
109 public void onInventoryChanged()
110 {
111 this.upperChest.onInventoryChanged();
112 this.lowerChest.onInventoryChanged();
113 }
114
115 /**
116 * Do not make give this method the name canInteractWith because it clashes with Container
117 */
118 public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
119 {
120 return this.upperChest.isUseableByPlayer(par1EntityPlayer) && this.lowerChest.isUseableByPlayer(par1EntityPlayer);
121 }
122
123 public void openChest()
124 {
125 this.upperChest.openChest();
126 this.lowerChest.openChest();
127 }
128
129 public void closeChest()
130 {
131 this.upperChest.closeChest();
132 this.lowerChest.closeChest();
133 }
134 }