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;
}
Aggregations