Class Tag_List

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

public class Tag_List extends Collection_Tag implements IListTag
Represents an NBT list tag - a homogeneous collection containing multiple tags of the same type, accessed by index rather than name.

List tags enforce type consistency, ensuring all contained elements match the declared list type. They provide indexed access and fluent builder methods for type-safe element addition.

Extends Collection_Tag with list-specific type validation and implements IListTag for standardized access.

Author:
Paul Ferlitz
  • Constructor Details

    • Tag_List

      public Tag_List(int listTypeID)
      Creates an empty list with the specified element type.
      Parameters:
      listTypeID - the NBT type ID for all elements in this list
    • Tag_List

      public Tag_List(String name, int listTypeID)
      Creates an empty named list with the specified element type.
      Parameters:
      name - the tag name
      listTypeID - the NBT type ID for all elements in this list
    • Tag_List

      public Tag_List(String name, int listTypeID, ArrayList<Tag<?>> data)
      Creates a list pre-populated with elements of the specified type.
      Parameters:
      name - the tag name
      listTypeID - the NBT type ID for all elements in this list
      data - the initial collection of elements
  • Method Details

    • getListTypeID

      public int getListTypeID()
      Returns the NBT type identifier for elements in this list.

      All elements must match this type to maintain list homogeneity.

      Specified by:
      getListTypeID in interface IListTag
      Returns:
      the NBT type ID of list elements
    • addString

      public IListTag addString(String name, String value)
      Adds a string element to this list with fluent chaining.

      Only valid for lists declared as string type.

      Specified by:
      addString in interface IListTag
      Parameters:
      name - the element name
      value - the string value
      Returns:
      this list tag for fluent operations
      Throws:
      IllegalArgumentException - if list type is not Tag_String
      See Also:
    • addInt

      public IListTag addInt(String name, int value)
      Adds an integer element to this list with fluent chaining.

      Only valid for lists declared as integer type.

      Specified by:
      addInt in interface IListTag
      Parameters:
      name - the element name
      value - the integer value
      Returns:
      this list tag for fluent operations
      Throws:
      IllegalArgumentException - if list type is not Tag_Int
      See Also:
    • addDouble

      public IListTag addDouble(String name, double value)
      Adds a double-precision element to this list with fluent chaining.

      Only valid for lists declared as double type.

      Specified by:
      addDouble in interface IListTag
      Parameters:
      name - the element name
      value - the double value
      Returns:
      this list tag for fluent operations
      Throws:
      IllegalArgumentException - if list type is not Tag_Double
      See Also:
    • addCompound

      public IListTag addCompound(String name)
      Adds a compound element to this list with fluent chaining.

      Only valid for lists declared as compound type.

      Specified by:
      addCompound in interface IListTag
      Parameters:
      name - the element name
      Returns:
      this list tag for fluent operations
      Throws:
      IllegalArgumentException - if list type is not Tag_Compound
      See Also:
    • toString

      public String toString()
      Generates a hierarchical string representation showing list metadata and elements.

      Output includes tag type, name, element type, size, and formatted child elements.

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