Posted October 17, 20231 yr I want to get a list of all the recipes, even ones defined in other mods. I found net.minecraft.world.item.crafting.Recipe, but I have no idea how to get a list of these. I have searched online, but most answers mention ForgeRegistries.RECIPES, which doesn't exist anymore.
October 18, 20231 yr Author Then what? List<CraftingRecipe> recipes = world.getRecipeManager().getAllRecipesFor(RecipeType.CRAFTING); for (CraftingRecipe recipe : recipes) { // ... } How do I get Item objects for the ingredients and result?
October 18, 20231 yr getAllRecipesFor returns a List of RecipeHolder. This mean that for each entry in the list you need to do entry.value to get the actual recipe. Once you have the recipe you can access its ingredients (which usually are called just like that). Do note that CraftingRecipe is an interface an therefore by itself doesn't have any ingredient reference. For that you need to check the actual implementation class of the recipe, like ShapedRecipe Edited October 18, 20231 yr by JimiIT92 Don't blame me if i always ask for your help. I just want to learn to be better
October 22, 20231 yr Author It looks like `getAllRecipesFor` is returning a List of CraftingRecipe, because this is valid: List<CraftingRecipe> recipes = world.getRecipeManager().getAllRecipesFor(RecipeType.CRAFTING); for (CraftingRecipe recipe : recipes) { // ... } I have tried doing this: Item result = recipe.getResultItem(RegistryAccess.EMPTY).getItem(); NonNullList<Ingredient> in = recipe.getIngredients(); for (Ingredient i : in) { for (ItemStack stack : i.getItems()) { Item ingredient = stack.getItem(); } } But this seems like a roundabout way of doing this, and I'm not sure whether it works. And I'm not sure why each Ingredient contains a list of items.
October 23, 20231 yr Quote It looks like `getAllRecipesFor` is returning a List of CraftingRecipe, because this is valid: Yes because you told it to get all of the crafting recipes: Quote getAllRecipesFor(RecipeType.CRAFTING); Since you seem confused about the crafting part, I'm assuming that you actually wanted to get all recipes for all recipe types? Including furnaces, smokers, etc? In which case you can just use the following: Collection<RecipeHolder<?>> recipes = world.getRecipeManager().getRecipes(); Quote And I'm not sure why each Ingredient contains a list of items. Well an ingredient just defines a list of items that could be valid for that entry. Consider for example the recipe for a chest. It uses the wooden planks tag which defines all of the wooden planks that can be used for each of those slots. Which is why there is several thousand(+) combinations that can be used to make a chest. So that `Ingredient` is what holds that information.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.