    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.util.Iterator;
    006
    007    public class ContainerFurnace extends Container
    008    {
    009        private TileEntityFurnace furnace;
    010        private int lastCookTime = 0;
    011        private int lastBurnTime = 0;
    012        private int lastItemBurnTime = 0;
    013
    014        public ContainerFurnace(InventoryPlayer par1InventoryPlayer, TileEntityFurnace par2TileEntityFurnace)
    015        {
    016            this.furnace = par2TileEntityFurnace;
    017            this.addSlotToContainer(new Slot(par2TileEntityFurnace, 0, 56, 17));
    018            this.addSlotToContainer(new Slot(par2TileEntityFurnace, 1, 56, 53));
    019            this.addSlotToContainer(new SlotFurnace(par1InventoryPlayer.player, par2TileEntityFurnace, 2, 116, 35));
    020            int var3;
    021
    022            for (var3 = 0; var3 < 3; ++var3)
    023            {
    024                for (int var4 = 0; var4 < 9; ++var4)
    025                {
    026                    this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
    027                }
    028            }
    029
    030            for (var3 = 0; var3 < 9; ++var3)
    031            {
    032                this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
    033            }
    034        }
    035
    036        public void addCraftingToCrafters(ICrafting par1ICrafting)
    037        {
    038            super.addCraftingToCrafters(par1ICrafting);
    039            par1ICrafting.updateCraftingInventoryInfo(this, 0, this.furnace.furnaceCookTime);
    040            par1ICrafting.updateCraftingInventoryInfo(this, 1, this.furnace.furnaceBurnTime);
    041            par1ICrafting.updateCraftingInventoryInfo(this, 2, this.furnace.currentItemBurnTime);
    042        }
    043
    044        /**
    045         * Updates crafting matrix; called from onCraftMatrixChanged. Args: none
    046         */
    047        public void updateCraftingResults()
    048        {
    049            super.updateCraftingResults();
    050            Iterator var1 = this.crafters.iterator();
    051
    052            while (var1.hasNext())
    053            {
    054                ICrafting var2 = (ICrafting)var1.next();
    055
    056                if (this.lastCookTime != this.furnace.furnaceCookTime)
    057                {
    058                    var2.updateCraftingInventoryInfo(this, 0, this.furnace.furnaceCookTime);
    059                }
    060
    061                if (this.lastBurnTime != this.furnace.furnaceBurnTime)
    062                {
    063                    var2.updateCraftingInventoryInfo(this, 1, this.furnace.furnaceBurnTime);
    064                }
    065
    066                if (this.lastItemBurnTime != this.furnace.currentItemBurnTime)
    067                {
    068                    var2.updateCraftingInventoryInfo(this, 2, this.furnace.currentItemBurnTime);
    069                }
    070            }
    071
    072            this.lastCookTime = this.furnace.furnaceCookTime;
    073            this.lastBurnTime = this.furnace.furnaceBurnTime;
    074            this.lastItemBurnTime = this.furnace.currentItemBurnTime;
    075        }
    076
    077        @SideOnly(Side.CLIENT)
    078        public void updateProgressBar(int par1, int par2)
    079        {
    080            if (par1 == 0)
    081            {
    082                this.furnace.furnaceCookTime = par2;
    083            }
    084
    085            if (par1 == 1)
    086            {
    087                this.furnace.furnaceBurnTime = par2;
    088            }
    089
    090            if (par1 == 2)
    091            {
    092                this.furnace.currentItemBurnTime = par2;
    093            }
    094        }
    095
    096        public boolean canInteractWith(EntityPlayer par1EntityPlayer)
    097        {
    098            return this.furnace.isUseableByPlayer(par1EntityPlayer);
    099        }
    100
    101        public ItemStack func_82846_b(EntityPlayer par1EntityPlayer, int par2)
    102        {
    103            ItemStack var3 = null;
    104            Slot var4 = (Slot)this.inventorySlots.get(par2);
    105
    106            if (var4 != null && var4.getHasStack())
    107            {
    108                ItemStack var5 = var4.getStack();
    109                var3 = var5.copy();
    110
    111                if (par2 == 2)
    112                {
    113                    if (!this.mergeItemStack(var5, 3, 39, true))
    114                    {
    115                        return null;
    116                    }
    117
    118                    var4.onSlotChange(var5, var3);
    119                }
    120                else if (par2 != 1 && par2 != 0)
    121                {
    122                    if (FurnaceRecipes.smelting().getSmeltingResult(var5) != null)
    123                    {
    124                        if (!this.mergeItemStack(var5, 0, 1, false))
    125                        {
    126                            return null;
    127                        }
    128                    }
    129                    else if (TileEntityFurnace.isItemFuel(var5))
    130                    {
    131                        if (!this.mergeItemStack(var5, 1, 2, false))
    132                        {
    133                            return null;
    134                        }
    135                    }
    136                    else if (par2 >= 3 && par2 < 30)
    137                    {
    138                        if (!this.mergeItemStack(var5, 30, 39, false))
    139                        {
    140                            return null;
    141                        }
    142                    }
    143                    else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(var5, 3, 30, false))
    144                    {
    145                        return null;
    146                    }
    147                }
    148                else if (!this.mergeItemStack(var5, 3, 39, false))
    149                {
    150                    return null;
    151                }
    152
    153                if (var5.stackSize == 0)
    154                {
    155                    var4.putStack((ItemStack)null);
    156                }
    157                else
    158                {
    159                    var4.onSlotChanged();
    160                }
    161
    162                if (var5.stackSize == var3.stackSize)
    163                {
    164                    return null;
    165                }
    166
    167                var4.func_82870_a(par1EntityPlayer, var5);
    168            }
    169
    170            return var3;
    171        }
    172    }