001 package net.minecraft.src; 002 003 public class ContainerChest extends Container 004 { 005 private IInventory lowerChestInventory; 006 private int numRows; 007 008 public ContainerChest(IInventory par1IInventory, IInventory par2IInventory) 009 { 010 this.lowerChestInventory = par2IInventory; 011 this.numRows = par2IInventory.getSizeInventory() / 9; 012 par2IInventory.openChest(); 013 int var3 = (this.numRows - 4) * 18; 014 int var4; 015 int var5; 016 017 for (var4 = 0; var4 < this.numRows; ++var4) 018 { 019 for (var5 = 0; var5 < 9; ++var5) 020 { 021 this.addSlotToContainer(new Slot(par2IInventory, var5 + var4 * 9, 8 + var5 * 18, 18 + var4 * 18)); 022 } 023 } 024 025 for (var4 = 0; var4 < 3; ++var4) 026 { 027 for (var5 = 0; var5 < 9; ++var5) 028 { 029 this.addSlotToContainer(new Slot(par1IInventory, var5 + var4 * 9 + 9, 8 + var5 * 18, 103 + var4 * 18 + var3)); 030 } 031 } 032 033 for (var4 = 0; var4 < 9; ++var4) 034 { 035 this.addSlotToContainer(new Slot(par1IInventory, var4, 8 + var4 * 18, 161 + var3)); 036 } 037 } 038 039 public boolean canInteractWith(EntityPlayer par1EntityPlayer) 040 { 041 return this.lowerChestInventory.isUseableByPlayer(par1EntityPlayer); 042 } 043 044 /** 045 * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that. 046 */ 047 public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) 048 { 049 ItemStack var3 = null; 050 Slot var4 = (Slot)this.inventorySlots.get(par2); 051 052 if (var4 != null && var4.getHasStack()) 053 { 054 ItemStack var5 = var4.getStack(); 055 var3 = var5.copy(); 056 057 if (par2 < this.numRows * 9) 058 { 059 if (!this.mergeItemStack(var5, this.numRows * 9, this.inventorySlots.size(), true)) 060 { 061 return null; 062 } 063 } 064 else if (!this.mergeItemStack(var5, 0, this.numRows * 9, false)) 065 { 066 return null; 067 } 068 069 if (var5.stackSize == 0) 070 { 071 var4.putStack((ItemStack)null); 072 } 073 else 074 { 075 var4.onSlotChanged(); 076 } 077 } 078 079 return var3; 080 } 081 082 /** 083 * Callback for when the crafting gui is closed. 084 */ 085 public void onCraftGuiClosed(EntityPlayer par1EntityPlayer) 086 { 087 super.onCraftGuiClosed(par1EntityPlayer); 088 this.lowerChestInventory.closeChest(); 089 } 090 091 public IInventory func_85151_d() 092 { 093 return this.lowerChestInventory; 094 } 095 }