    001package net.minecraft.inventory;
    002
    003import net.minecraft.entity.player.EntityPlayer;
    004import net.minecraft.item.ItemStack;
    005import net.minecraft.tileentity.TileEntityDispenser;
    006
    007public class ContainerDispenser extends Container
    008{
    009    private TileEntityDispenser tileEntityDispenser;
    010
    011    public ContainerDispenser(IInventory par1IInventory, TileEntityDispenser par2TileEntityDispenser)
    012    {
    013        this.tileEntityDispenser = par2TileEntityDispenser;
    014        int var3;
    015        int var4;
    016
    017        for (var3 = 0; var3 < 3; ++var3)
    018        {
    019            for (var4 = 0; var4 < 3; ++var4)
    020            {
    021                this.addSlotToContainer(new Slot(par2TileEntityDispenser, var4 + var3 * 3, 62 + var4 * 18, 17 + var3 * 18));
    022            }
    023        }
    024
    025        for (var3 = 0; var3 < 3; ++var3)
    026        {
    027            for (var4 = 0; var4 < 9; ++var4)
    028            {
    029                this.addSlotToContainer(new Slot(par1IInventory, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
    030            }
    031        }
    032
    033        for (var3 = 0; var3 < 9; ++var3)
    034        {
    035            this.addSlotToContainer(new Slot(par1IInventory, var3, 8 + var3 * 18, 142));
    036        }
    037    }
    038
    039    public boolean canInteractWith(EntityPlayer par1EntityPlayer)
    040    {
    041        return this.tileEntityDispenser.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 < 9)
    058            {
    059                if (!this.mergeItemStack(var5, 9, 45, true))
    060                {
    061                    return null;
    062                }
    063            }
    064            else if (!this.mergeItemStack(var5, 0, 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            if (var5.stackSize == var3.stackSize)
    079            {
    080                return null;
    081            }
    082
    083            var4.onPickupFromSlot(par1EntityPlayer, var5);
    084        }
    085
    086        return var3;
    087    }
    088}