Interface IRecipeHandler<T extends net.minecraft.world.item.crafting.Recipe<?>>

Type Parameters:
T - The generic type the recipe handler can receive. Refer to the implementation specifications for more information.
All Known Implementing Classes:
CookingRecipeHandler, CTShapedRecipeHandler, CTShapelessRecipeHandler, ShapedRecipeHandler, ShapelessRecipeHandler, SmithingTransformRecipeHandler, SmithingTrimRecipeHandler, StoneCutterRecipeHandler

public interface IRecipeHandler<T extends net.minecraft.world.item.crafting.Recipe<?>>
Represents a handler for a specific type of recipe indicated by the generic parameter.

Differently from IRecipeManager, there can be more than one handler for recipe type, since handlers are bound to the actual class type of the recipe in question (e.g. ShapelessRecipe.class, not minecraft:crafting_shapeless).

Since:
9.0.0
  • Method Details

    • dumpToCommandString

      String dumpToCommandString(IRecipeManager<? super T> manager, T recipe)
      Creates a String representation of a valid addRecipe (or alternative) call for the given subclass of Recipe.

      Recipe dumps are triggered by the /ct recipes or /ct recipes hand commands.

      All newlines added to either the start or the end of the string will be automatically trimmed.

      Parameters:
      manager - The recipe manager responsible for this kind of recipes.
      recipe - The recipe that is currently being dumped.
      Returns:
      A String representing a addRecipe (or similar) call.
      Since:
      9.0.0
    • doesConflict

      <U extends net.minecraft.world.item.crafting.Recipe<?>> boolean doesConflict(IRecipeManager<? super T> manager, T firstRecipe, U secondRecipe)
      Checks if the two recipes conflict with each other.

      In this case, a conflict is defined as the two recipes being made in the exact same way (e.g. with the same shape and the same ingredients if the two recipes are shaped crafting table ones).

      Conflicts are also considered symmetrical in this implementation, which means that if firstRecipe conflicts with secondRecipe, the opposite is also true.

      Type Parameters:
      U - The type of secondRecipe.
      Parameters:
      manager - The recipe manager responsible for this kind of recipes.
      firstRecipe - The recipe which should be checked for conflict.
      secondRecipe - The other recipe which firstRecipe should be checked against. The recipe may or may not be of the same type of firstRecipe. See the API note section for more details.
      Returns:
      Whether the firstRecipe conflicts with secondRecipe or not.
      Since:
      9.0.0
    • decompose

      Optional<IDecomposedRecipe> decompose(IRecipeManager<? super T> manager, T recipe)
      Decomposes a recipe from its complete form into an IDecomposedRecipe.

      The decomposition needs to be complete, meaning that any meaningful part of the recipe should be present in the returned decomposed recipe. The only exception is the name, as decomposed recipes only track IRecipeComponents, and names aren't one.

      It is allowed for an implementation to specify that the given recipe cannot be properly decomposed. Examples of this occurrence might be recipes whose behavior is completely determined by code, such as map cloning in vanilla. In this context, it is allowed to return Optional.empty().

      It is mandatory for a recipe handler to produce a decomposed recipe that can then be converted back into its complete form in recompose(IRecipeManager, ResourceLocation, IDecomposedRecipe). In other words, if the return value of this method isn't empty, then recompose(manager, name, decompose(manager, recipe).get()) must not return an empty optional.

      Parameters:
      manager - The recipe manager responsible for this kind of recipes.
      recipe - The recipe that should be decomposed.
      Returns:
      An Optional wrapping decomposed recipe, or an empty one if need be as specified above.
      Since:
      10.0.0
    • recompose

      Optional<T> recompose(IRecipeManager<? super T> manager, net.minecraft.resources.ResourceLocation name, IDecomposedRecipe recipe)
      Reconstructs a complete recipe from its decomposed form.

      The recomposition should be as complete as possible, making sure that all IRecipeComponents that are necessary to properly rebuild the recipe are present in the given IDecomposedRecipe. If the recipe presents unknown components, i.e. components that this handler doesn't know how to convert, the handler is allowed to throw an exception as detailed in the following paragraphs.

      It is allowed for an implementation to return Optional.empty() in case the recomposition fails for any reason, or if no decomposed recipe can be used to rebuild a recipe in its complete form, e.g. for map cloning in vanilla.

      It is mandatory for a recipe handler that knows how to decompose a recipe to also know how to recompose it. In other words, if decompose(IRecipeManager, Recipe) returns a non-empty Optional, then recompose(manager, name, decompose(manager, recipe).get()) must not return an empty optional nor throw an exception.

      Parameters:
      manager - The recipe manager responsible for this kind of recipes.
      name - The name to give to the recomposed recipe once it has been built. It is mandatory that Recipe.getId() and this parameter represent the same name.
      recipe - The IDecomposedRecipe that should be recomposed back into a complete form.
      Returns:
      An Optional wrapping the complete form of the recipe, or an empty one if need be as specified above.
      Throws:
      IllegalArgumentException - If any of the required recipe components are not present in the recipe, or they have invalid or meaningless values (e.g. an empty output). Optionally, if any unknown component is present in the decomposed recipe.
      Since:
      10.0.0