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:
    • 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
    • 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
    • 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