Class RecipeKey<T>
- Type Parameters:
T- The type of element held by this key's component
A key is always associated with a RecipeComponent which represents the type of data that it holds.
Each recipe key has set of names that it may be called by in JSON, as well as a functionNames name
used in autogenerated methods and a primary name used for serialization.
A key may also be optional, which means that its value may not always be present in JSON and will also not
be serialized or written to the value map unless it is declared as alwaysWrite.
By default, each key will have a "builder" method generated for scripts using the first functionNames name.
You can disable this by setting noFunctions().
Finally, some types of components such as items or fluids may perform validation to ensure that they aren't holding empty data.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanfinal com.mojang.serialization.Codec<T> final RecipeComponent<T> booleanfinal Stringfinal SequencedSet<String> final ComponentRolefinal dev.latvian.mods.rhino.type.TypeInfo -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds an alternate name for this key in JSONAdds multiple alternate names for this key in JSONSet this in order to always write optional keys, even if their value hasn't changed.Marks this key as optional, with a default value ofnull.exclude()Excludes this key from auto-generated constructors.functionNames(String... names) Sets a list of names that are used to auto-generate builder functions in JS, e.g.functionNames(List<String> names) Sets a list of names that are used to auto-generate builder functions in JS, e.g.inthashCode()Disables the generation of builder functions for this key.booleanoptional()Returns true if this key has a defined optional valueoptional(RecipeOptional<T> value) Marks this key as optional, meaning that it can be omitted when deserializing recipes from JSON and will not be serialized unless it is explicitly set.Marks this key as optional, meaning that it can be omitted when deserializing recipes from JSON and will not be serialized unless it is explicitly set.com.google.gson.JsonObjecttoJson(RecipeSchemaStorage storage, RecipeSchemaType type, com.mojang.serialization.DynamicOps<com.google.gson.JsonElement> ops) toString()
-
Field Details
-
component
-
typeInfo
public final dev.latvian.mods.rhino.type.TypeInfo typeInfo -
codec
-
name
-
role
-
names
-
optional
-
excluded
public boolean excluded -
functionNames
-
alwaysWrite
public boolean alwaysWrite
-
-
Constructor Details
-
RecipeKey
-
-
Method Details
-
hashCode
public int hashCode() -
toString
-
optional
Marks this key as optional, meaning that it can be omitted when deserializing recipes from JSON and will not be serialized unless it is explicitly set.- Parameters:
value- The default value of this key; note that the instance supplied here will be used directly and across multiple recipes, so make sure to only pass immutable objects!- See Also:
-
optional
Marks this key as optional, meaning that it can be omitted when deserializing recipes from JSON and will not be serialized unless it is explicitly set.- Parameters:
value- The default value of this key; unlike inoptional(Object), the value will be computed at recipe initialization time, which makes it safe to pass mutable objects here.- See Also:
-
defaultOptional
Marks this key as optional, with a default value ofnull.- See Also:
-
optional
public boolean optional()Returns true if this key has a defined optional value- Returns:
- Whether this key is optional
-
alt
Adds an alternate name for this key in JSON- Parameters:
name- Another name this key may be called by
-
alt
Adds multiple alternate names for this key in JSON- Parameters:
names- A list of names this key may be called by
-
exclude
Excludes this key from auto-generated constructors. Requires optional() value to also be set.This method does nothing if a custom constructor has been set.
-
noFunctions
Disables the generation of builder functions for this key. -
functionNames
Sets a list of names that are used to auto-generate builder functions in JS, e.g..xp(value). The first one of these names will be the preferred one that documentation should recommend. -
functionNames
Sets a list of names that are used to auto-generate builder functions in JS, e.g..xp(value). The first one of these names will be the preferred one that documentation should recommend. -
alwaysWrite
Set this in order to always write optional keys, even if their value hasn't changed.This can also be used to always populate the value map with a default value for an optional key.
-
getValidFunctionNames
-
getPrimaryFunctionName
-
toJson
public com.google.gson.JsonObject toJson(RecipeSchemaStorage storage, RecipeSchemaType type, com.mojang.serialization.DynamicOps<com.google.gson.JsonElement> ops)
-