Jump to content

Recommended Posts

Posted

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.

Posted (edited)

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 by JimiIT92

Don't blame me if i always ask for your help. I just want to learn to be better :)

Posted

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.

Posted
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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.