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 Summary
Modifier and TypeMethodDescriptiondefault booleandefault ListRecipeComponent<T> default ListRecipeComponent<T> default ListRecipeComponent<T> asList()default ListRecipeComponent<T> default <K> RecipeComponent<TinyMap<K, T>> asMap(RecipeComponent<K> key) default RecipeComponent<TinyMap<Character, T>> static CustomObjectRecipeComponentbuilder(CustomObjectRecipeComponent.Key... keys) static CustomObjectRecipeComponentdefault voidbuildUniqueId(UniqueIdBuilder builder, T value) com.mojang.serialization.Codec<T> codec()default @Nullable RecipeComponentBuilderdefault booleanhasPriority(RecipeMatchContext cx, Object from) Declares whether this component should take priority when being considered by e.g.default booleanShallow empty check functiondefault booleankey(String name, ComponentRole role) Creates a newRecipeKeyfor this component with the given name.default booleanmatches(RecipeMatchContext cx, T value, ReplacementMatchInfo match) default <O> EitherRecipeComponent<T, O> or(RecipeComponent<O> other) default RecipeComponent<T> orSelf()default voidreadFromJson(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.default Treplace(RecipeScriptContext cx, T original, ReplacementMatchInfo match, Object with) default List<?> default StringtoString(OpsContainer ops, T value) type()dev.latvian.mods.rhino.type.TypeInfotypeInfo()Defines a description for how this component may be constructed.default voidvalidate(RecipeValidationContext ctx, T value) default RecipeComponent<T> default Twrap(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 aschema'sconstructor(s) or automatically generated builder methods.default voidwriteToJson(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.
-
Method Details
-
builder
-
builder
-
key
Creates a newRecipeKeyfor this component with the given name.- Parameters:
name- The name of the key- Returns:
- The created
RecipeKey
-
inputKey
-
outputKey
-
otherKey
-
type
RecipeComponentType<?> 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
Declares whether this component should take priority when being considered by e.g. anEitherRecipeComponentduring deserialization.- Parameters:
cx- Script contextfrom- The object to be deserialized from- Returns:
- Whether this component should take priority
-
wrap
Method to read the value contained within this component from an input object; this may be some arbitrary value passed into aschema'sconstructor(s) or automatically generated builder methods. By default, it will attempt to type wrap based ontypeInfo()- Parameters:
cx- Script contextfrom- 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 contextcv- A holder object to retrieve the component's value fromjson- 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 contextcv- The holder object to store the resulting value injson- 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
- Parameters:
cx- Script contextvalue- The value to checkmatch- The replacement match to check against- Returns:
- true if the given value matches the given replacement match.
-
replace
-
allowEmpty
default boolean allowEmpty() -
validate
-
isEmpty
Shallow empty check function -
buildUniqueId
-
toString
-
asList
-
asListOrSelf
-
asConditionalList
-
asConditionalListOrSelf
-
orSelf
-
asMap
-
asPatternKey
-
or
-
withCodec
-
createBuilder
-
spread
-
isIgnored
default boolean isIgnored()
-