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
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static @interface 
    Annotates an IRecipeHandler indicating which recipe classes it is able to handle.
  • Method Summary

    Modifier and Type
    Method
    Description
    decompose(IRecipeManager<? super T> manager, net.minecraft.core.RegistryAccess registryAccess, T recipe)
    Decomposes a recipe from its complete form into an IDecomposedRecipe.
    <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.
    dumpToCommandString(IRecipeManager<? super T> manager, net.minecraft.core.RegistryAccess registryAccess, net.minecraft.world.item.crafting.RecipeHolder<T> holder)
    Creates a String representation of a valid addRecipe (or alternative) call for the given subclass of Recipe.
    recompose(IRecipeManager<? super T> manager, net.minecraft.core.RegistryAccess registryAccess, IDecomposedRecipe recipe)
    Reconstructs a complete recipe from its decomposed form.
  • Method Details

    • dumpToCommandString

      String dumpToCommandString(IRecipeManager<? super T> manager, net.minecraft.core.RegistryAccess registryAccess, net.minecraft.world.item.crafting.RecipeHolder<T> holder)
      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.
      registryAccess - Access to registries to get the output of recipes.
      holder - The recipe that is currently being dumped.
      Returns:
      A String representing a addRecipe (or similar) call.
      Since:
      11.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, net.minecraft.core.RegistryAccess registryAccess, 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, RegistryAccess, 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.
      registryAccess - Access to registries to get the output 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.core.RegistryAccess registryAccess, 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, RegistryAccess, 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.
      registryAccess - Access to registries.
      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:
      11.0.0