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.3.0
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic enumProtection level for configuration node accesses through ops instance.
- 
Method SummaryModifier 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.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.mojang.serialization.DynamicOpsconvertList, 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- 
instanceGet 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.3.0
 
- 
instanceGet 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.3.0
 
- 
forSerializersGet 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.3.0
 
- 
wrapWrap 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.3.0
 
- 
fromNodeConfigure an ops instance using the options of an existing node.- Parameters:
- value- the value type
- Returns:
- values
- Since:
- 4.3.0
 
- 
builderCreate a new builder for an ops instance.- Returns:
- builder
- Since:
- 4.3.0
 
- 
compressMapsWhether 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 interface- DynamicOps<ConfigurationNode>
- Returns:
- whether maps are compressed
 
- 
emptyCreate a new empty node using this ops instance's factory.- Specified by:
- emptyin interface- DynamicOps<ConfigurationNode>
- Returns:
- the new node
 
- 
emptyMap- Specified by:
- emptyMapin interface- DynamicOps<ConfigurationNode>
 
- 
emptyList- Specified by:
- emptyListin interface- DynamicOps<ConfigurationNode>
 
- 
convertToCreate 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 interface- DynamicOps<ConfigurationNode>
- Type Parameters:
- U- output type
- Parameters:
- targetOps- output type
- source- source value
- Returns:
- output value
 
- 
getNumberValueGet 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 interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- data source
- Returns:
- extracted number
 
- 
getStringValueGet the value of the provided node if it is a scalar, converted to aString.- Specified by:
- getStringValuein interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- data source
- Returns:
- string | error
 
- 
createNumericCreate a new node using this ops instance's node factory, and set its value to the provided number.- Specified by:
- createNumericin interface- DynamicOps<ConfigurationNode>
- Parameters:
- value- value
- Returns:
- new node with value
 
- 
createBooleanCreate a new node using this ops instance's node factory, and set its value to the provided boolean.- Specified by:
- createBooleanin interface- DynamicOps<ConfigurationNode>
- Parameters:
- value- value
- Returns:
- new node with value
 
- 
createStringCreate a new node using this ops instance's node factory, and set its value to the provided string.- Specified by:
- createStringin interface- DynamicOps<ConfigurationNode>
- Parameters:
- value- value
- Returns:
- new node with value
 
- 
mergeToPrimitivepublic DataResult<ConfigurationNode> mergeToPrimitive(ConfigurationNode prefix, ConfigurationNode value) Return a result where ifprefixis empty, the node isvalue, but otherwise returns an error.- Specified by:
- mergeToPrimitivein interface- DynamicOps<ConfigurationNode>
- Parameters:
- prefix- starting value
- value- to update base with
- Returns:
- result of updated node or error
 
- 
mergeToListAppends elementvalueto list nodeinput.- Specified by:
- mergeToListin interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- base node. Must be empty or of list type
- value- value to add as element to the list
- Returns:
- success with modified node, or error if inputcontains a non-listvalue
 
- 
mergeToListpublic DataResult<ConfigurationNode> mergeToList(ConfigurationNode input, List<ConfigurationNode> values) Appends nodes invaluesto copy of list nodeinput.- Specified by:
- mergeToListin interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- base node. Must be empty or of list type
- values- list of values to append to base node
- Returns:
- success with modified node, or error if inputcontains a non-listvalue
 
- 
mergeToMappublic 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 interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- base node. Must be empty or of map type
- key- key relative to base node
- value- value to set at empty node
- Returns:
- success with modified node, or error if inputcontains a non-listvalue
 
- 
getMapValuespublic 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 interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- input node
- Returns:
- result, if successful, of a stream of pairs (key, value) of entries in the input node.
 
- 
getMapGet 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 interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- input node
- Returns:
- result, if successful, of map-like view of a copy of the input
 
- 
getListGet 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 interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- data source
- Returns:
- result, that if successful will take an action to perform on every element
 
- 
getStreamGet the contents of list nodeinputas aStreamof nodes.- Specified by:
- getStreamin interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- data source
- Returns:
- if node is empty or a list, stream of nodes
 
- 
createMapCreate 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 interface- DynamicOps<ConfigurationNode>
- Parameters:
- values- entries in the map
- Returns:
- newly created node
 
- 
createMapCreate 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 interface- DynamicOps<ConfigurationNode>
- Parameters:
- values- unwrapped node map
- Returns:
- newly created node
 
- 
createListCreate a new node containing values emitted byinputas list elements.- Specified by:
- createListin interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- data source
- Returns:
- newly created node
 
- 
removeGet a copy ofinputwithout the value at nodekey.If the input node is not a map, the input node will be returned. - Specified by:
- removein interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- data source
- key- key to the node to be removed
- Returns:
- if node removed, a copy of the input without node, otherwise input
 
- 
getAttempt to get the child ofinputatkey.- Specified by:
- getin interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- data source
- key- child key
- Returns:
- success containing child if child is non-virtual, otherwise failure
 
- 
getGenericGet 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 interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- parent node
- key- wrapped key of child
- Returns:
- success containing child if child is non-virtual, otherwise failure
 
- 
setUpdate a copy ofinputwithvalueat pathkey.- Specified by:
- setin interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- data source
- key- key of child node
- value- value for child node
- Returns:
- updated parent node
 
- 
updatepublic 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 interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- base value
- key- key to change
- function- function to process the node at- wrappedKey
- Returns:
- an updated copy of input node
 
- 
updateGenericpublic 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 interface- DynamicOps<ConfigurationNode>
- Parameters:
- input- base value
- wrappedKey- key to change
- function- function to process the node at- wrappedKey
- Returns:
- an updated copy of input node
 
- 
toString
 
-