Interface IReplacementRule
- All Known Implementing Classes:
FullIngredientReplacementRule,IngredientReplacementRule,StackTargetingReplacementRule
Each replacement rule is responsible for replacing ingredients based on their type class and the rule that the implementation defines. It is not required for a replacement rule to apply the same way to different ingredient types nor to know how to apply itself to every possible ingredient type.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final IReplacementRuleRepresents a rule that does nothing. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Optional<T>Chains a series ofOptionals together, returning the first non-empty one, if available.describe()Describes in a short and simple sentence the behavior of this rule.<T,U extends net.minecraft.world.item.crafting.Recipe<?>>
Optional<T>getReplacement(T ingredient, Class<T> type, U recipe) Attempts to replace the given ingredient, with typetype, according to the rules defined by this replacement rule.static <T,U, S extends net.minecraft.world.item.crafting.Recipe<?>>
Optional<T>withType(T ingredient, Class<T> type, S recipe, Class<U> targetedType, BiFunction<U, S, Optional<U>> producer) Attempts to apply the givenproducerif the ingredient type matches the specified one.
-
Field Details
-
EMPTY
Represents a rule that does nothing.This replacement rule simply returns
Optional.empty()ingetReplacement(Object, Class, Recipe)for any possible set of parameters, representing effectively a no-op replacement rule.
-
-
Method Details
-
chain
Chains a series ofOptionals together, returning the first non-empty one, if available.- Type Parameters:
T- The type parameter of the various optionals.- Parameters:
optionals- The series ofOptionals to check.- Returns:
- The first non-empty optional, if present, or
Optional.empty()otherwise. - See Also:
-
withType
static <T,U, Optional<T> withTypeS extends net.minecraft.world.item.crafting.Recipe<?>> (T ingredient, Class<T> type, S recipe, Class<U> targetedType, BiFunction<U, S, Optional<U>> producer) Attempts to apply the givenproducerif the ingredient type matches the specified one.The function effectively represents the replacement rule that will be applied to
ingredient, as long astypeis the same astargetedType. This effectively provides a self-contained method to perform these checks without having to resort to unchecked casts in the implementation of the replacement rule.If the ingredient doesn't match the given type, then it's assumed that the given
producercannot operate on the ingredient, andOptional.empty()is returned.- Type Parameters:
T- The type of the ingredient that is passed to the function; its value should match the one ofgetReplacement(Object, Class, Recipe).U- The type of the ingredient that theproducerrecognizes.S- The type of the recipe that is currently being replaced; its value should match the one ofgetReplacement(Object, Class, Recipe).- Parameters:
ingredient- The ingredient that should be replaced; its value should match the input ofgetReplacement(Object, Class, Recipe).type- The type of theingredientthat should be replaced; its value should match the input ofgetReplacement(Object, Class, Recipe).recipe- The recipe that is currently being acted upon, ornullif this information cannot be provided; its value should match the input ofgetReplacement(Object, Class, Recipe).targetedType- The type the ingredient should have for it to be operated upon by theproducer. This value will be compared totypewith a direct equality check (i.e.type == targetedType).producer- ABiFunctionthat takes an ingredient of typetargetedTypeand the targeted recipe as an input and replaces the ingredient, returning either anOptionalwith the ingredient, orOptional.empty()if the ingredient cannot be replaced.- Returns:
- An
Optionalcontaining the replaced ingredient, iftypematchestargetedTypeandproducerdetermines that a replacement of the ingredient is needed;Optional.empty()in all other cases. - See Also:
-
getReplacement
<T,U extends net.minecraft.world.item.crafting.Recipe<?>> Optional<T> getReplacement(T ingredient, Class<T> type, U recipe) Attempts to replace the given ingredient, with typetype, according to the rules defined by this replacement rule.- Type Parameters:
T- The type of the ingredient that should be replaced.U- The type of the recipe that is currently being replaced.- Parameters:
ingredient- The ingredient that should be replaced.type- The type of the ingredient that should be replaced. Its value may or may not correspond to the actual ingredient's class, although it's guaranteed to be one of its superclasses (in other words, it is guaranteed thattype.isAssignableFrom(ingredient.getClass()), but the equality checktype == ingredient.getClass()is not guaranteed).recipe- The recipe that is currently being subjected to replacement, if any;nullotherwise.- Returns:
- An
Optionalcontaining the replaced ingredient, if this rule knows how to operate on the ingredient's type and deems that the ingredient should be replaced;Optional.empty()otherwise.
-
describe
String describe()Describes in a short and simple sentence the behavior of this rule.- Returns:
- The description of this rule.
-