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