    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        /**
    102         * Called to transfer a stack from one inventory to the other eg. when shift clicking.
    103         */
    104        public ItemStack transferStackInSlot(int par1)
    105        {
    106            ItemStack var2 = null;
    107            Slot var3 = (Slot)this.inventorySlots.get(par1);
    108
    109            if (var3 != null && var3.getHasStack())
    110            {
    111                ItemStack var4 = var3.getStack();
    112                var2 = var4.copy();
    113
    114                if (par1 == 2)
    115                {
    116                    if (!this.mergeItemStack(var4, 3, 39, true))
    117                    {
    118                        return null;
    119                    }
    120
    121                    var3.onSlotChange(var4, var2);
    122                }
    123                else if (par1 != 1 && par1 != 0)
    124                {
    125                    if (FurnaceRecipes.smelting().getSmeltingResult(var4) != null)
    126                    {
    127                        if (!this.mergeItemStack(var4, 0, 1, false))
    128                        {
    129                            return null;
    130                        }
    131                    }
    132                    else if (TileEntityFurnace.isItemFuel(var4))
    133                    {
    134                        if (!this.mergeItemStack(var4, 1, 2, false))
    135                        {
    136                            return null;
    137                        }
    138                    }
    139                    else if (par1 >= 3 && par1 < 30)
    140                    {
    141                        if (!this.mergeItemStack(var4, 30, 39, false))
    142                        {
    143                            return null;
    144                        }
    145                    }
    146                    else if (par1 >= 30 && par1 < 39 && !this.mergeItemStack(var4, 3, 30, false))
    147                    {
    148                        return null;
    149                    }
    150                }
    151                else if (!this.mergeItemStack(var4, 3, 39, false))
    152                {
    153                    return null;
    154                }
    155
    156                if (var4.stackSize == 0)
    157                {
    158                    var3.putStack((ItemStack)null);
    159                }
    160                else
    161                {
    162                    var3.onSlotChanged();
    163                }
    164
    165                if (var4.stackSize == var2.stackSize)
    166                {
    167                    return null;
    168                }
    169
    170                var3.onPickupFromSlot(var4);
    171            }
    172
    173            return var2;
    174        }
    175    }