    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 to transfer a stack from one inventory to the other eg. when shift clicking.
    042         */
    043        public ItemStack transferStackInSlot(int par1)
    044        {
    045            ItemStack var2 = null;
    046            Slot var3 = (Slot)this.inventorySlots.get(par1);
    047
    048            if (var3 != null && var3.getHasStack())
    049            {
    050                ItemStack var4 = var3.getStack();
    051                var2 = var4.copy();
    052
    053                if (par1 < 9)
    054                {
    055                    if (!this.mergeItemStack(var4, 9, 45, true))
    056                    {
    057                        return null;
    058                    }
    059                }
    060                else if (!this.mergeItemStack(var4, 0, 9, false))
    061                {
    062                    return null;
    063                }
    064
    065                if (var4.stackSize == 0)
    066                {
    067                    var3.putStack((ItemStack)null);
    068                }
    069                else
    070                {
    071                    var3.onSlotChanged();
    072                }
    073
    074                if (var4.stackSize == var2.stackSize)
    075                {
    076                    return null;
    077                }
    078
    079                var3.onPickupFromSlot(var4);
    080            }
    081
    082            return var2;
    083        }
    084    }