Interface RecipeComponent<T>

Type Parameters:
T - The value type of this component
All Known Subinterfaces:
NumberComponent<S,T>, RecipeComponentWithParent<T>
All Known Implementing Classes:
BlockComponent, BlockStateComponent, BooleanComponent, CharacterComponent, CustomObjectRecipeComponent, EitherRecipeComponent, EnumComponent, FluidIngredientComponent, FluidStackComponent, IgnoreComponent, IngredientComponent, ItemStackComponent, ListRecipeComponent, MapRecipeComponent, NestedRecipeComponent, NumberComponent.DoubleRange, NumberComponent.FloatRange, NumberComponent.IntRange, NumberComponent.LongRange, RecipeComponentWithCodec, RegistryComponent, ResourceKeyComponent, SimpleRecipeComponent, SizedFluidIngredientComponent, SizedIngredientComponent, StringComponent, TagKeyComponent, TimeComponent

public interface RecipeComponent<T>
A recipe component is a reusable definition of a recipe element (such as an in/output item, a fluid, or even just a number value) that has a description associated with it and defines logic on how to serialize the value contained within the context of a recipe with a codec().

Recipe components are used in conjunction with RecipeKeys to define the structure of a recipe, and are also referred to by bulk recipe operations such as replacements.

There are lots of standard components provided in the dev.latvian.mods.kubejs.recipe.component package, including items and fluid in- and outputs, generic group and logic components (array, map, and, or) and all kinds of primitives (including specialised ones such as number ranges and characters), which you can use to more easily define standardised components for your own recipes, though you may also want to define your own components from the ground up depending on your use case.

See Also:
  • Method Details

    • builder

    • builder

    • key

      default RecipeKey<T> key(String name, ComponentRole role)
      Creates a new RecipeKey for this component with the given name.
      Parameters:
      name - The name of the key
      Returns:
      The created RecipeKey
    • inputKey

      default RecipeKey<T> inputKey(String name)
    • outputKey

      default RecipeKey<T> outputKey(String name)
    • otherKey

      default RecipeKey<T> otherKey(String name)
    • type

    • codec

      com.mojang.serialization.Codec<T> codec()
    • typeInfo

      dev.latvian.mods.rhino.type.TypeInfo typeInfo()
      Defines a description for how this component may be constructed. Type descriptions may be comprised of a primitive type such as a string, number or Java class (which may be useful if that that class has an appropriate type wrapper for it already), an array of fixed or dynamic length, a map / object, or a union of multiple types.

      Type descriptions are used by addons like ProbeJS to provide typing hints.

      Returns:
      A description of how this component may be constructed
    • hasPriority

      default boolean hasPriority(RecipeMatchContext cx, Object from)
      Declares whether this component should take priority when being considered by e.g. an EitherRecipeComponent during deserialization.
      Parameters:
      cx - Script context
      from - The object to be deserialized from
      Returns:
      Whether this component should take priority
    • wrap

      default T wrap(RecipeScriptContext cx, Object from)
      Method to read the value contained within this component from an input object; this may be some arbitrary value passed into a schema's constructor(s) or automatically generated builder methods. By default, it will attempt to type wrap based on typeInfo()
      Parameters:
      cx - Script context
      from - An object to be converted to a value for this component
      Returns:
      The value read from the input
    • writeToJson

      default void writeToJson(KubeRecipe recipe, RecipeComponentValue<T> cv, com.google.gson.JsonObject json)
      This method serves as a more specialized override for serializing to JSON, providing the JSON object as additional context.
      Parameters:
      recipe - The recipe object used for context
      cv - A holder object to retrieve the component's value from
      json - The root JSON object to write to (this might be the root of the recipe JSON, or a nested object inside if this component is contained within for example a RecipeComponentBuilder)
    • readFromJson

      default void readFromJson(KubeRecipe recipe, RecipeComponentValue<T> cv, com.google.gson.JsonObject json)
      This method serves as a more specialized override for deserializing from JSON, providing the JSON object as additional context.
      Parameters:
      recipe - The recipe object used for context
      cv - The holder object to store the resulting value in
      json - The root JSON object to read from (this might be the root of the recipe JSON, or a nested object inside if this component is contained within for example a RecipeComponentBuilder)
    • matches

      default boolean matches(RecipeMatchContext cx, T value, ReplacementMatchInfo match)
      Parameters:
      cx - Script context
      value - The value to check
      match - The replacement match to check against
      Returns:
      true if the given value matches the given replacement match.
    • replace

      default T replace(RecipeScriptContext cx, T original, ReplacementMatchInfo match, Object with)
    • allowEmpty

      default boolean allowEmpty()
    • validate

      default void validate(RecipeValidationContext ctx, T value)
    • isEmpty

      default boolean isEmpty(T value)
      Shallow empty check function
    • buildUniqueId

      default void buildUniqueId(UniqueIdBuilder builder, T value)
    • toString

      default String toString(OpsContainer ops, T value)
    • asList

      default ListRecipeComponent<T> asList()
    • asListOrSelf

      default ListRecipeComponent<T> asListOrSelf()
    • asConditionalList

      default ListRecipeComponent<T> asConditionalList()
    • asConditionalListOrSelf

      default ListRecipeComponent<T> asConditionalListOrSelf()
    • orSelf

      default RecipeComponent<T> orSelf()
    • asMap

      default <K> RecipeComponent<TinyMap<K,T>> asMap(RecipeComponent<K> key)
    • asPatternKey

      default RecipeComponent<TinyMap<Character,T>> asPatternKey()
    • or

      default <O> EitherRecipeComponent<T,O> or(RecipeComponent<O> other)
    • withCodec

      default RecipeComponent<T> withCodec(com.mojang.serialization.Codec<T> codec)
    • createBuilder

      @Nullable @Experimental default @Nullable RecipeComponentBuilder createBuilder()
    • spread

      default List<?> spread(T value)
    • isIgnored

      default boolean isIgnored()