<commit_before>package com.builtbroken.industry.content;

import com.builtbroken.jlib.data.Colors;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.IIcon;

/**
 * Created by robert on 1/7/2015.
 */
public class TileFurnace extends TileMachine
{
    public int heatLevel = 0;

    public TileFurnace()
    {
        super(Material.iron, 2);
        this.name = "BasicFurnace";
        this.max_processing_ticks = 200;
    }

    @Override
    public void update()
    {
        super.update();
        if (this.canProcess())
        {
            ++this.processing_ticks;

            if (this.processing_ticks >= max_processing_ticks)
            {
                this.processing_ticks = 0;
                this.processRecipe();
            }
        }
        else if (heatLevel > 0)
        {
            heatLevel--;
        }

        setEnabled(heatLevel > 0);
    }

    /** Checks if we can smelt the item */
    protected boolean canProcess()
    {
        ItemStack input = this.getStackInSlot(0);
        if(input != null) // check for intput
        {
            ItemStack output = this.getStackInSlot(1);

            if (output == null || output.stackSize <= output.getItem().getItemStackLimit(output)) // check for output room
            {
                ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(input);
                if (itemstack != null) // check output can contain recipe
                {
                    if(output == null)
                    {
                        return true;
                    }
                    else if(output.isItemEqual(itemstack))
                    {
                        int newStackSize = output.stackSize + itemstack.stackSize; // check if we don't exceed max stack size
                        return newStackSize <= getInventoryStackLimit() && newStackSize <= output.getMaxStackSize();
                    }
                }
            }
        }
        return false;
    }

    /** Processes the recipe */
    protected void processRecipe()
    {
        ItemStack output = this.getStackInSlot(1);
        ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(getStackInSlot(0));

        //Increase output stack size
        if (output == null)
        {
            this.setInventorySlotContents(1, result.copy());
        }
        else if (output.getItem() == result.getItem())
        {
            output.stackSize += result.stackSize;
        }

        //Decrease input stack size
        --this.getStackInSlot(0).stackSize;
        if (this.getStackInSlot(0).stackSize <= 0)<commit_msg>Abstracted canProcess to use a getRecipe method<commit_after>package com.builtbroken.industry.content;

import com.builtbroken.jlib.data.Colors;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.IIcon;

/**
 * Created by robert on 1/7/2015.
 */
public class TileFurnace extends TileMachine
{
    public int heatLevel = 0;

    public TileFurnace()
    {
        super(Material.iron, 2);
        this.name = "BasicFurnace";
        this.max_processing_ticks = 200;
    }

    @Override
    public void update()
    {
        super.update();
        if (this.canProcess())
        {
            ++this.processing_ticks;

            if (this.processing_ticks >= max_processing_ticks)
            {
                this.processing_ticks = 0;
                this.processRecipe();
            }
        }
        else if (heatLevel > 0)
        {
            heatLevel--;
        }

        setEnabled(heatLevel > 0);
    }

    /**
     * Checks if we can smelt the item
     */
    protected boolean canProcess()
    {
        ItemStack itemstack = getRecipe();
        if (itemstack != null)
        {
            ItemStack output = this.getStackInSlot(1);

            if (output == null)
            {
                return true;
            }
            else if (output.isItemEqual(itemstack) && output.stackSize <= output.getItem().getItemStackLimit(output)) // check for output room
            {
                int newStackSize = output.stackSize + itemstack.stackSize; // check if we don't exceed max stack size
                return newStackSize <= getInventoryStackLimit() && newStackSize <= output.getMaxStackSize();
            }
        }
        return false;
    }

    /**
     * Checks if we have a recipe for the input
     */
    protected ItemStack getRecipe()
    {
        return this.getStackInSlot(0) != null ? FurnaceRecipes.smelting().getSmeltingResult(this.getStackInSlot(0)) : null;
    }

    /**
     * Processes the recipe
     */
    protected void processRecipe()
    {
        ItemStack output = this.getStackInSlot(1);
        ItemStack result = getRecipe();

        //Increase output stack size
        if (output == null)
        {
            this.setInventorySlotContents(1, result.copy());
        }
        else if (output.getItem() == result.getItem())
        {
            output.stackSize += result.stackSize;
        }

        //Decrease input stack size
        --this.getStackInSlot(0).stackSize;
        if (this.getStackInSlot(0).stackSize <= 0)
{'fraction_non_alphanumeric': 0.1037037037037037, 'fraction_numerical': 0.007760141093474427, 'mean_word_length': 1.8743030917384693, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3749780', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1601, 'n_words': 336}