<commit_before><commit_msg>Added CraftingUtils with methods to find recipes from the result item (#44)<commit_after>package net.darkhax.bookshelf.lib.util;

import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;

import java.util.ArrayList;
import java.util.List;

public final class CraftingUtils
{
    public static ShapedRecipes[] findShapedRecipe(ItemStack result) {
        return findShapedRecipe(result, Integer.MAX_VALUE);
    }

    public static ShapedRecipes[] findShapedRecipe(ItemStack result, int depth) {
        List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
        List<ShapedRecipes> found = new ArrayList<>();
        for( IRecipe recipe : recipes ) {
            if( recipe instanceof ShapedRecipes ) {
                ShapedRecipes sRecipe = ((ShapedRecipes) recipe);
                ItemStack recipeResult = sRecipe.getRecipeOutput();
                if( ItemStackUtils.areStacksEqual(recipeResult, result, result.hasTagCompound()) ) {
                    found.add(sRecipe);
                    if( depth >= found.size() ) {
                        break;
                    }
                }
            }
        }

        return found.size() > 0 ? found.toArray(new ShapedRecipes[found.size()]) : null;
    }
    public static ShapelessRecipes[] findShapelessRecipe(ItemStack result) {
        return findShapelessRecipe(result, Integer.MAX_VALUE);
    }

    public static ShapelessRecipes[] findShapelessRecipe(ItemStack result, int depth) {
        List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
        List<ShapelessRecipes> found = new ArrayList<>();
        for( IRecipe recipe : recipes ) {
            if( recipe instanceof ShapelessRecipes ) {
                ShapelessRecipes sRecipe = ((ShapelessRecipes) recipe);
                ItemStack recipeResult = sRecipe.getRecipeOutput();
                if( ItemStackUtils.areStacksEqual(recipeResult, result, result.hasTagCompound()) ) {
                    found.add(sRecipe);
                    if( depth >= found.size() ) {
                        break;
                    }
                }
            }
        }

        return found.size() > 0 ? found.toArray(new ShapelessRecipes[found.size()]) : null;
    }

    public static ShapedOreRecipe[] findShapedOreRecipe(ItemStack result) {
        return findShapedOreRecipe(result, Integer.MAX_VALUE);
    }

    public static ShapedOreRecipe[] findShapedOreRecipe(ItemStack result, int depth) {
        List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
        List<ShapedOreRecipe> found = new ArrayList<>();
        for( IRecipe recipe : recipes ) {
            if( recipe instanceof ShapedOreRecipe ) {
                ShapedOreRecipe sRecipe = ((ShapedOreRecipe) recipe);
                ItemStack recipeResult = sRecipe.getRecipeOutput();
                if( ItemStackUtils.areStacksEqual(recipeResult, result, result.hasTagCompound()) ) {
                    found.add(sRecipe);
                    if( depth >= found.size() ) {
                        break;
                    }
                }
            }
        }

        return found.size() > 0 ? found.toArray(new ShapedOreRecipe[found.size()]) : null;
    }

    public static ShapelessOreRecipe[] findShapelessOreRecipe(ItemStack result) {
        return findShapelessOreRecipe(result, Integer.MAX_VALUE);
    }

    public static ShapelessOreRecipe[] findShapelessOreRecipe(ItemStack result, int depth) {
        List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
        List<ShapelessOreRecipe> found = new ArrayList<>();
        for( IRecipe recipe : recipes ) {
            if( recipe instanceof ShapelessOreRecipe ) {
                ShapelessOreRecipe sRecipe = ((ShapelessOreRecipe) recipe);
                ItemStack recipeResult = sRecipe.getRecipeOutput();
                if( ItemStackUtils.areStacksEqual(recipeResult, result, result.hasTagCompound()) ) {
                    found.add(sRecipe);
                    if( depth >= found.size() ) {
                        break;
                    }
                }
            }
        }

        return found.size() > 0 ? found.toArray(new ShapelessOreRecipe[found.size()]) : null;
    }
}
{'fraction_non_alphanumeric': 0.0971215117556581, 'fraction_numerical': 0.0013183915622940012, 'mean_word_length': 2.3009427121102246, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '7589191', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1266, 'n_words': 243}