Class Tag_Compound

All Implemented Interfaces:
ICompoundTag, ITag<ArrayList<Tag<?>>>

public class Tag_Compound extends Collection_Tag implements ICompoundTag
Represents an NBT compound tag - a named collection of heterogeneous tags that forms the backbone of NBT data structures.

Compound tags store multiple child tags of different types, accessed by name. They provide both direct tag manipulation and fluent builder methods for common data types.

Extends Collection_Tag with compound-specific operations and implements ICompoundTag for standardized access.

Author:
Paul Ferlitz
  • Constructor Details

    • Tag_Compound

      public Tag_Compound()
      Creates an empty compound tag with default name.
    • Tag_Compound

      public Tag_Compound(String name)
      Creates an empty compound tag with the specified name.
      Parameters:
      name - the tag name
    • Tag_Compound

      public Tag_Compound(String name, ArrayList<Tag<?>> data)
      Creates a compound tag pre-populated with child tags.
      Parameters:
      name - the tag name
      data - the initial collection of child tags
  • Method Details

    • addString

      public ICompoundTag addString(String name, String value)
      Adds a string tag and returns this compound for method chaining.
      Specified by:
      addString in interface ICompoundTag
      Parameters:
      name - the tag name
      value - the string value
      Returns:
      this compound tag for fluent operations
      See Also:
    • addInt

      public ICompoundTag addInt(String name, int value)
      Adds an integer tag and returns this compound for method chaining.
      Specified by:
      addInt in interface ICompoundTag
      Parameters:
      name - the tag name
      value - the integer value
      Returns:
      this compound tag for fluent operations
      See Also:
    • addDouble

      public ICompoundTag addDouble(String name, double value)
      Adds a double-precision tag and returns this compound for method chaining.
      Specified by:
      addDouble in interface ICompoundTag
      Parameters:
      name - the tag name
      value - the double value
      Returns:
      this compound tag for fluent operations
      See Also:
    • addFloat

      public ICompoundTag addFloat(String name, float value)
      Adds a single-precision float tag and returns this compound for method chaining.
      Specified by:
      addFloat in interface ICompoundTag
      Parameters:
      name - the tag name
      value - the float value
      Returns:
      this compound tag for fluent operations
      See Also:
    • addByte

      public ICompoundTag addByte(String name, byte value)
      Adds a byte tag and returns this compound for method chaining.
      Specified by:
      addByte in interface ICompoundTag
      Parameters:
      name - the tag name
      value - the byte value
      Returns:
      this compound tag for fluent operations
      See Also:
    • addShort

      public ICompoundTag addShort(String name, short value)
      Adds a short integer tag and returns this compound for method chaining.
      Specified by:
      addShort in interface ICompoundTag
      Parameters:
      name - the tag name
      value - the short value
      Returns:
      this compound tag for fluent operations
      See Also:
    • addLong

      public ICompoundTag addLong(String name, long value)
      Adds a long integer tag and returns this compound for method chaining.
      Specified by:
      addLong in interface ICompoundTag
      Parameters:
      name - the tag name
      value - the long value
      Returns:
      this compound tag for fluent operations
      See Also:
    • addByteArray

      public ICompoundTag addByteArray(String name, byte[] value)
      Adds a byte array tag and returns this compound for method chaining.
      Specified by:
      addByteArray in interface ICompoundTag
      Parameters:
      name - the tag name
      value - the byte array value
      Returns:
      this compound tag for fluent operations
      See Also:
    • addIntArray

      public ICompoundTag addIntArray(String name, int[] value)
      Adds an integer array tag and returns this compound for method chaining.
      Specified by:
      addIntArray in interface ICompoundTag
      Parameters:
      name - the tag name
      value - the integer array value
      Returns:
      this compound tag for fluent operations
      See Also:
    • addLongArray

      public ICompoundTag addLongArray(String name, long[] value)
      Adds a long array tag and returns this compound for method chaining.
      Specified by:
      addLongArray in interface ICompoundTag
      Parameters:
      name - the tag name
      value - the long array value
      Returns:
      this compound tag for fluent operations
      See Also:
    • hasTag

      public boolean hasTag(String tagName)
      Description copied from interface: ICompoundTag
      Checks whether this compound contains a tag with the specified name.
      Specified by:
      hasTag in interface ICompoundTag
      Parameters:
      tagName - The name to search for
      Returns:
      true if a tag with this name exists, false otherwise
    • getTag

      public ITag<?> getTag(String name)
      Description copied from interface: ICompoundTag
      Retrieves a child tag by name without requiring casts.
      Specified by:
      getTag in interface ICompoundTag
      Parameters:
      name - The name of the tag to find
      Returns:
      The tag if found, null otherwise
    • getString

      public String getString(String name)
      Description copied from interface: ICompoundTag
      Retrieves a string value directly from a child tag.
      Specified by:
      getString in interface ICompoundTag
      Parameters:
      name - The name of the string tag
      Returns:
      The string value, or null if tag doesn't exist or isn't a string
    • getInt

      public int getInt(String name)
      Description copied from interface: ICompoundTag
      Retrieves an integer value directly from a child tag.
      Specified by:
      getInt in interface ICompoundTag
      Parameters:
      name - The name of the integer tag
      Returns:
      The integer value, or 0 if tag doesn't exist or isn't an integer
    • getDouble

      public double getDouble(String name)
      Description copied from interface: ICompoundTag
      Retrieves a double value directly from a child tag.
      Specified by:
      getDouble in interface ICompoundTag
      Parameters:
      name - The name of the double tag
      Returns:
      The double value, or 0.0 if tag doesn't exist or isn't a double
    • getByte

      public byte getByte(String name)
      Description copied from interface: ICompoundTag
      Retrieves a byte value directly from a child tag.
      Specified by:
      getByte in interface ICompoundTag
      Parameters:
      name - The name of the byte tag
      Returns:
      The byte value, or 0 if tag doesn't exist or isn't a byte
    • getFloat

      public float getFloat(String name)
      Description copied from interface: ICompoundTag
      Retrieves a float value directly from a child tag.
      Specified by:
      getFloat in interface ICompoundTag
      Parameters:
      name - The name of the float tag
      Returns:
      The float value, or 0.0f if tag doesn't exist or isn't a float
    • getShort

      public short getShort(String name)
      Description copied from interface: ICompoundTag
      Retrieves a short value directly from a child tag.
      Specified by:
      getShort in interface ICompoundTag
      Parameters:
      name - The name of the short tag
      Returns:
      The short value, or 0 if tag doesn't exist or isn't a short
    • getLong

      public long getLong(String name)
      Description copied from interface: ICompoundTag
      Retrieves a long value directly from a child tag.
      Specified by:
      getLong in interface ICompoundTag
      Parameters:
      name - The name of the long tag
      Returns:
      The long value, or 0L if tag doesn't exist or isn't a long
    • getCompound

      public ICompoundTag getCompound(String name)
      Description copied from interface: ICompoundTag
      Retrieves a compound tag by name without casting.
      Specified by:
      getCompound in interface ICompoundTag
      Parameters:
      name - The name of the compound tag
      Returns:
      The ICompoundTag if found, null otherwise
    • getList

      public IListTag getList(String name)
      Description copied from interface: ICompoundTag
      Retrieves a list tag by name without casting.
      Specified by:
      getList in interface ICompoundTag
      Parameters:
      name - The name of the list tag
      Returns:
      The IListTag if found, null otherwise
    • getByteArray

      public byte[] getByteArray(String name)
      Description copied from interface: ICompoundTag
      Retrieves a byte array value directly from a child tag.
      Specified by:
      getByteArray in interface ICompoundTag
      Parameters:
      name - The name of the byte array tag
      Returns:
      The byte array value, or null if tag doesn't exist or isn't a byte array
    • getIntArray

      public int[] getIntArray(String name)
      Description copied from interface: ICompoundTag
      Retrieves an integer array value directly from a child tag.
      Specified by:
      getIntArray in interface ICompoundTag
      Parameters:
      name - The name of the integer array tag
      Returns:
      The integer array value, or null if tag doesn't exist or isn't an integer array
    • getLongArray

      public long[] getLongArray(String name)
      Description copied from interface: ICompoundTag
      Retrieves a long array value directly from a child tag.
      Specified by:
      getLongArray in interface ICompoundTag
      Parameters:
      name - The name of the long array tag
      Returns:
      The long array value, or null if tag doesn't exist or isn't a long array
    • setString

      public ICompoundTag setString(String name, String value)
      Description copied from interface: ICompoundTag
      Updates or creates a string tag with the given name and value.
      Specified by:
      setString in interface ICompoundTag
      Parameters:
      name - The tag name
      value - The String value to store
      Returns:
      This compound for fluent method chaining
    • setInt

      public ICompoundTag setInt(String name, int value)
      Description copied from interface: ICompoundTag
      Updates or creates an integer tag with the given name and value.
      Specified by:
      setInt in interface ICompoundTag
      Parameters:
      name - The tag name
      value - The Integer value to store
      Returns:
      This compound for fluent method chaining
    • setDouble

      public ICompoundTag setDouble(String name, double value)
      Description copied from interface: ICompoundTag
      Updates or creates a double-precision floating point tag.
      Specified by:
      setDouble in interface ICompoundTag
      Parameters:
      name - The tag name
      value - The Double value to store
      Returns:
      This compound for fluent method chaining
    • setFloat

      public ICompoundTag setFloat(String name, float value)
      Description copied from interface: ICompoundTag
      Updates or creates a single-precision floating point tag.
      Specified by:
      setFloat in interface ICompoundTag
      Parameters:
      name - The tag name
      value - The Float value to store
      Returns:
      This compound for fluent method chaining
    • setByte

      public ICompoundTag setByte(String name, byte value)
      Description copied from interface: ICompoundTag
      Updates or creates a byte tag with the given name and value.
      Specified by:
      setByte in interface ICompoundTag
      Parameters:
      name - The tag name
      value - The Byte value to store
      Returns:
      This compound for fluent method chaining
    • setShort

      public ICompoundTag setShort(String name, short value)
      Description copied from interface: ICompoundTag
      Updates or creates a short integer tag.
      Specified by:
      setShort in interface ICompoundTag
      Parameters:
      name - The tag name
      value - The Short value to store
      Returns:
      This compound for fluent method chaining
    • setLong

      public ICompoundTag setLong(String name, long value)
      Description copied from interface: ICompoundTag
      Updates or creates a long integer tag.
      Specified by:
      setLong in interface ICompoundTag
      Parameters:
      name - The tag name
      value - The Long value to store
      Returns:
      This compound for fluent method chaining
    • setByteArray

      public ICompoundTag setByteArray(String name, byte[] value)
      Description copied from interface: ICompoundTag
      Updates or creates a byte array tag.
      Specified by:
      setByteArray in interface ICompoundTag
      Parameters:
      name - The tag name
      value - The byte array value to store
      Returns:
      This compound for fluent method chaining
    • setIntArray

      public ICompoundTag setIntArray(String name, int[] value)
      Description copied from interface: ICompoundTag
      Updates or creates an integer array tag.
      Specified by:
      setIntArray in interface ICompoundTag
      Parameters:
      name - The tag name
      value - The integer array value to store
      Returns:
      This compound for fluent method chaining
    • setLongArray

      public ICompoundTag setLongArray(String name, long[] value)
      Description copied from interface: ICompoundTag
      Updates or creates a long array tag.
      Specified by:
      setLongArray in interface ICompoundTag
      Parameters:
      name - The tag name
      value - The long array value to store
      Returns:
      This compound for fluent method chaining
    • setTag

      public ICompoundTag setTag(ITag<?> tag)
      Description copied from interface: ICompoundTag
      Updates or replaces an existing tag with a new one.
      Specified by:
      setTag in interface ICompoundTag
      Parameters:
      tag - The tag to set (replaces any existing tag with the same name)
      Returns:
      This compound for fluent method chaining
    • removeTag

      public ICompoundTag removeTag(String name)
      Description copied from interface: ICompoundTag
      Removes a tag by name and returns this compound for chaining.
      Specified by:
      removeTag in interface ICompoundTag
      Parameters:
      name - The name of the tag to remove
      Returns:
      This compound for fluent method chaining
    • removeTags

      public ICompoundTag removeTags(String... names)
      Description copied from interface: ICompoundTag
      Removes multiple tags by name and returns this compound for chaining.
      Specified by:
      removeTags in interface ICompoundTag
      Parameters:
      names - The names of the tags to remove
      Returns:
      This compound for fluent method chaining
    • clear

      public ICompoundTag clear()
      Description copied from interface: ICompoundTag
      Removes all tags from this compound.
      Specified by:
      clear in interface ICompoundTag
      Returns:
      This compound for fluent method chaining
    • size

      public int size()
      Description copied from interface: ICompoundTag
      Gets the number of child tags in this compound.
      Specified by:
      size in interface ICompoundTag
      Returns:
      The number of child tags
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: ICompoundTag
      Checks if this compound is empty (has no child tags).
      Specified by:
      isEmpty in interface ICompoundTag
      Returns:
      true if empty, false otherwise
    • toString

      public String toString()
      Generates a hierarchical string representation showing all nested tags.

      Output includes tag type, name, size, and recursively formatted child tags.

      Specified by:
      toString in interface ITag<ArrayList<Tag<?>>>
      Overrides:
      toString in class Tag<ArrayList<Tag<?>>>
      Returns:
      formatted multi-line string representation