    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        public ItemStack func_82846_b(EntityPlayer par1EntityPlayer, int par2)
    041        {
    042            ItemStack var3 = null;
    043            Slot var4 = (Slot)this.inventorySlots.get(par2);
    044
    045            if (var4 != null && var4.getHasStack())
    046            {
    047                ItemStack var5 = var4.getStack();
    048                var3 = var5.copy();
    049
    050                if (par2 < 9)
    051                {
    052                    if (!this.mergeItemStack(var5, 9, 45, true))
    053                    {
    054                        return null;
    055                    }
    056                }
    057                else if (!this.mergeItemStack(var5, 0, 9, false))
    058                {
    059                    return null;
    060                }
    061
    062                if (var5.stackSize == 0)
    063                {
    064                    var4.putStack((ItemStack)null);
    065                }
    066                else
    067                {
    068                    var4.onSlotChanged();
    069                }
    070
    071                if (var5.stackSize == var3.stackSize)
    072                {
    073                    return null;
    074                }
    075
    076                var4.func_82870_a(par1EntityPlayer, var5);
    077            }
    078
    079            return var3;
    080        }
    081    }