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