Search in sources :

Example 1 with RecipeManager

use of net.minecraft.item.crafting.RecipeManager in project minecolonies by Minecolonies.

the class JEIPlugin method buildVanillaRecipesMap.

private Map<IRecipeType<?>, List<IGenericRecipe>> buildVanillaRecipesMap() {
    final RecipeManager recipeManager = Minecraft.getInstance().level.getRecipeManager();
    final List<IGenericRecipe> craftingRecipes = new ArrayList<>();
    for (final IRecipe<CraftingInventory> recipe : recipeManager.byType(IRecipeType.CRAFTING).values()) {
        if (!recipe.canCraftInDimensions(3, 3))
            continue;
        tryAddingVanillaRecipe(craftingRecipes, recipe);
    }
    final List<IGenericRecipe> smeltingRecipes = new ArrayList<>();
    for (final IRecipe<IInventory> recipe : recipeManager.byType(IRecipeType.SMELTING).values()) {
        tryAddingVanillaRecipe(smeltingRecipes, recipe);
    }
    return new ImmutableMap.Builder<IRecipeType<?>, List<IGenericRecipe>>().put(IRecipeType.CRAFTING, craftingRecipes).put(IRecipeType.SMELTING, smeltingRecipes).build();
}
Also used : CraftingInventory(net.minecraft.inventory.CraftingInventory) IInventory(net.minecraft.inventory.IInventory) IRecipeType(net.minecraft.item.crafting.IRecipeType) RecipeManager(net.minecraft.item.crafting.RecipeManager) IRecipeManager(mezz.jei.api.recipe.IRecipeManager) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with RecipeManager

use of net.minecraft.item.crafting.RecipeManager in project minecolonies by ldtteam.

the class JEIPlugin method buildVanillaRecipesMap.

private Map<IRecipeType<?>, List<IGenericRecipe>> buildVanillaRecipesMap() {
    final RecipeManager recipeManager = Minecraft.getInstance().level.getRecipeManager();
    final List<IGenericRecipe> craftingRecipes = new ArrayList<>();
    for (final IRecipe<CraftingInventory> recipe : recipeManager.byType(IRecipeType.CRAFTING).values()) {
        if (!recipe.canCraftInDimensions(3, 3))
            continue;
        tryAddingVanillaRecipe(craftingRecipes, recipe);
    }
    final List<IGenericRecipe> smeltingRecipes = new ArrayList<>();
    for (final IRecipe<IInventory> recipe : recipeManager.byType(IRecipeType.SMELTING).values()) {
        tryAddingVanillaRecipe(smeltingRecipes, recipe);
    }
    return new ImmutableMap.Builder<IRecipeType<?>, List<IGenericRecipe>>().put(IRecipeType.CRAFTING, craftingRecipes).put(IRecipeType.SMELTING, smeltingRecipes).build();
}
Also used : CraftingInventory(net.minecraft.inventory.CraftingInventory) IInventory(net.minecraft.inventory.IInventory) IRecipeType(net.minecraft.item.crafting.IRecipeType) RecipeManager(net.minecraft.item.crafting.RecipeManager) IRecipeManager(mezz.jei.api.recipe.IRecipeManager) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with RecipeManager

use of net.minecraft.item.crafting.RecipeManager in project Ceramics by KnightMiner.

the class JEIPlugin method registerRecipes.

@Override
public void registerRecipes(IRecipeRegistration registration) {
    ClientWorld world = Minecraft.getInstance().world;
    assert world != null;
    RecipeManager recipeManager = world.getRecipeManager();
    List<KilnRecipe> results = new ArrayList<>();
    for (IRecipe<IInventory> recipe : recipeManager.getRecipes(Registration.KILN_RECIPE).values()) {
        // ignore dynamic
        if (recipe.isDynamic()) {
            continue;
        }
        // validate output
        ItemStack output = recipe.getRecipeOutput();
        if (output.isEmpty()) {
            Ceramics.LOG.error("Invalid kiln recipe {}, no output", recipe.getId());
            continue;
        }
        List<Ingredient> ingredients = recipe.getIngredients();
        if (ingredients.size() != 1) {
            Ceramics.LOG.error("Invalid kiln recipe {}, wrong number of inputs", recipe.getId());
            continue;
        }
        // recipe type
        if (!(recipe instanceof KilnRecipe)) {
            Ceramics.LOG.error("Invalid kiln recipe {}, wrong class", recipe.getId());
            continue;
        }
        // add to list
        results.add((KilnRecipe) recipe);
    }
    registration.addRecipes(results, KilnCategory.UID);
    // clay repair info
    List<ItemStack> clayRepair = CeramicsTags.Items.TERRACOTTA_CRACK_REPAIR.getAllElements().stream().map(ItemStack::new).collect(Collectors.toList());
    registration.addIngredientInfo(clayRepair, VanillaTypes.ITEM, Ceramics.lang("jei", "clay_repair"));
}
Also used : IInventory(net.minecraft.inventory.IInventory) KilnRecipe(knightminer.ceramics.recipe.KilnRecipe) Ingredient(net.minecraft.item.crafting.Ingredient) RecipeManager(net.minecraft.item.crafting.RecipeManager) ArrayList(java.util.ArrayList) ClientWorld(net.minecraft.client.world.ClientWorld) ItemStack(net.minecraft.item.ItemStack)

Example 4 with RecipeManager

use of net.minecraft.item.crafting.RecipeManager in project Mekanism by mekanism.

the class MekanismRecipeType method getRecipes.

@Nonnull
public List<RECIPE_TYPE> getRecipes(@Nullable World world) {
    if (world == null) {
        // Try to get a fallback world if we are in a context that may not have one
        // If we are on the client get the client's world, if we are on the server get the current server's world
        world = DistExecutor.safeRunForDist(() -> MekanismClient::tryGetClientWorld, () -> () -> ServerLifecycleHooks.getCurrentServer().overworld());
        if (world == null) {
            // If we failed, then return no recipes
            return Collections.emptyList();
        }
    }
    if (cachedRecipes.isEmpty()) {
        RecipeManager recipeManager = world.getRecipeManager();
        // TODO: Should we use the byType(RecipeType) that we ATd so that our recipes don't have to always return true for matching?
        List<RECIPE_TYPE> recipes = recipeManager.getRecipesFor(this, IgnoredIInventory.INSTANCE, world);
        if (this == SMELTING) {
            Map<ResourceLocation, IRecipe<IInventory>> smeltingRecipes = recipeManager.byType(IRecipeType.SMELTING);
            // Copy recipes our recipes to make sure it is mutable
            recipes = new ArrayList<>(recipes);
            for (Entry<ResourceLocation, IRecipe<IInventory>> entry : smeltingRecipes.entrySet()) {
                IRecipe<IInventory> smeltingRecipe = entry.getValue();
                ItemStack recipeOutput = smeltingRecipe.getResultItem();
                if (!smeltingRecipe.isSpecial() && !recipeOutput.isEmpty()) {
                    // TODO: Can Smelting recipes even be "special", if so can we add some sort of checker to make getOutput return the correct result
                    NonNullList<Ingredient> ingredients = smeltingRecipe.getIngredients();
                    int ingredientCount = ingredients.size();
                    ItemStackIngredient input;
                    if (ingredientCount == 0) {
                        // Something went wrong
                        continue;
                    } else if (ingredientCount == 1) {
                        input = ItemStackIngredient.from(ingredients.get(0));
                    } else {
                        ItemStackIngredient[] itemIngredients = new ItemStackIngredient[ingredientCount];
                        for (int i = 0; i < ingredientCount; i++) {
                            itemIngredients[i] = ItemStackIngredient.from(ingredients.get(i));
                        }
                        input = ItemStackIngredient.createMulti(itemIngredients);
                    }
                    recipes.add((RECIPE_TYPE) new SmeltingIRecipe(entry.getKey(), input, recipeOutput));
                }
            }
        }
        cachedRecipes = recipes;
    }
    return cachedRecipes;
}
Also used : IgnoredIInventory(mekanism.api.inventory.IgnoredIInventory) IInventory(net.minecraft.inventory.IInventory) ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) SmeltingIRecipe(mekanism.common.recipe.impl.SmeltingIRecipe) SmeltingIRecipe(mekanism.common.recipe.impl.SmeltingIRecipe) IRecipe(net.minecraft.item.crafting.IRecipe) ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) Ingredient(net.minecraft.item.crafting.Ingredient) ResourceLocation(net.minecraft.util.ResourceLocation) RecipeManager(net.minecraft.item.crafting.RecipeManager) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 5 with RecipeManager

use of net.minecraft.item.crafting.RecipeManager in project MCMOD-Industria by M-Marvin.

the class JEIPlugin method registerRecipes.

@SuppressWarnings("resource")
@Override
public void registerRecipes(IRecipeRegistration registration) {
    RecipeManager manager = Minecraft.getInstance().level.getRecipeManager();
    registration.addRecipes(getRecipes(manager, ModRecipeTypes.ALLOY), JEIRecipeCategories.ALLOY_FURNACE);
    registration.addRecipes(getRecipes(manager, ModRecipeTypes.THERMAL_ZENTRIFUGE), JEIRecipeCategories.THERMAL_ZENTRIFUGE);
    registration.addRecipes(getRecipes(manager, ModRecipeTypes.SCHREDDER), JEIRecipeCategories.SCHREDDER);
    registration.addRecipes(getRecipes(manager, ModRecipeTypes.BLENDING), JEIRecipeCategories.BLENDER);
    registration.addRecipes(getRecipes(manager, ModRecipeTypes.RIFINING), JEIRecipeCategories.RIFINING);
    registration.addRecipes(getRecipes(manager, ModRecipeTypes.FLUID_BATH), JEIRecipeCategories.FLUID_BATH);
    registration.addRecipes(getRecipes(manager, ModRecipeTypes.WASHING), JEIRecipeCategories.WASHING_PLANT);
    registration.addRecipes(getRecipes(manager, ModRecipeTypes.METAL_FORM), JEIRecipeCategories.METAL_FORMER);
    registration.addRecipes(getRecipes(manager, ModRecipeTypes.BLAST_FURNACE), JEIRecipeCategories.BLAST_FURNACE);
    registration.addRecipes(UtilHelper.toCollection(new FluidStack(ModFluids.COMPRESSED_AIR, 1500)), JEIRecipeCategories.AIR_COMPRESSOR);
    registration.addRecipes(MultipartBuildRecipes.getRecipes(), JEIRecipeCategories.MULTIPART_BUILD);
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) RecipeManager(net.minecraft.item.crafting.RecipeManager)

Aggregations

RecipeManager (net.minecraft.item.crafting.RecipeManager)5 IInventory (net.minecraft.inventory.IInventory)4 ArrayList (java.util.ArrayList)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 IGenericRecipe (com.minecolonies.api.crafting.IGenericRecipe)2 List (java.util.List)2 IRecipeManager (mezz.jei.api.recipe.IRecipeManager)2 CraftingInventory (net.minecraft.inventory.CraftingInventory)2 ItemStack (net.minecraft.item.ItemStack)2 IRecipeType (net.minecraft.item.crafting.IRecipeType)2 Ingredient (net.minecraft.item.crafting.Ingredient)2 Nonnull (javax.annotation.Nonnull)1 KilnRecipe (knightminer.ceramics.recipe.KilnRecipe)1 IgnoredIInventory (mekanism.api.inventory.IgnoredIInventory)1 ItemStackIngredient (mekanism.api.recipes.inputs.ItemStackIngredient)1 SmeltingIRecipe (mekanism.common.recipe.impl.SmeltingIRecipe)1 ClientWorld (net.minecraft.client.world.ClientWorld)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 FluidStack (net.minecraftforge.fluids.FluidStack)1