package client.gui.container;

import common.inventory.ContainerFurnace;
import common.inventory.IInventory;
import common.inventory.InventoryPlayer;
import common.tileentity.TileEntityFurnace;


public class GuiFurnace extends GuiContainer
{
//    private static final String furnaceGuiTextures = "textures/gui/furnace.png";

    /** The player inventory bound to this GUI. */
    private final InventoryPlayer playerInventory;
    private IInventory tileFurnace;

    public GuiFurnace(InventoryPlayer playerInv, IInventory furnaceInv)
    {
        super(new ContainerFurnace(playerInv, furnaceInv));
        this.playerInventory = playerInv;
        this.tileFurnace = furnaceInv;
    }

    /**
     * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
     */
    public void drawGuiContainerForegroundLayer()
    {
        String s = this.tileFurnace.getCommandName();
        this.drawString(s, 8, 6);
        this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2);
    }

    /**
     * Args : renderPartialTicks, mouseX, mouseY
     */
    public void drawGuiContainerBackgroundLayer()
    {
        this.rect(58, 36, 12, 14, 0x202020);
        if (TileEntityFurnace.isBurning(this.tileFurnace))
        {
            int k = this.getBurnLeftScaled(13);
            k = Math.min(k, 13);
            this.rect(58, 36 + 13 - k, 12, k + 1, 0xff7f00);
        }

        int l = this.getCookProgressScaled(24);
        this.rect(79, 39, 24, 8, 0x606060);
        if(l > 0)
        	this.rect(79, 39, l + 1, 8, 0xffaf00);
    }

    private int getCookProgressScaled(int pixels)
    {
        int i = this.tileFurnace.getField(2);
        int j = this.tileFurnace.getField(3);
        return j != 0 && i != 0 ? i * pixels / j : 0;
    }

    private int getBurnLeftScaled(int pixels)
    {
        int i = this.tileFurnace.getField(1);

        if (i == 0)
        {
            i = 200;
        }

        return this.tileFurnace.getField(0) * pixels / i;
    }
}
