Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

  • 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?

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 :)

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.