Difference between revisions of "Named Binary Tag"

From Forge Community Wiki
m (SciWhiz12 moved page Named Binary Tag to Named Binary Tag: expand the title)
(Update to 1.17)
 
Line 2: Line 2:
  
 
== NBT Types ==
 
== NBT Types ==
There are a total of fourteen different nbt data types that can be parsed. The most common one to use is <code>CompoundNBT</code>s within a <code>TileEntity</code> or <code>Entity</code> when it comes to writing to the disk. However, on capabilities, other types can be specified to reduce the space it takes on a file.
+
There are a total of fourteen different nbt data types that can be parsed. The most common one to use is <code>CompoundTag</code>s within a <code>BlockEntity</code> or <code>Entity</code> when it comes to writing to the disk. However, on capabilities, other types can be specified to reduce the space it takes on a file.
  
All types implement <code>INBT</code> in some fashion. This interface holds basic methods for writing to a file and copying itself. It also holds basic methods to determine the output to a chat line.
+
All types implement <code>Tag</code> in some fashion. This interface holds basic methods for writing to a file and copying itself. It also holds basic methods to determine the output to a chat line.
 
{| class="wikitable sortable" border=1
 
{| class="wikitable sortable" border=1
 
!Id !!Name !!Description  
 
!Id !!Name !!Description  
 
|-
 
|-
|  0  ||  <code>EndNBT</code>  ||  Specifies the end of an nbt file.  
+
|  0  ||  <code>EndTag</code>  ||  Specifies the end of an nbt file.  
 
|-
 
|-
|  1  ||  <code>ByteNBT</code>  ||  Holds a byte. Also used to store a boolean value.  
+
|  1  ||  <code>ByteTag</code>  ||  Holds a byte. Also used to store a boolean value.  
 
|-
 
|-
|  2  ||  <code>ShortNBT</code>  ||  Holds a short.  
+
|  2  ||  <code>ShortTag</code>  ||  Holds a short.  
 
|-
 
|-
|  3  ||  <code>IntNBT</code>  ||  Holds an integer.  
+
|  3  ||  <code>IntTag</code>  ||  Holds an integer.  
 
|-
 
|-
|  4  ||  <code>LongNBT</code>  ||  Holds a long.  
+
|  4  ||  <code>LongTag</code>  ||  Holds a long.  
 
|-
 
|-
|  5  ||  <code>FloatNBT</code>  ||  Holds a float.  
+
|  5  ||  <code>FloatTag</code>  ||  Holds a float.  
 
|-
 
|-
|  6  ||  <code>DoubleNBT</code>  ||  Holds a double.  
+
|  6  ||  <code>DoubleTag</code>  ||  Holds a double.  
 
|-
 
|-
|  7  ||  <code>ByteArrayNBT</code>  ||  Holds a byte array. Can be parsed from an array of primitive bytes or a list of byte objects.  
+
|  7  ||  <code>ByteArrayTag</code>  ||  Holds a byte array. Can be parsed from an array of primitive bytes or a list of byte objects.  
 
|-
 
|-
|  8  ||  <code>StringNBT</code>  ||  Holds a string.  
+
|  8  ||  <code>StringTag</code>  ||  Holds a string.  
 
|-
 
|-
|  9  ||  <code>ListNBT</code>  ||  Holds a list of a specific <code>INBT</code>.  
+
|  9  ||  <code>ListTag</code>  ||  Holds a list of a specific <code>Tag</code>.  
 
|-
 
|-
|  10  ||  <code>CompoundNBT</code>  ||  Holds an object comprised of <code>INBT</code>s. It works similarly to a java object where it can store other primitives, objects, or itself inside.  
+
|  10  ||  <code>CompoundTag</code>  ||  Holds an object comprised of <code>Tag</code>s. It works similarly to a java object where it can store other primitives, objects, or itself inside.  
 
|-
 
|-
|  11  ||  <code>IntArrayNBT</code>  ||  Holds an integer array. Can be parsed from an array of primitive integers or a list of integer objects.  
+
|  11  ||  <code>IntArrayTag</code>  ||  Holds an integer array. Can be parsed from an array of primitive integers or a list of integer objects.  
 
|-
 
|-
|  12  ||  <code>LongArrayNBT</code>  ||  Holds an long array. Can be parsed from an array of primitive long, a list of long objects, or a <code>LongSet</code>.  
+
|  12  ||  <code>LongArrayTag</code>  ||  Holds an long array. Can be parsed from an array of primitive long, a list of long objects, or a <code>LongSet</code>.  
 
|-
 
|-
|  99  ||  <code>NumberNBT</code>  ||  Holds a generic number. Used when the specific <code>INBT</code> for a number is not specified. All numbers can be converted to each other.  
+
|  99  ||  <code>NumericTag</code>  ||  Holds a generic number. Used when the specific <code>Tag</code> for a number is not specified. All numbers can be converted to each other.  
 
|-
 
|-
 
|}
 
|}
  
In most cases, you will only have to deal with <code>CompoundNBT</code> and <code>ListNBT</code>. The others are usually handled internally by whichever type uses them.
+
In most cases, you will only have to deal with <code>CompoundTag</code> and <code>ListTag</code>. The others are usually handled internally by whichever type uses them.
  
 
== Common Usages ==
 
== Common Usages ==
<code>CompoundNBT</code>s are used similar to objects. You can <code>put</code> and value within them using a key. You can then retrieve the value once again with that same key. It has specific methods for putting and getting most of the different types of data (e.g. an integer using <code>putInt</code> and <code>getInt</code>).
+
<code>CompoundTag</code>s are used similar to objects. You can <code>put</code> and value within them using a key. You can then retrieve the value once again with that same key. It has specific methods for putting and getting most of the different types of data (e.g. an integer using <code>putInt</code> and <code>getInt</code>).
  
<code>ListNBT</code>s are functionally the same as <code>ArrayList</code>s. You can <code>add</code>, <code>remove</code>, <code>set</code>, or <code>get</code> a specific NBT type.
+
<code>ListTag</code>s are functionally the same as <code>ArrayList</code>s. You can <code>add</code>, <code>remove</code>, <code>set</code>, or <code>get</code> a specific NBT type.

Latest revision as of 18:26, 2 August 2021

Information between two points are passed in many different ways in Minecraft. The most common of them is known as NBTs. NBTs are a structured binary file used to store information on the disk. They are also used as intermediaries to hold information that will be sent across a network. Understanding and utilizing NBTs properly is a good start to understanding disk storage in general.

NBT Types

There are a total of fourteen different nbt data types that can be parsed. The most common one to use is CompoundTags within a BlockEntity or Entity when it comes to writing to the disk. However, on capabilities, other types can be specified to reduce the space it takes on a file.

All types implement Tag in some fashion. This interface holds basic methods for writing to a file and copying itself. It also holds basic methods to determine the output to a chat line.

Id Name Description
0 EndTag Specifies the end of an nbt file.
1 ByteTag Holds a byte. Also used to store a boolean value.
2 ShortTag Holds a short.
3 IntTag Holds an integer.
4 LongTag Holds a long.
5 FloatTag Holds a float.
6 DoubleTag Holds a double.
7 ByteArrayTag Holds a byte array. Can be parsed from an array of primitive bytes or a list of byte objects.
8 StringTag Holds a string.
9 ListTag Holds a list of a specific Tag.
10 CompoundTag Holds an object comprised of Tags. It works similarly to a java object where it can store other primitives, objects, or itself inside.
11 IntArrayTag Holds an integer array. Can be parsed from an array of primitive integers or a list of integer objects.
12 LongArrayTag Holds an long array. Can be parsed from an array of primitive long, a list of long objects, or a LongSet.
99 NumericTag Holds a generic number. Used when the specific Tag for a number is not specified. All numbers can be converted to each other.

In most cases, you will only have to deal with CompoundTag and ListTag. The others are usually handled internally by whichever type uses them.

Common Usages

CompoundTags are used similar to objects. You can put and value within them using a key. You can then retrieve the value once again with that same key. It has specific methods for putting and getting most of the different types of data (e.g. an integer using putInt and getInt).

ListTags are functionally the same as ArrayLists. You can add, remove, set, or get a specific NBT type.