Interface ITargetingStrategy

All Superinterfaces:
CommandStringDisplayable

@ZenRegister public interface ITargetingStrategy extends CommandStringDisplayable
Represents a way of targeting components for replacement.

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).

Since:
10.0.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final net.minecraft.resources.ResourceLocation
    The ID that identifies the strategy used in case of no other strategy being specified.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    castStrategy(IRecipeComponent<T> component, T object, Function<T,T> replacer)
    Executes the strategy determined by this ITargetingStrategy on the given object.
    find(net.minecraft.resources.ResourceLocation id)
    Obtains an ITargetingStrategy with the given id, if available.
    default String
    Returns the BEP to get this thingy
  • Field Details

    • DEFAULT_STRATEGY_ID

      static final net.minecraft.resources.ResourceLocation DEFAULT_STRATEGY_ID
      The 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

      static ITargetingStrategy find(net.minecraft.resources.ResourceLocation id)
      Obtains an ITargetingStrategy with the given id, if available.

      It is invalid to call this method before the IReplacerRegistry has 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

      <T> T castStrategy(IRecipeComponent<T> component, T object, Function<T,T> replacer)
      Executes the strategy determined by this ITargetingStrategy on 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 - A Function that 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 as object or related to it. If the given object should not be replaced, then null should be returned to indicate this. On the contrary, any non-null object 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 replacer Function and this strategy. In particular, this strategy must return null if all invocations of the replacer have returned null. This means that no replacement has been carried out. On the contrary, if at least one of the invocations has returned a non-null value, 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

      default String getCommandString()
      Description copied from interface: CommandStringDisplayable
      Returns the BEP to get this thingy
      Specified by:
      getCommandString in interface CommandStringDisplayable