Search in sources :

Example 1 with IIngredients

use of mezz.jei.api.ingredients.IIngredients in project BluePower by Qmunity.

the class AlloyFurnaceHandler method setIngredients.

@Override
public void setIngredients(StandardAlloyFurnaceRecipe recipe, IIngredients ingredients) {
    List<List<ItemStack>> items = recipe.getRequiredItems().stream().map(ingredient -> Arrays.asList(ingredient.getItems())).collect(Collectors.toList());
    for (int i = 0; i < items.size(); i++) {
        for (ItemStack itemStack : items.get(i)) {
            itemStack.setCount(recipe.getRequiredCount().get(i));
        }
    }
    ingredients.setInputLists(VanillaTypes.ITEM, items);
    ingredients.setOutput(VanillaTypes.ITEM, recipe.getResultItem());
}
Also used : Refs(com.bluepowermod.reference.Refs) Arrays(java.util.Arrays) IDrawable(mezz.jei.api.gui.drawable.IDrawable) BPBlocks(com.bluepowermod.init.BPBlocks) IIngredients(mezz.jei.api.ingredients.IIngredients) Items(net.minecraft.item.Items) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) Collectors(java.util.stream.Collectors) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) StandardAlloyFurnaceRecipe(com.bluepowermod.recipe.AlloyFurnaceRegistry.StandardAlloyFurnaceRecipe) IRecipeCategory(mezz.jei.api.recipe.category.IRecipeCategory) ResourceLocation(net.minecraft.util.ResourceLocation) IDrawableAnimated(mezz.jei.api.gui.drawable.IDrawableAnimated) VanillaTypes(mezz.jei.api.constants.VanillaTypes) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IIngredients

use of mezz.jei.api.ingredients.IIngredients in project CraftTweaker by CraftTweaker.

the class ConflictCommand method gatherRecipes.

/**
 * Collects all recipes, converts them to the own class and adds them to the List
 */
private void gatherRecipes() {
    IRecipeRegistry reg = JEIAddonPlugin.recipeRegistry;
    for (IRecipeCategory category : reg.getRecipeCategories()) {
        if (category instanceof CraftingRecipeCategory) {
            List wrappers = reg.getRecipeWrappers(category);
            for (Object wrapper : wrappers) {
                if (wrapper instanceof IRecipeWrapper && !(wrapper instanceof TippedArrowRecipeWrapper)) {
                    IRecipeWrapper wrap = ((IRecipeWrapper) wrapper);
                    IIngredients ing = new Ingredients();
                    wrap.getIngredients(ing);
                    List<List<ItemStack>> inputs = ing.getInputs(ItemStack.class);
                    List<List<ItemStack>> outputs = ing.getOutputs(ItemStack.class);
                    // checks for having no outputs or having a "null" output
                    ItemStack output = outputs.size() > 0 ? outputs.get(0) != null ? outputs.get(0).size() > 0 ? outputs.get(0).get(0) : null : null : null;
                    // prevent checking recipes with "null" output
                    if (output == null) {
                        continue;
                    }
                    // differs shaped an shapeless recipes
                    if (wrapper instanceof IShapedCraftingRecipeWrapper) {
                        craftingRecipeEntries.add(new CraftingRecipeEntry(inputs, output, ((IShapedCraftingRecipeWrapper) wrapper).getWidth(), ((IShapedCraftingRecipeWrapper) wrapper).getHeight(), "noname"));
                    } else {
                        craftingRecipeEntries.add(new CraftingRecipeEntry(inputs, output, "noname"));
                    }
                }
            }
        }
    }
}
Also used : Ingredients(mezz.jei.ingredients.Ingredients) IIngredients(mezz.jei.api.ingredients.IIngredients) IRecipeRegistry(mezz.jei.api.IRecipeRegistry) IIngredients(mezz.jei.api.ingredients.IIngredients) ItemStack(net.minecraft.item.ItemStack) IShapedCraftingRecipeWrapper(mezz.jei.api.recipe.wrapper.IShapedCraftingRecipeWrapper)

Example 3 with IIngredients

use of mezz.jei.api.ingredients.IIngredients in project GregTech by GregTechCE.

the class GTRecipeWrapper method getIngredients.

@Override
public void getIngredients(IIngredients ingredients) {
    if (!recipe.getInputs().isEmpty()) {
        List<CountableIngredient> recipeInputs = recipe.getInputs();
        List<List<ItemStack>> matchingInputs = new ArrayList<>(recipeInputs.size());
        for (CountableIngredient ingredient : recipeInputs) {
            List<ItemStack> ingredientValues = Arrays.stream(ingredient.getIngredient().getMatchingStacks()).map(ItemStack::copy).sorted(OreDictUnifier.getItemStackComparator()).collect(Collectors.toList());
            ingredientValues.forEach(stack -> {
                if (ingredient.getCount() == 0) {
                    notConsumedInput.add(stack);
                    stack.setCount(1);
                } else
                    stack.setCount(ingredient.getCount());
            });
            matchingInputs.add(ingredientValues);
        }
        ingredients.setInputLists(VanillaTypes.ITEM, matchingInputs);
    }
    if (!recipe.getFluidInputs().isEmpty()) {
        List<FluidStack> recipeInputs = recipe.getFluidInputs().stream().map(FluidStack::copy).collect(Collectors.toList());
        recipeInputs.forEach(stack -> {
            if (stack.amount == 0) {
                notConsumedFluidInput.add(stack);
                stack.amount = 1;
            }
        });
        ingredients.setInputs(VanillaTypes.FLUID, recipeInputs);
    }
    if (!recipe.getOutputs().isEmpty() || !recipe.getChancedOutputs().isEmpty()) {
        List<ItemStack> recipeOutputs = recipe.getOutputs().stream().map(ItemStack::copy).collect(Collectors.toList());
        List<ChanceEntry> chancedOutputs = recipe.getChancedOutputs();
        for (ChanceEntry chancedEntry : chancedOutputs) {
            ItemStack chancedStack = chancedEntry.getItemStack();
            chanceOutput.put(chancedStack, chancedEntry);
            recipeOutputs.add(chancedStack);
        }
        recipeOutputs.sort(Comparator.comparingInt(stack -> {
            ChanceEntry chanceEntry = chanceOutput.get(stack);
            if (chanceEntry == null)
                return 0;
            return chanceEntry.getChance();
        }));
        ingredients.setOutputs(VanillaTypes.ITEM, recipeOutputs);
    }
    if (!recipe.getFluidOutputs().isEmpty()) {
        List<FluidStack> recipeOutputs = recipe.getFluidOutputs().stream().map(FluidStack::copy).collect(Collectors.toList());
        ingredients.setOutputs(VanillaTypes.FLUID, recipeOutputs);
    }
}
Also used : Recipe(gregtech.api.recipes.Recipe) OreDictUnifier(gregtech.api.unification.OreDictUnifier) java.util(java.util) Hash(it.unimi.dsi.fastutil.Hash) IIngredients(mezz.jei.api.ingredients.IIngredients) Object2ObjectOpenCustomHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap) IRecipeWrapper(mezz.jei.api.recipe.IRecipeWrapper) Collectors(java.util.stream.Collectors) RecipeProperty(gregtech.api.recipes.recipeproperties.RecipeProperty) I18n(net.minecraft.client.resources.I18n) ItemStack(net.minecraft.item.ItemStack) ObjectOpenCustomHashSet(it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet) ItemStackHashStrategy(gregtech.api.util.ItemStackHashStrategy) JEIHelpers(gregtech.integration.jei.utils.JEIHelpers) Minecraft(net.minecraft.client.Minecraft) VanillaTypes(mezz.jei.api.ingredients.VanillaTypes) FluidStack(net.minecraftforge.fluids.FluidStack) ChanceEntry(gregtech.api.recipes.Recipe.ChanceEntry) RecipeMap(gregtech.api.recipes.RecipeMap) CountableIngredient(gregtech.api.recipes.CountableIngredient) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack) ChanceEntry(gregtech.api.recipes.Recipe.ChanceEntry) CountableIngredient(gregtech.api.recipes.CountableIngredient)

Aggregations

IIngredients (mezz.jei.api.ingredients.IIngredients)3 ItemStack (net.minecraft.item.ItemStack)3 Collectors (java.util.stream.Collectors)2 BPBlocks (com.bluepowermod.init.BPBlocks)1 StandardAlloyFurnaceRecipe (com.bluepowermod.recipe.AlloyFurnaceRegistry.StandardAlloyFurnaceRecipe)1 Refs (com.bluepowermod.reference.Refs)1 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 CountableIngredient (gregtech.api.recipes.CountableIngredient)1 Recipe (gregtech.api.recipes.Recipe)1 ChanceEntry (gregtech.api.recipes.Recipe.ChanceEntry)1 RecipeMap (gregtech.api.recipes.RecipeMap)1 RecipeProperty (gregtech.api.recipes.recipeproperties.RecipeProperty)1 OreDictUnifier (gregtech.api.unification.OreDictUnifier)1 ItemStackHashStrategy (gregtech.api.util.ItemStackHashStrategy)1 JEIHelpers (gregtech.integration.jei.utils.JEIHelpers)1 Hash (it.unimi.dsi.fastutil.Hash)1 Object2ObjectOpenCustomHashMap (it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap)1 ObjectOpenCustomHashSet (it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet)1 java.util (java.util)1 Arrays (java.util.Arrays)1