Interface NbtCompound

All Superinterfaces:
ClonableWrapper, Iterable<NbtBase<?>>, NbtBase<Map<String,NbtBase<?>>>

public interface NbtCompound extends NbtBase<Map<String,NbtBase<?>>>, Iterable<NbtBase<?>>
Represents a mapping of arbitrary NBT elements and their unique names.

Use NbtFactory to load or create an instance.

The NbtBase.getValue() method returns a Map that will return the full content of this NBT compound, but may throw an UnsupportedOperationException for any of the write operations.

  • Method Details

    • getValue

      @Deprecated Map<String,NbtBase<?>> getValue()
      Deprecated.
      Description copied from interface: NbtBase
      Retrieve the value of this NBT tag.

      Is either a primitive wrapper, String, List or a Map.

      Users are encouraged to cast an NBT compound to NbtCompound and use its put and get-methods instead of accessing its content from getValue().

      All operations that modify collections directly, such as List.add(Object) or Map.clear(), are considered optional. This also include members in Iterator and ListIterator. Operations that are not implemented throw a UnsupportedOperationException.

      Specified by:
      getValue in interface NbtBase<Map<String,NbtBase<?>>>
      Returns:
      Value of this tag.
    • containsKey

      boolean containsKey(String key)
      Determine if an entry with the given key exists or not.
      Parameters:
      key - - the key to lookup.
      Returns:
      TRUE if an entry with the given key exists, FALSE otherwise.
    • getKeys

      Set<String> getKeys()
      Retrieve a Set view of the keys of each entry in this compound.
      Returns:
      The keys of each entry.
    • getValue

      <T> NbtBase<T> getValue(String key)
      Retrieve the value of a given entry.
      Type Parameters:
      T - Type
      Parameters:
      key - - key of the entry to retrieve.
      Returns:
      The value of this entry, or NULL if not found.
    • getValueOrDefault

      NbtBase<?> getValueOrDefault(String key, NbtType type)
      Retrieve a value by its key, or assign and return a new NBT element if it doesn't exist.
      Parameters:
      key - - the key of the entry to find or create.
      type - - the NBT element we will create if not found.
      Returns:
      The value that was retrieved or just created.
    • put

      <T> NbtCompound put(@Nonnull NbtBase<T> entry)
      Set a entry based on its name.
      Type Parameters:
      T - Type
      Parameters:
      entry - - entry with a name and value.
      Returns:
      This compound, for chaining.
      Throws:
      IllegalArgumentException - If entry is NULL.
    • getString

      String getString(String key)
      Retrieve the string value of an entry identified by a given key.
      Parameters:
      key - - the key of the entry.
      Returns:
      The string value of the entry.
      Throws:
      IllegalArgumentException - If the key doesn't exist.
    • getStringOrDefault

      String getStringOrDefault(String key)
      Retrieve the string value of an existing entry, or from a new default entry if it doesn't exist.
      Parameters:
      key - - the key of the entry.
      Returns:
      The value that was retrieved or just created.
    • put

      NbtCompound put(String key, String value)
      Associate a NBT string value with the given key.
      Parameters:
      key - - the key and NBT name.
      value - - the value.
      Returns:
      This current compound, for chaining.
    • put

      NbtCompound put(String key, NbtBase<?> entry)
      Inserts an entry after cloning it and renaming it to "key".
      Parameters:
      key - - the name of the entry.
      entry - - the entry to insert.
      Returns:
      This current compound, for chaining.
    • getByte

      byte getByte(String key)
      Retrieve the byte value of an entry identified by a given key.
      Parameters:
      key - - the key of the entry.
      Returns:
      The byte value of the entry.
      Throws:
      IllegalArgumentException - If the key doesn't exist.
    • getByteOrDefault

      byte getByteOrDefault(String key)
      Retrieve the byte value of an existing entry, or from a new default entry if it doesn't exist.
      Parameters:
      key - - the key of the entry.
      Returns:
      The value that was retrieved or just created.
    • put

      NbtCompound put(String key, byte value)
      Associate a NBT byte value with the given key.
      Parameters:
      key - - the key and NBT name.
      value - - the value.
      Returns:
      This current compound, for chaining.
    • getShort

      Short getShort(String key)
      Retrieve the short value of an entry identified by a given key.
      Parameters:
      key - - the key of the entry.
      Returns:
      The short value of the entry.
      Throws:
      IllegalArgumentException - If the key doesn't exist.
    • getShortOrDefault

      short getShortOrDefault(String key)
      Retrieve the short value of an existing entry, or from a new default entry if it doesn't exist.
      Parameters:
      key - - the key of the entry.
      Returns:
      The value that was retrieved or just created.
    • put

      NbtCompound put(String key, short value)
      Associate a NBT short value with the given key.
      Parameters:
      key - - the key and NBT name.
      value - - the value.
      Returns:
      This current compound, for chaining.
    • getInteger

      int getInteger(String key)
      Retrieve the integer value of an entry identified by a given key.
      Parameters:
      key - - the key of the entry.
      Returns:
      The integer value of the entry.
      Throws:
      IllegalArgumentException - If the key doesn't exist.
    • getIntegerOrDefault

      int getIntegerOrDefault(String key)
      Retrieve the integer value of an existing entry, or from a new default entry if it doesn't exist.
      Parameters:
      key - - the key of the entry.
      Returns:
      The value that was retrieved or just created.
    • put

      NbtCompound put(String key, int value)
      Associate a NBT integer value with the given key.
      Parameters:
      key - - the key and NBT name.
      value - - the value.
      Returns:
      This current compound, for chaining.
    • getLong

      long getLong(String key)
      Retrieve the long value of an entry identified by a given key.
      Parameters:
      key - - the key of the entry.
      Returns:
      The long value of the entry.
      Throws:
      IllegalArgumentException - If the key doesn't exist.
    • getLongOrDefault

      long getLongOrDefault(String key)
      Retrieve the long value of an existing entry, or from a new default entry if it doesn't exist.
      Parameters:
      key - - the key of the entry.
      Returns:
      The value that was retrieved or just created.
    • put

      NbtCompound put(String key, long value)
      Associate a NBT long value with the given key.
      Parameters:
      key - - the key and NBT name.
      value - - the value.
      Returns:
      This current compound, for chaining.
    • getFloat

      float getFloat(String key)
      Retrieve the float value of an entry identified by a given key.
      Parameters:
      key - - the key of the entry.
      Returns:
      The float value of the entry.
      Throws:
      IllegalArgumentException - If the key doesn't exist.
    • getFloatOrDefault

      float getFloatOrDefault(String key)
      Retrieve the float value of an existing entry, or from a new default entry if it doesn't exist.
      Parameters:
      key - - the key of the entry.
      Returns:
      The value that was retrieved or just created.
    • put

      NbtCompound put(String key, float value)
      Associate a NBT float value with the given key.
      Parameters:
      key - - the key and NBT name.
      value - - the value.
      Returns:
      This current compound, for chaining.
    • getDouble

      double getDouble(String key)
      Retrieve the double value of an entry identified by a given key.
      Parameters:
      key - - the key of the entry.
      Returns:
      The double value of the entry.
      Throws:
      IllegalArgumentException - If the key doesn't exist.
    • getDoubleOrDefault

      double getDoubleOrDefault(String key)
      Retrieve the double value of an existing entry, or from a new default entry if it doesn't exist.
      Parameters:
      key - - the key of the entry.
      Returns:
      The value that was retrieved or just created.
    • put

      NbtCompound put(String key, double value)
      Associate a NBT double value with the given key.
      Parameters:
      key - - the key and NBT name.
      value - - the value.
      Returns:
      This current compound, for chaining.
    • getByteArray

      byte[] getByteArray(String key)
      Retrieve the byte array value of an entry identified by a given key.
      Parameters:
      key - - the key of the entry.
      Returns:
      The byte array value of the entry.
      Throws:
      IllegalArgumentException - If the key doesn't exist.
    • put

      NbtCompound put(String key, byte[] value)
      Associate a NBT byte array value with the given key.
      Parameters:
      key - - the key and NBT name.
      value - - the value.
      Returns:
      This current compound, for chaining.
    • getIntegerArray

      int[] getIntegerArray(String key)
      Retrieve the integer array value of an entry identified by a given key.
      Parameters:
      key - - the key of the entry.
      Returns:
      The integer array value of the entry.
      Throws:
      IllegalArgumentException - If the key doesn't exist.
    • put

      NbtCompound put(String key, int[] value)
      Associate a NBT integer array value with the given key.
      Parameters:
      key - - the key and NBT name.
      value - - the value.
      Returns:
      This current compound, for chaining.
    • putObject

      NbtCompound putObject(String key, Object value)
      Associates a given Java primitive value, list, map or NbtBase with a certain key.

      If the value is NULL, the corresponding key is removed. Any Map or List will be converted to a corresponding NbtCompound or NbtList.

      Parameters:
      key - - the name of the new entry,
      value - - the value of the new entry, or NULL to remove the current value.
      Returns:
      This current compound, for chaining.
    • getObject

      Object getObject(String key)
      Retrieve the primitive object, NbtList or NbtCompound associated with the given key.
      Parameters:
      key - - the key of the object to find.
      Returns:
      The object with this key, or NULL if we couldn't find anything.
    • getCompound

      NbtCompound getCompound(String key)
      Retrieve the compound (map) value of an entry identified by a given key.
      Parameters:
      key - - the key of the entry.
      Returns:
      The compound value of the entry.
      Throws:
      IllegalArgumentException - If the key doesn't exist.
    • getCompoundOrDefault

      NbtCompound getCompoundOrDefault(String key)
      Retrieve a compound (map) value by its key, or create a new compound if it doesn't exist.
      Parameters:
      key - - the key of the entry to find or create.
      Returns:
      The compound value that was retrieved or just created.
    • put

      NbtCompound put(NbtCompound compound)
      Associate a NBT compound with its name as key.
      Parameters:
      compound - - the compound value.
      Returns:
      This current compound, for chaining.
    • getList

      <T> NbtList<T> getList(String key)
      Retrieve the NBT list value of an entry identified by a given key.
      Type Parameters:
      T - Type
      Parameters:
      key - - the key of the entry.
      Returns:
      The NBT list value of the entry.
      Throws:
      IllegalArgumentException - If the key doesn't exist.
    • getListOrDefault

      <T> NbtList<T> getListOrDefault(String key)
      Retrieve a NBT list value by its key, or create a new list if it doesn't exist.
      Type Parameters:
      T - Type
      Parameters:
      key - - the key of the entry to find or create.
      Returns:
      The compound value that was retrieved or just created.
    • put

      <T> NbtCompound put(NbtList<T> list)
      Associate a NBT list with the given key.
      Type Parameters:
      T - Type
      Parameters:
      list - - the list value.
      Returns:
      This current compound, for chaining.
    • put

      <T> NbtCompound put(String key, Collection<? extends NbtBase<T>> list)
      Associate a new NBT list with the given key.
      Type Parameters:
      T - Type
      Parameters:
      key - - the key and name of the new NBT list.
      list - - the list of NBT elements.
      Returns:
      This current compound, for chaining.
    • remove

      <T> NbtBase<?> remove(String key)
      Remove the NBT element that is associated with the given key.
      Type Parameters:
      T - Type
      Parameters:
      key - - the key of the element to remove.
      Returns:
      The removed element, or NULL if no such element was found.
    • iterator

      Iterator<NbtBase<?>> iterator()
      Retrieve an iterator view of the NBT tags stored in this compound.
      Specified by:
      iterator in interface Iterable<NbtBase<?>>
      Returns:
      The tags stored in this compound.