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