Interface ITargetingStrategy
- All Superinterfaces:
CommandStringDisplayable
A targeting strategy is thus responsible for determining how IRecipeComponents are treated when dealing
with replacement. For example, a strategy might determine that all composite components should be decomposed into
atoms.
For script writers, a strategy can be obtained with the <targetingstrategy> bracket handler.
For integration writers, an instance of a targeting strategy can be obtained through the find method. Any
newly created strategy must be registered in the CraftTweaker plugin to be available to users.
This is a FunctionalInterface whose functional method is
castStrategy(IRecipeComponent, Object, Function).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final net.minecraft.resources.ResourceLocationThe ID that identifies the strategy used in case of no other strategy being specified. -
Method Summary
Modifier and TypeMethodDescription<T> TcastStrategy(IRecipeComponent<T> component, T object, Function<T, T> replacer) Executes the strategy determined by thisITargetingStrategyon the given object.static ITargetingStrategyfind(net.minecraft.resources.ResourceLocation id) Obtains anITargetingStrategywith the given id, if available.default StringReturns the BEP to get this thingy
-
Field Details
-
DEFAULT_STRATEGY_ID
static final net.minecraft.resources.ResourceLocation DEFAULT_STRATEGY_IDThe ID that identifies the strategy used in case of no other strategy being specified.This strategy is guaranteed to always exist.
- Since:
- 10.0.0
-
-
Method Details
-
find
Obtains anITargetingStrategywith the given id, if available.It is invalid to call this method before the
IReplacerRegistryhas been fully built: attempting to do that will result in undefined behavior.- Parameters:
id- The id uniquely identifying the strategy to obtain.- Returns:
- The strategy with the given name.
- Throws:
NullPointerException- If no strategy with the given name exists- Since:
- 10.0.0
-
castStrategy
Executes the strategy determined by thisITargetingStrategyon the given object.It is allowed for a strategy to exhibit different behavior according to the given
IRecipeComponent, although such behavior is discouraged.- Type Parameters:
T- The type of the object pointed to by the component.- Parameters:
component- The component that is being analyzed by this strategy.object- The object that must be examined for potential replacement.replacer- AFunctionthat is responsible for carrying out the replacement. The argument given to the function is the object that should be replaced as determined by the current strategy. It might or might not be the same asobjector related to it. If the given object should not be replaced, thennullshould be returned to indicate this. On the contrary, any non-nullobject is implicitly determined to be a replacement, even if it matches the input parameter. This allows for further flexibility in the replacement behavior.- Returns:
- The replaced object as determined by a combination of the
replacerFunctionand this strategy. In particular, this strategy must returnnullif all invocations of thereplacerhave returnednull. This means that no replacement has been carried out. On the contrary, if at least one of the invocations has returned a non-nullvalue, then the return value of this function must also be non-null. It is up to the implementation to determine what to return. - Since:
- 10.0.0
-
getCommandString
Description copied from interface:CommandStringDisplayableReturns the BEP to get this thingy- Specified by:
getCommandStringin interfaceCommandStringDisplayable
-