Class NbtCompound

java.lang.Object
net.minecraft.nbt.NbtCompound
All Implemented Interfaces:
NbtElement

public class NbtCompound
extends Object
implements NbtElement
Represents an NBT compound object which holds unordered key-value pairs with distinct case-sensitive string keys.
  • Field Details

  • Constructor Details

    • NbtCompound

      protected NbtCompound​(Map<String,​NbtElement> entries)
    • NbtCompound

      public NbtCompound()
  • Method Details

    • write

      public void write​(DataOutput output) throws IOException
      Specified by:
      write in interface NbtElement
      Throws:
      IOException
    • getKeys

      public Set<String> getKeys()
    • getType

      public byte getType()
      Gets the type of this NBT element.
      Specified by:
      getType in interface NbtElement
      Returns:
      the type
    • getNbtType

      public NbtType<NbtCompound> getNbtType()
      Gets the NBT type definition of this NBT element.
      Specified by:
      getNbtType in interface NbtElement
      Returns:
      the element type definition
    • getSize

      public int getSize()
    • put

      @Nullable public NbtElement put​(String key, NbtElement element)
    • putByte

      public void putByte​(String key, byte value)
    • putShort

      public void putShort​(String key, short value)
    • putInt

      public void putInt​(String key, int value)
    • putLong

      public void putLong​(String key, long value)
    • putUuid

      public void putUuid​(String key, UUID value)
      Writes a UUID to its NBT representation in this NbtCompound.
    • getUuid

      public UUID getUuid​(String key)
      Reads a UUID from its NBT representation in this NbtCompound.
    • containsUuid

      public boolean containsUuid​(String key)
      Returns true if this NbtCompound contains a valid UUID representation associated with the given key. A valid UUID is represented by an int array of length 4.
    • putFloat

      public void putFloat​(String key, float value)
    • putDouble

      public void putDouble​(String key, double value)
    • putString

      public void putString​(String key, String value)
    • putByteArray

      public void putByteArray​(String key, byte[] value)
    • putIntArray

      public void putIntArray​(String key, int[] value)
    • putIntArray

      public void putIntArray​(String key, List<Integer> value)
    • putLongArray

      public void putLongArray​(String key, long[] value)
    • putLongArray

      public void putLongArray​(String key, List<Long> value)
    • putBoolean

      public void putBoolean​(String key, boolean value)
    • get

      @Nullable public NbtElement get​(String key)
    • getType

      public byte getType​(String key)
      Gets the NBT type of the element stored at the specified key.
      Returns:
      the element NBT type, or 0 if it does not exist
    • contains

      public boolean contains​(String key)
      Determines whether the NBT compound object contains the specified key.
      Returns:
      true if the key exists, else false
    • contains

      public boolean contains​(String key, int type)
      Returns whether the NBT compound object contains an element of the specified type at the specified key.

      The type restriction can also be 99, which only allows any type of number.

      Returns:
      true if the key exists and the element type is equivalent to the given type, else false
    • getByte

      public byte getByte​(String key)
    • getShort

      public short getShort​(String key)
    • getInt

      public int getInt​(String key)
    • getLong

      public long getLong​(String key)
    • getFloat

      public float getFloat​(String key)
    • getDouble

      public double getDouble​(String key)
    • getString

      public String getString​(String key)
    • getByteArray

      public byte[] getByteArray​(String key)
    • getIntArray

      public int[] getIntArray​(String key)
    • getLongArray

      public long[] getLongArray​(String key)
    • getCompound

      public NbtCompound getCompound​(String key)
    • getList

      public NbtList getList​(String key, int type)
    • getBoolean

      public boolean getBoolean​(String key)
    • remove

      public void remove​(String key)
    • toString

      public String toString()
      Specified by:
      toString in interface NbtElement
      Overrides:
      toString in class Object
    • isEmpty

      public boolean isEmpty()
    • createCrashReport

      private CrashReport createCrashReport​(String key, NbtType<?> reader, ClassCastException classCastException)
    • copy

      public NbtCompound copy()
      Description copied from interface: NbtElement
      Copies this NBT element.
      Specified by:
      copy in interface NbtElement
      Returns:
      the copied element
    • equals

      public boolean equals​(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • write

      private static void write​(String key, NbtElement element, DataOutput output) throws IOException
      Throws:
      IOException
    • readByte

      private static byte readByte​(DataInput input, NbtTagSizeTracker tracker) throws IOException
      Throws:
      IOException
    • readString

      private static String readString​(DataInput input, NbtTagSizeTracker tracker) throws IOException
      Throws:
      IOException
    • read

      private static NbtElement read​(NbtType<?> reader, String key, DataInput input, int depth, NbtTagSizeTracker tracker)
    • copyFrom

      public NbtCompound copyFrom​(NbtCompound source)
    • escapeTagKey

      protected static String escapeTagKey​(String key)
    • prettyPrintTagKey

      protected static Text prettyPrintTagKey​(String key)
    • toText

      public Text toText​(String indent, int depth)
      Specified by:
      toText in interface NbtElement
    • toMap

      protected Map<String,​NbtElement> toMap()