Class ReplacementHandlerHelper

java.lang.Object
com.blamejared.crafttweaker.api.recipe.handler.helper.ReplacementHandlerHelper

public final class ReplacementHandlerHelper extends Object
Set of helper functions that can replace ingredients according to the given IReplacementRules.
See Also:
  • Method Details

    • replaceNonNullIngredientList

      public static <T extends net.minecraft.world.item.crafting.Recipe<?>, U> Optional<Function<net.minecraft.resources.ResourceLocation,T>> replaceNonNullIngredientList(net.minecraft.core.NonNullList<U> originalIngredients, Class<U> ingredientClass, T recipe, List<IReplacementRule> rules, Function<net.minecraft.core.NonNullList<U>,Function<net.minecraft.resources.ResourceLocation,T>> factory)
      Replaces the given NonNullList of ingredients of type ingredientClass according to the given set of rules.

      This acts as the NonNullList equivalent of replaceIngredientList(List, Class, Recipe, List, Function), in case the recipe constructor explicitly requires a NonNullList to be passed as a parameter.

      Type Parameters:
      T - The type of the recipe whose ingredients are currently undergoing replacement.
      U - The type of the ingredient that is currently being replaced. No restrictions are placed on the type of the ingredient.
      Parameters:
      originalIngredients - The original NonNullList of ingredients that will be replaced; this should match the list of ingredients in the recipe.
      ingredientClass - The type of the ingredient that should be replaced. Its value may or may not correspond to the actual ingredient's class, although it must be one of its superclass (in other words, it is not necessary for ingredientClass == originalIngredients[i].getClass() for any i between 0 and originalIngredients.size(); on the other hand, ingredientClass.isAssignableFrom(originalIngredients[i].getClass()) must hold true for every i in the same range).
      recipe - The recipe whose ingredients are currently undergoing replacement.
      rules - The list of IReplacementRules that need to be applied to the recipe.
      factory - A Function that accepts a NonNullList of ingredients of type U as a first parameter and returns a Function that can create the recipe given an ID in the form of a ResourceLocation (it effectively is a factory for a recipe factory).
      Returns:
      An Optional holding a Function that is able to create a new recipe with the replaced ingredient list when given an ID in the form of a ResourceLocation, if any replacements have been carried out on one or more of its ingredients; Optional.empty() otherwise.
    • replaceIngredientList

      public static <T extends net.minecraft.world.item.crafting.Recipe<?>, U> Optional<Function<net.minecraft.resources.ResourceLocation,T>> replaceIngredientList(List<U> originalIngredients, Class<U> ingredientClass, T recipe, List<IReplacementRule> rules, Function<List<U>,Function<net.minecraft.resources.ResourceLocation,T>> factory)
      Replaces the given List of ingredients of type ingredientClass according to the given set of rules.

      If the recipe requires a NonNullList as a parameter, it is possible to use the more specialized version replaceNonNullIngredientList(NonNullList, Class, Recipe, List, Function).

      Type Parameters:
      T - The type of the recipe whose ingredients are currently undergoing replacement.
      U - The type of the ingredient that is currently being replaced. No restrictions are placed on the type of the ingredient.
      Parameters:
      originalIngredients - The original List of ingredients that will be replaced; this should match the list of ingredients in the recipe.
      ingredientClass - The type of the ingredient that should be replaced. Its value may or may not correspond to the actual ingredient's class, although it must be one of its superclass (in other words, it is not necessary for ingredientClass == originalIngredients[i].getClass() for any i between 0 and originalIngredients.size(); on the other hand, ingredientClass.isAssignableFrom(originalIngredients[i].getClass()) must hold true for every i in the same range).
      recipe - The recipe whose ingredients are currently undergoing replacement.
      rules - The list of IReplacementRules that need to be applied to the recipe.
      factory - A Function that accepts a List of ingredients of type U as a first parameter and returns a Function that can create the recipe given an ID in the form of a ResourceLocation (it effectively is a factory for a recipe factory).
      Returns:
      An Optional holding a Function that is able to create a new recipe with the replaced ingredient list when given an ID in the form of a ResourceLocation, if any replacements have been carried out on one or more of its ingredients; Optional.empty() otherwise.
    • replaceIngredientArray

      public static <T extends net.minecraft.world.item.crafting.Recipe<?>, U> Optional<Function<net.minecraft.resources.ResourceLocation,T>> replaceIngredientArray(U[] originalIngredients, Class<U> ingredientClass, T recipe, List<IReplacementRule> rules, Function<U[],Function<net.minecraft.resources.ResourceLocation,T>> factory)
      Replaces the given array of ingredients of type ingredientClass according to the given set of rules.
      Type Parameters:
      T - The type of the recipe whose ingredients are currently undergoing replacement.
      U - The type of the ingredient that is currently being replaced. No restrictions are placed on the type of the ingredient.
      Parameters:
      originalIngredients - The original array of ingredients that will be replaced; this should match the array of ingredients in the recipe.
      ingredientClass - The type of the ingredient that should be replaced. Its value may or may not correspond to the actual ingredient's class, although it must be one of its superclass (in other words, it is not necessary for ingredientClass == originalIngredients[i].getClass() for any i between 0 and originalIngredients.size(); on the other hand, ingredientClass.isAssignableFrom(originalIngredients[i].getClass()) must hold true for every i in the same range).
      recipe - The recipe whose ingredients are currently undergoing replacement.
      rules - The list of IReplacementRules that need to be applied to the recipe.
      factory - A Function that accepts an array of ingredients of type U as a first parameter and returns a Function that can create the recipe given an ID in the form of a ResourceLocation (it effectively is a factory for a recipe factory).
      Returns:
      An Optional holding a Function that is able to create a new recipe with the replaced ingredient list when given an ID in the form of a ResourceLocation, if any replacements have been carried out on one or more of its ingredients; Optional.empty() otherwise.