    001    package net.minecraft.inventory;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.SideOnly;
    005    import net.minecraft.entity.player.EntityPlayer;
    006    import net.minecraft.entity.player.InventoryPlayer;
    007    import net.minecraft.item.ItemStack;
    008    import net.minecraft.tileentity.TileEntityBrewingStand;
    009
    010    public class ContainerBrewingStand extends Container
    011    {
    012        private TileEntityBrewingStand tileBrewingStand;
    013
    014        /** Instance of Slot. */
    015        private final Slot theSlot;
    016        private int brewTime = 0;
    017
    018        public ContainerBrewingStand(InventoryPlayer par1InventoryPlayer, TileEntityBrewingStand par2TileEntityBrewingStand)
    019        {
    020            this.tileBrewingStand = par2TileEntityBrewingStand;
    021            this.addSlotToContainer(new SlotBrewingStandPotion(par1InventoryPlayer.player, par2TileEntityBrewingStand, 0, 56, 46));
    022            this.addSlotToContainer(new SlotBrewingStandPotion(par1InventoryPlayer.player, par2TileEntityBrewingStand, 1, 79, 53));
    023            this.addSlotToContainer(new SlotBrewingStandPotion(par1InventoryPlayer.player, par2TileEntityBrewingStand, 2, 102, 46));
    024            this.theSlot = this.addSlotToContainer(new SlotBrewingStandIngredient(this, par2TileEntityBrewingStand, 3, 79, 17));
    025            int var3;
    026
    027            for (var3 = 0; var3 < 3; ++var3)
    028            {
    029                for (int var4 = 0; var4 < 9; ++var4)
    030                {
    031                    this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
    032                }
    033            }
    034
    035            for (var3 = 0; var3 < 9; ++var3)
    036            {
    037                this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
    038            }
    039        }
    040
    041        public void addCraftingToCrafters(ICrafting par1ICrafting)
    042        {
    043            super.addCraftingToCrafters(par1ICrafting);
    044            par1ICrafting.sendProgressBarUpdate(this, 0, this.tileBrewingStand.getBrewTime());
    045        }
    046
    047        /**
    048         * Updates crafting matrix; called from onCraftMatrixChanged. Args: none
    049         */
    050        public void updateCraftingResults()
    051        {
    052            super.updateCraftingResults();
    053
    054            for (int var1 = 0; var1 < this.crafters.size(); ++var1)
    055            {
    056                ICrafting var2 = (ICrafting)this.crafters.get(var1);
    057
    058                if (this.brewTime != this.tileBrewingStand.getBrewTime())
    059                {
    060                    var2.sendProgressBarUpdate(this, 0, this.tileBrewingStand.getBrewTime());
    061                }
    062            }
    063
    064            this.brewTime = this.tileBrewingStand.getBrewTime();
    065        }
    066
    067        @SideOnly(Side.CLIENT)
    068        public void updateProgressBar(int par1, int par2)
    069        {
    070            if (par1 == 0)
    071            {
    072                this.tileBrewingStand.setBrewTime(par2);
    073            }
    074        }
    075
    076        public boolean canInteractWith(EntityPlayer par1EntityPlayer)
    077        {
    078            return this.tileBrewingStand.isUseableByPlayer(par1EntityPlayer);
    079        }
    080
    081        /**
    082         * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
    083         */
    084        public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    085        {
    086            ItemStack var3 = null;
    087            Slot var4 = (Slot)this.inventorySlots.get(par2);
    088
    089            if (var4 != null && var4.getHasStack())
    090            {
    091                ItemStack var5 = var4.getStack();
    092                var3 = var5.copy();
    093
    094                if ((par2 < 0 || par2 > 2) && par2 != 3)
    095                {
    096                    if (!this.theSlot.getHasStack() && this.theSlot.isItemValid(var5))
    097                    {
    098                        if (!this.mergeItemStack(var5, 3, 4, false))
    099                        {
    100                            return null;
    101                        }
    102                    }
    103                    else if (SlotBrewingStandPotion.canHoldPotion(var3))
    104                    {
    105                        if (!this.mergeItemStack(var5, 0, 3, false))
    106                        {
    107                            return null;
    108                        }
    109                    }
    110                    else if (par2 >= 4 && par2 < 31)
    111                    {
    112                        if (!this.mergeItemStack(var5, 31, 40, false))
    113                        {
    114                            return null;
    115                        }
    116                    }
    117                    else if (par2 >= 31 && par2 < 40)
    118                    {
    119                        if (!this.mergeItemStack(var5, 4, 31, false))
    120                        {
    121                            return null;
    122                        }
    123                    }
    124                    else if (!this.mergeItemStack(var5, 4, 40, false))
    125                    {
    126                        return null;
    127                    }
    128                }
    129                else
    130                {
    131                    if (!this.mergeItemStack(var5, 4, 40, true))
    132                    {
    133                        return null;
    134                    }
    135
    136                    var4.onSlotChange(var5, var3);
    137                }
    138
    139                if (var5.stackSize == 0)
    140                {
    141                    var4.putStack((ItemStack)null);
    142                }
    143                else
    144                {
    145                    var4.onSlotChanged();
    146                }
    147
    148                if (var5.stackSize == var3.stackSize)
    149                {
    150                    return null;
    151                }
    152
    153                var4.onPickupFromSlot(par1EntityPlayer, var5);
    154            }
    155
    156            return var3;
    157        }
    158    }