<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://forge.gemwire.uk/index.php?action=history&amp;feed=atom&amp;title=DynamicOps%2F1.18</id>
	<title>DynamicOps/1.18 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://forge.gemwire.uk/index.php?action=history&amp;feed=atom&amp;title=DynamicOps%2F1.18"/>
	<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=DynamicOps/1.18&amp;action=history"/>
	<updated>2026-05-22T22:54:33Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.0</generator>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=DynamicOps/1.18&amp;diff=3176&amp;oldid=prev</id>
		<title>ShrimpBot: Copy DynamicOps to MC1.18 archive</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=DynamicOps/1.18&amp;diff=3176&amp;oldid=prev"/>
		<updated>2022-06-10T07:44:22Z</updated>

		<summary type="html">&lt;p&gt;Copy &lt;a href=&quot;/wiki/DynamicOps&quot; title=&quot;DynamicOps&quot;&gt;DynamicOps&lt;/a&gt; to MC1.18 archive&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The &amp;lt;code&amp;gt;DynamicOps&amp;lt;/code&amp;gt; class is part of mojang's DataFixerUpper serialization library; DynamicOps are used alongside [[codecs/1.18|codecs]] to convert java objects to a serialized format and back. While Codecs describe how a java object is to be serialized, DynamicOps describe the format the object is to be serialized to.&lt;br /&gt;
&lt;br /&gt;
The DataFixerUpper library includes several DynamicOps for serializing to json; vanilla minecraft also includes a DynamicOps for serializing to minecraft's [[Using NBT/1.18|NBT]] format.&lt;br /&gt;
&lt;br /&gt;
= Builtin DynamicOps =&lt;br /&gt;
&lt;br /&gt;
== JsonOps ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;JsonOps&amp;lt;/code&amp;gt; DynamicOps are used to serialize and deserialize json data. These are instances of &amp;lt;code&amp;gt;DynamicOps&amp;lt;JsonElement&amp;gt;&amp;lt;/code&amp;gt;, meaning that they are used to convert java objects to and from &amp;lt;code&amp;gt;JsonElement&amp;lt;/code&amp;gt; instances. These can used in conjunction with codecs to serialize/deserialize objects from assets and datapacks.&lt;br /&gt;
&lt;br /&gt;
There are two public instances of JsonOps: &amp;lt;code&amp;gt;JsonOps.INSTANCE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;JsonOps.COMPRESSED&amp;lt;/code&amp;gt;. Compressed data is represented as a single string to read/write. However, this is never used within vanilla itself.&lt;br /&gt;
&lt;br /&gt;
== NbtOps ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;NbtOps.INSTANCE&amp;lt;/code&amp;gt; is an instance of &amp;lt;code&amp;gt;DynamicOps&amp;lt;Tag&amp;gt;&amp;lt;/code&amp;gt;, meaning it is used to convert java objects to and from &amp;lt;code&amp;gt;Tag&amp;lt;/code&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
There is only one public instance of NbtOps: &amp;lt;code&amp;gt;NbtOps.INSTANCE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Using DynamicOps =&lt;br /&gt;
&lt;br /&gt;
== Serializing and Deserializing ==&lt;br /&gt;
&lt;br /&gt;
By combining a &amp;lt;code&amp;gt;Codec&amp;lt;SomeJavaType&amp;gt;&amp;lt;/code&amp;gt; with a &amp;lt;code&amp;gt;DynamicOps&amp;lt;SomeSerializedFormat&amp;gt;&amp;lt;/code&amp;gt;, the proper java object can be converted to the serialized form and back. See [[codecs/1.18|codecs]] for details on this subject.&lt;br /&gt;
&lt;br /&gt;
== Format Conversion ==&lt;br /&gt;
&lt;br /&gt;
By using the &amp;lt;code&amp;gt;DynamicOps#convertTo&amp;lt;/code&amp;gt; instance method with a second DynamicOps instance, data can be converted between two different serialized formats, such as JsonElement to Tag and back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
// converting Tag to JsonElement&lt;br /&gt;
JsonElement someJsonElement = NbtOps.INSTANCE.convertTo(JsonOps.INSTANCE, someTag);&lt;br /&gt;
&lt;br /&gt;
// converting JsonElement to Tag&lt;br /&gt;
Tag someTag = JsonOps.INSTANCE.convertTo(NbtOps.INSTANCE, someJsonElement);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Depending on the implementation of the DynamicOps used, this may throw an exception or return an empty object if the two formats are incompatible.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= External Links =&lt;br /&gt;
* [https://kvverti.github.io/Documented-DataFixerUpper/snapshot/com/mojang/serialization/DynamicOps.html DynamicOps unofficial javadocs]&lt;/div&gt;</summary>
		<author><name>ShrimpBot</name></author>
	</entry>
</feed>