    001    package net.minecraft.src;
    002
    003    public class ContainerDispenser extends Container
    004    {
    005        private TileEntityDispenser tileEntityDispenser;
    006
    007        public ContainerDispenser(IInventory par1IInventory, TileEntityDispenser par2TileEntityDispenser)
    008        {
    009            this.tileEntityDispenser = par2TileEntityDispenser;
    010            int var3;
    011            int var4;
    012
    013            for (var3 = 0; var3 < 3; ++var3)
    014            {
    015                for (var4 = 0; var4 < 3; ++var4)
    016                {
    017                    this.addSlotToContainer(new Slot(par2TileEntityDispenser, var4 + var3 * 3, 62 + var4 * 18, 17 + var3 * 18));
    018                }
    019            }
    020
    021            for (var3 = 0; var3 < 3; ++var3)
    022            {
    023                for (var4 = 0; var4 < 9; ++var4)
    024                {
    025                    this.addSlotToContainer(new Slot(par1IInventory, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
    026                }
    027            }
    028
    029            for (var3 = 0; var3 < 9; ++var3)
    030            {
    031                this.addSlotToContainer(new Slot(par1IInventory, var3, 8 + var3 * 18, 142));
    032            }
    033        }
    034
    035        public boolean canInteractWith(EntityPlayer par1EntityPlayer)
    036        {
    037            return this.tileEntityDispenser.isUseableByPlayer(par1EntityPlayer);
    038        }
    039
    040        /**
    041         * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
    042         */
    043        public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    044        {
    045            ItemStack var3 = null;
    046            Slot var4 = (Slot)this.inventorySlots.get(par2);
    047
    048            if (var4 != null && var4.getHasStack())
    049            {
    050                ItemStack var5 = var4.getStack();
    051                var3 = var5.copy();
    052
    053                if (par2 < 9)
    054                {
    055                    if (!this.mergeItemStack(var5, 9, 45, true))
    056                    {
    057                        return null;
    058                    }
    059                }
    060                else if (!this.mergeItemStack(var5, 0, 9, false))
    061                {
    062                    return null;
    063                }
    064
    065                if (var5.stackSize == 0)
    066                {
    067                    var4.putStack((ItemStack)null);
    068                }
    069                else
    070                {
    071                    var4.onSlotChanged();
    072                }
    073
    074                if (var5.stackSize == var3.stackSize)
    075                {
    076                    return null;
    077                }
    078
    079                var4.onPickupFromSlot(par1EntityPlayer, var5);
    080            }
    081
    082            return var3;
    083        }
    084    }