Search in sources :

Example 1 with SmeltingIRecipe

use of mekanism.common.recipe.impl.SmeltingIRecipe 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)

Aggregations

Nonnull (javax.annotation.Nonnull)1 IgnoredIInventory (mekanism.api.inventory.IgnoredIInventory)1 ItemStackIngredient (mekanism.api.recipes.inputs.ItemStackIngredient)1 SmeltingIRecipe (mekanism.common.recipe.impl.SmeltingIRecipe)1 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 Ingredient (net.minecraft.item.crafting.Ingredient)1 RecipeManager (net.minecraft.item.crafting.RecipeManager)1 ResourceLocation (net.minecraft.util.ResourceLocation)1