Changes

55 bytes removed ,  19:32, 2 August 2021
Update to 1.17
Line 11: Line 11:  
There are two public instances of JsonOps: <code>JsonOps.INSTANCE</code> and <code>JsonOps.COMPRESSED</code>. Compressed data is represented as a single string to read/write. However, this is never used within vanilla itself.
 
There are two public instances of JsonOps: <code>JsonOps.INSTANCE</code> and <code>JsonOps.COMPRESSED</code>. Compressed data is represented as a single string to read/write. However, this is never used within vanilla itself.
   −
== NBTDynamicOps ==
+
== NbtOps ==
   −
The <code>NBTDynamicOps.INSTANCE</code> is an instance of <code>DynamicOps<INBT></code>, meaning it is used to convert java objects to and from <code>INBT</code> instances. This can be used for serializing data into packets to send across networks, as well as serializing persistant data for entities and similar objects.
+
The <code>NbtOps.INSTANCE</code> is an instance of <code>DynamicOps<Tag></code>, meaning it is used to convert java objects to and from <code>Tag</code> instances. This can be used for serializing data into packets to send across networks, as well as serializing persistent data for entities and similar objects.
   −
There is only one public instance of NBTDynamicOps: <code>NBTDynamicOps.INSTANCE</code>.
+
There is only one public instance of NbtOps: <code>NbtOps.INSTANCE</code>.
    
= Using DynamicOps =
 
= Using DynamicOps =
Line 25: Line 25:  
== Format Conversion ==
 
== Format Conversion ==
   −
By using the <code>DynamicOps#convertTo</code> instance method with a second DynamicOps instance, data can be converted between two different serialized formats, such as JsonElement to INBT and back.
+
By using the <code>DynamicOps#convertTo</code> instance method with a second DynamicOps instance, data can be converted between two different serialized formats, such as JsonElement to Tag and back.
    
<syntaxhighlight lang=java>
 
<syntaxhighlight lang=java>
// converting INBT to JsonElement
+
// converting Tag to JsonElement
JsonElement someJsonElement = NBTDynamicOps.INSTANCE.convertTo(JsonOps.INSTANCE, someNBT);
+
JsonElement someJsonElement = NbtOps.INSTANCE.convertTo(JsonOps.INSTANCE, someTag);
   −
// converting JsonElement to INBT
+
// converting JsonElement to Tag
INBT someNBT = JsonOps.INSTANCE.convertTo(NBTDynamicOps.INSTANCE, someJsonElement);
+
Tag someTag = JsonOps.INSTANCE.convertTo(NbtOps.INSTANCE, someJsonElement);
 
</syntaxhighlight>
 
</syntaxhighlight>
    
Depending on the implementation of the DynamicOps used, this may throw an exception or return an empty object if the two formats are incompatible.
 
Depending on the implementation of the DynamicOps used, this may throw an exception or return an empty object if the two formats are incompatible.
   −
In particular, it is '''not''' safe to convert lists of numbers to NBT in this manner, due to the NBT format's strong typing and the way the NBTDynamicOps attempts to create lists of numbers.
+
In particular, it is '''not''' safe to convert lists of numbers to NBT in this manner, due to the NBT format's strong typing and the way the NbtOps attempts to create lists of numbers.
    
= External Links =
 
= External Links =
 
* [https://kvverti.github.io/Documented-DataFixerUpper/snapshot/com/mojang/serialization/DynamicOps.html DynamicOps unofficial javadocs]
 
* [https://kvverti.github.io/Documented-DataFixerUpper/snapshot/com/mojang/serialization/DynamicOps.html DynamicOps unofficial javadocs]