<commit_before>package com.raoulvdberge.refinedstorage.apiimpl.autocrafting;

import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPatternContainer;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactory;
import com.raoulvdberge.refinedstorage.item.ItemPattern;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;

import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.stream.Collectors;

public class CraftingPattern implements ICraftingPattern {
    private ICraftingPatternContainer container;
    private ItemStack stack;
    private IRecipe recipe;
    private List<ItemStack> inputs = new ArrayList<>();
    private List<List<ItemStack>> oreInputs = new ArrayList<>();
    private List<ItemStack> outputs = new ArrayList<>();
    private List<ItemStack> byproducts = new ArrayList<>();
    private boolean mekanism = false; // Cause they are special in so many ways ¯\_(ツ)_/¯

    public CraftingPattern(World world, ICraftingPatternContainer container, ItemStack stack) {
        this.container = container;
        this.stack = stack;

        InventoryCrafting inv = new InventoryCrafting(new Container() {
            @Override
            public boolean canInteractWith(EntityPlayer player) {
                return false;
            }
        }, 3, 3);

        for (int i = 0; i < 9; ++i) {
            ItemStack slot = ItemPattern.getSlot(stack, i);
            inputs.add(slot);
            inv.setInventorySlotContents(i, slot);
        }

        if (!ItemPattern.isProcessing(stack)) {
            recipe = CraftingManager.getInstance().getRecipeList().stream().filter(r -> r.matches(inv, world)).findFirst().orElse(null);
            if (recipe != null) {
                ItemStack output = recipe.getCraftingResult(inv);
                if (output != null) {
                    boolean shapedOre = recipe instanceof ShapedOreRecipe;
                    // It is a dirty fix, but hey someone has to do it. ~ way2muchnoise 2016 "bite me"
                    mekanism = recipe.getClass().getName().equals("mekanism.common.recipe.ShapedMekanismRecipe");

                    ItemStack out = output.copy();
                    if (mekanism && out.hasTagCompound()) {
                        out.getTagCompound().removeTag("mekData");
                    }
                    outputs.add(out);

                    if (shapedOre || mekanism) {
                        Object[] inputs = new Object[0];
                        if (shapedOre) {
                            inputs = ((ShapedOreRecipe) recipe).getInput();
                        } else {
                            try {
                                inputs = (Object[]) recipe.getClass().getMethod("getInput").invoke(recipe);
                            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                                e.printStackTrace();
                            }
                        }
                        for (Object input : inputs) {
                            if (input == null) {
                                oreInputs.add(Collections.emptyList());
                            } else if (input instanceof ItemStack) {
                                ItemStack stripped = ((ItemStack) input).copy();
                                if (mekanism && ((ItemStack) input).hasTagCompound()) {<commit_msg>fixes Darkoaksto, #661<commit_after>package com.raoulvdberge.refinedstorage.apiimpl.autocrafting;

import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPatternContainer;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactory;
import com.raoulvdberge.refinedstorage.item.ItemPattern;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;

import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.stream.Collectors;

public class CraftingPattern implements ICraftingPattern {
    private ICraftingPatternContainer container;
    private ItemStack stack;
    private IRecipe recipe;
    private List<ItemStack> inputs = new ArrayList<>();
    private List<List<ItemStack>> oreInputs = new ArrayList<>();
    private List<ItemStack> outputs = new ArrayList<>();
    private List<ItemStack> byproducts = new ArrayList<>();
    private boolean mekanism = false; // Cause they are special in so many ways ¯\_(ツ)_/¯

    public CraftingPattern(World world, ICraftingPatternContainer container, ItemStack stack) {
        this.container = container;
        this.stack = stack;

        InventoryCrafting inv = new InventoryCrafting(new Container() {
            @Override
            public boolean canInteractWith(EntityPlayer player) {
                return false;
            }
        }, 3, 3);

        for (int i = 0; i < 9; ++i) {
            ItemStack slot = ItemPattern.getSlot(stack, i);
            inputs.add(slot);
            inv.setInventorySlotContents(i, slot);
        }

        if (!ItemPattern.isProcessing(stack)) {
            recipe = CraftingManager.getInstance().getRecipeList().stream().filter(r -> r.matches(inv, world)).findFirst().orElse(null);
            if (recipe != null) {
                ItemStack output = recipe.getCraftingResult(inv);
                if (output != null) {
                    boolean shapedOre = recipe instanceof ShapedOreRecipe;
                    // It is a dirty fix, but hey someone has to do it. ~ way2muchnoise 2016 "bite me"
                    mekanism = recipe.getClass().getName().equals("mekanism.common.recipe.ShapedMekanismRecipe");

                    ItemStack out = output.copy();
                    if (mekanism && out.hasTagCompound()) {
                        out.getTagCompound().removeTag("mekData");
                    }
                    outputs.add(out);

                    if ((isOredict() && shapedOre) || mekanism) {
                        Object[] inputs = new Object[0];
                        if (shapedOre) {
                            inputs = ((ShapedOreRecipe) recipe).getInput();
                        } else {
                            try {
                                inputs = (Object[]) recipe.getClass().getMethod("getInput").invoke(recipe);
                            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                                e.printStackTrace();
                            }
                        }
                        for (Object input : inputs) {
                            if (input == null) {
                                oreInputs.add(Collections.emptyList());
                            } else if (input instanceof ItemStack) {
                                ItemStack stripped = ((ItemStack) input).copy();
                                if (mekanism && ((ItemStack) input).hasTagCompound()) {
{'fraction_non_alphanumeric': 0.09857723577235772, 'fraction_numerical': 0.0029217479674796746, 'mean_word_length': 2.1279300754866903, 'pattern_counts': {'":': 0, '<': 23, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '263575', 'n_tokens_mistral': 2088, 'n_tokens_neox': 2025, 'n_words': 427}