Class ConfigurateOps
- All Implemented Interfaces:
DynamicOps<ConfigurationNode>
The DynamicOps interface should be thought of essentially as a way
to perform operations on a type without having to directly implement that
interface on the type. Rather than taking an object that implements an
interface, DFU methods take the implementation of the DynamicOps interface
plus the type implemented onto.
When possible, the first node's ConfigurationNode.copy() method
will be used to create a new node to contain results. Otherwise, the provided
factory will be used. The default factory creates a
CommentedConfigurationNode with the default serializer collection
but a custom factory may be provided.
DynamicOps has the following primitive types (as determined by those
codecs that implement PrimitiveCodec):
- boolean
- literal boolean, or numeric 1 for true, 0 for false
- byte
- numeric value,
coercedto a byte. IfcompressMaps(), a string may be parsed as a byte as well. - short
- numeric value,
coercedto a short. IfcompressMaps(), a string may be parsed as a short as well. - int
- numeric value,
coercedto an integer. IfcompressMaps(), a string may be parsed as an integer as well. - long
- numeric value,
coercedto a long. IfcompressMaps(), a string may be parsed as a long as well. - float
- numeric value,
coercedto a float. IfcompressMaps(), a string may be parsed as a float as well. - double
- numeric value,
coercedto a double. IfcompressMaps(), a string may be parsed as a double as well. String- Any scalar value, as
a string ByteBuffer- An array of bytes. Either a native byte array in the node, or (by default impl) a list of bytes
IntStream- A sequence of integers. Either a native int array in the node, or (by default impl) a list of integers
LongStream- A sequence of longs. Either a native long array in the node, or (by default impl) a list of longs
- Since:
- 4.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumProtection level for configuration node accesses through ops instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic ConfigurateOpsBuilderbuilder()Create a new builder for an ops instance.booleanWhether data passed through this ops will be compressed or not.<U> UconvertTo(DynamicOps<U> targetOps, ConfigurationNode source) Create a copy of the source node converted to a different data structure.createBoolean(boolean value) Create a new node using this ops instance's node factory, and set its value to the provided boolean.createList(Stream<ConfigurationNode> input) Create a new node containing values emitted byinputas list elements.createMap(Map<ConfigurationNode, ConfigurationNode> values) Create a new node containing the map entries from the mapvalues.createMap(Stream<Pair<ConfigurationNode, ConfigurationNode>> values) Create a new node containing the map entries from the streamvalues.createNumeric(Number value) Create a new node using this ops instance's node factory, and set its value to the provided number.createString(String value) Create a new node using this ops instance's node factory, and set its value to the provided string.empty()Create a new empty node using this ops instance's factory.emptyMap()static DynamicOps<ConfigurationNode>forSerializers(TypeSerializerCollection collection) Get an ops instance that will create nodes using the provided collection.static DynamicOps<ConfigurationNode>fromNode(ConfigurationNode value) Configure an ops instance using the options of an existing node.get(ConfigurationNode input, String key) Attempt to get the child ofinputatkey.getGeneric(ConfigurationNode input, ConfigurationNode key) Get a child of the provided node atkey.getList(ConfigurationNode input) Get a consumer that takes an action to perform on every element of list nodeinput.getMap(ConfigurationNode input) Get a map-like view of a copy of the contents ofinput.getMapValues(ConfigurationNode input) Return a stream of pairs of (key, value) for map data in the input node.getNumberValue(ConfigurationNode input) Get the value of the provided node if it is a number or boolean.getStream(ConfigurationNode input) Get the contents of list nodeinputas aStreamof nodes.getStringValue(ConfigurationNode input) Get the value of the provided node if it is a scalar, converted to aString.static DynamicOps<ConfigurationNode>instance()Get the shared instance of this class, which creates new nodes using the default factory.static DynamicOps<ConfigurationNode>instance(boolean compressed) Get the shared instance of this class, which creates new nodes using the default factory.mergeToList(ConfigurationNode input, List<ConfigurationNode> values) Appends nodes invaluesto copy of list nodeinput.mergeToList(ConfigurationNode input, ConfigurationNode value) Appends elementvalueto list nodeinput.mergeToMap(ConfigurationNode input, ConfigurationNode key, ConfigurationNode value) Update the child ofinputatkeywithvalue.mergeToPrimitive(ConfigurationNode prefix, ConfigurationNode value) Return a result where ifprefixis empty, the node isvalue, but otherwise returns an error.remove(ConfigurationNode input, String key) Get a copy ofinputwithout the value at nodekey.set(ConfigurationNode input, String key, ConfigurationNode value) Update a copy ofinputwithvalueat pathkey.toString()update(ConfigurationNode input, String key, Function<ConfigurationNode, ConfigurationNode> function) Copies the input node and transform its child atkey.updateGeneric(ConfigurationNode input, ConfigurationNode wrappedKey, Function<ConfigurationNode, ConfigurationNode> function) Copies the input node and transform the node atwrappedKey.static Dynamic<ConfigurationNode>wrap(ConfigurationNode node) Wrap a ConfigurationNode in aDynamicinstance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.mojang.serialization.DynamicOps
convertList, convertMap, createByte, createByteList, createDouble, createFloat, createInt, createIntList, createLong, createLongList, createShort, getBooleanValue, getByteBuffer, getIntStream, getLongStream, getMapEntries, getNumberValue, list, list, listBuilder, map, mapBuilder, mergeToMap, mergeToMap, readMap, withDecoder, withEncoder, withParser
-
Method Details
-
instance
Get the shared instance of this class, which creates new nodes using the default factory. The returned instance will not be compressed- Returns:
- the shared instance
- Since:
- 4.0.0
-
instance
Get the shared instance of this class, which creates new nodes using the default factory.See
compressMaps()for a description of what thecompressed
parameter does.- Parameters:
compressed- whether keys should be compressed in the output of this serializer- Returns:
- the shared instance
- Since:
- 4.0.0
-
forSerializers
Get an ops instance that will create nodes using the provided collection.- Parameters:
collection- collection to provide through created nodes' options- Returns:
- ops instance
- Since:
- 4.0.0
-
wrap
Wrap a ConfigurationNode in aDynamicinstance. The returned Dynamic will use the same type serializer collection as the original node for its operations.- Parameters:
node- the node to wrap- Returns:
- a wrapped node
- Since:
- 4.0.0
-
fromNode
Configure an ops instance using the options of an existing node.- Parameters:
value- the value type- Returns:
- values
- Since:
- 4.0.0
-
builder
Create a new builder for an ops instance.- Returns:
- builder
- Since:
- 4.0.0
-
compressMaps
Whether data passed through this ops will be compressed or not.In the context of DFU,
compressed
means that in situations where values are of aKeyabletype (as is with types like Minecraft Registries) rather than fully encoding each value, its index into the container is encoded.While data encoded this way may take less space to store, the compressed data will also require an explicit mapping of indices to values. If this is not stored with the node, the indices of values must be preserved to correctly deserialize compressed values.
For example, for an enum new values could only be appended, not added in the middle of the constants.
- Specified by:
compressMapsin interfaceDynamicOps<ConfigurationNode>- Returns:
- whether maps are compressed
-
empty
Create a new empty node using this ops instance's factory.- Specified by:
emptyin interfaceDynamicOps<ConfigurationNode>- Returns:
- the new node
-
emptyMap
- Specified by:
emptyMapin interfaceDynamicOps<ConfigurationNode>
-
emptyList
- Specified by:
emptyListin interfaceDynamicOps<ConfigurationNode>
-
convertTo
Create a copy of the source node converted to a different data structure.Value types will be preserved as much as possible, but a reverse conversion will most likely be lossy
- Specified by:
convertToin interfaceDynamicOps<ConfigurationNode>- Type Parameters:
U- output type- Parameters:
targetOps- output typesource- source value- Returns:
- output value
-
getNumberValue
Get the value of the provided node if it is a number or boolean.If
compressMaps()is true, values may be coerced from another type.- Specified by:
getNumberValuein interfaceDynamicOps<ConfigurationNode>- Parameters:
input- data source- Returns:
- extracted number
-
getStringValue
Get the value of the provided node if it is a scalar, converted to aString.- Specified by:
getStringValuein interfaceDynamicOps<ConfigurationNode>- Parameters:
input- data source- Returns:
- string | error
-
createNumeric
Create a new node using this ops instance's node factory, and set its value to the provided number.- Specified by:
createNumericin interfaceDynamicOps<ConfigurationNode>- Parameters:
value- value- Returns:
- new node with value
-
createBoolean
Create a new node using this ops instance's node factory, and set its value to the provided boolean.- Specified by:
createBooleanin interfaceDynamicOps<ConfigurationNode>- Parameters:
value- value- Returns:
- new node with value
-
createString
Create a new node using this ops instance's node factory, and set its value to the provided string.- Specified by:
createStringin interfaceDynamicOps<ConfigurationNode>- Parameters:
value- value- Returns:
- new node with value
-
mergeToPrimitive
public DataResult<ConfigurationNode> mergeToPrimitive(ConfigurationNode prefix, ConfigurationNode value) Return a result where ifprefixis empty, the node isvalue, but otherwise returns an error.- Specified by:
mergeToPrimitivein interfaceDynamicOps<ConfigurationNode>- Parameters:
prefix- starting valuevalue- to update base with- Returns:
- result of updated node or error
-
mergeToList
Appends elementvalueto list nodeinput.- Specified by:
mergeToListin interfaceDynamicOps<ConfigurationNode>- Parameters:
input- base node. Must be empty or of list typevalue- value to add as element to the list- Returns:
- success with modified node, or error if
inputcontains a non-listvalue
-
mergeToList
public DataResult<ConfigurationNode> mergeToList(ConfigurationNode input, List<ConfigurationNode> values) Appends nodes invaluesto copy of list nodeinput.- Specified by:
mergeToListin interfaceDynamicOps<ConfigurationNode>- Parameters:
input- base node. Must be empty or of list typevalues- list of values to append to base node- Returns:
- success with modified node, or error if
inputcontains a non-listvalue
-
mergeToMap
public DataResult<ConfigurationNode> mergeToMap(ConfigurationNode input, ConfigurationNode key, ConfigurationNode value) Update the child ofinputatkeywithvalue.This operation will only affect the returned copy of the input node
- Specified by:
mergeToMapin interfaceDynamicOps<ConfigurationNode>- Parameters:
input- base node. Must be empty or of map typekey- key relative to base nodevalue- value to set at empty node- Returns:
- success with modified node, or error if
inputcontains a non-listvalue
-
getMapValues
public DataResult<Stream<Pair<ConfigurationNode,ConfigurationNode>>> getMapValues(ConfigurationNode input) Return a stream of pairs of (key, value) for map data in the input node.If the input node is non-empty and not a map, the result will be a failure.
- Specified by:
getMapValuesin interfaceDynamicOps<ConfigurationNode>- Parameters:
input- input node- Returns:
- result, if successful, of a stream of pairs (key, value) of entries in the input node.
-
getMap
Get a map-like view of a copy of the contents ofinput.If the input node is non-empty and not a map, the result will be a failure.
- Specified by:
getMapin interfaceDynamicOps<ConfigurationNode>- Parameters:
input- input node- Returns:
- result, if successful, of map-like view of a copy of the input
-
getList
Get a consumer that takes an action to perform on every element of list nodeinput.As an example, to print out every node in a list (minus error checking):
getList(listNode).result().get() .accept(element -> System.out.println(element);- Specified by:
getListin interfaceDynamicOps<ConfigurationNode>- Parameters:
input- data source- Returns:
- result, that if successful will take an action to perform on every element
-
getStream
Get the contents of list nodeinputas aStreamof nodes.- Specified by:
getStreamin interfaceDynamicOps<ConfigurationNode>- Parameters:
input- data source- Returns:
- if node is empty or a list, stream of nodes
-
createMap
Create a new node containing the map entries from the streamvalues.Keys will be interpreted as a single Object, and can only currently access direct children.
- Specified by:
createMapin interfaceDynamicOps<ConfigurationNode>- Parameters:
values- entries in the map- Returns:
- newly created node
-
createMap
Create a new node containing the map entries from the mapvalues.Keys will be interpreted as a single Object, and can only currently access direct children.
- Specified by:
createMapin interfaceDynamicOps<ConfigurationNode>- Parameters:
values- unwrapped node map- Returns:
- newly created node
-
createList
Create a new node containing values emitted byinputas list elements.- Specified by:
createListin interfaceDynamicOps<ConfigurationNode>- Parameters:
input- data source- Returns:
- newly created node
-
remove
Get a copy ofinputwithout the value at nodekey.If the input node is not a map, the input node will be returned.
- Specified by:
removein interfaceDynamicOps<ConfigurationNode>- Parameters:
input- data sourcekey- key to the node to be removed- Returns:
- if node removed, a copy of the input without node, otherwise input
-
get
Attempt to get the child ofinputatkey.- Specified by:
getin interfaceDynamicOps<ConfigurationNode>- Parameters:
input- data sourcekey- child key- Returns:
- success containing child if child is non-virtual, otherwise failure
-
getGeneric
Get a child of the provided node atkey.Keys will be interpreted as a single Object, and can only currently access direct children.
- Specified by:
getGenericin interfaceDynamicOps<ConfigurationNode>- Parameters:
input- parent nodekey- wrapped key of child- Returns:
- success containing child if child is non-virtual, otherwise failure
-
set
Update a copy ofinputwithvalueat pathkey.- Specified by:
setin interfaceDynamicOps<ConfigurationNode>- Parameters:
input- data sourcekey- key of child nodevalue- value for child node- Returns:
- updated parent node
-
update
public ConfigurationNode update(ConfigurationNode input, String key, Function<ConfigurationNode, ConfigurationNode> function) Copies the input node and transform its child atkey.Return a copy of the input node with the child at
keytransformed by the provided functionIf there is no value at
key, the input node will be returned unmodified.- Specified by:
updatein interfaceDynamicOps<ConfigurationNode>- Parameters:
input- base valuekey- key to changefunction- function to process the node atwrappedKey- Returns:
- an updated copy of input node
-
updateGeneric
public ConfigurationNode updateGeneric(ConfigurationNode input, ConfigurationNode wrappedKey, Function<ConfigurationNode, ConfigurationNode> function) Copies the input node and transform the node atwrappedKey.Return a copy of the input node with the child at
wrappedKeytransformed by the provided functionIf there is no value at
wrappedKey, the input node will be returned unmodified.Keys will be interpreted as a single Object, and can only currently access direct children.
- Specified by:
updateGenericin interfaceDynamicOps<ConfigurationNode>- Parameters:
input- base valuewrappedKey- key to changefunction- function to process the node atwrappedKey- Returns:
- an updated copy of input node
-
toString
-