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

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

      Only valid for lists declared as float type.

      Specified by:
      addFloat in interface IListTag
      Parameters:
      name - the element name
      value - the float value
      Returns:
      this list tag for fluent operations
      Throws:
      IllegalArgumentException - if list type is not Tag_Float
      See Also:
    • addByte

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

      Only valid for lists declared as byte type.

      Specified by:
      addByte in interface IListTag
      Parameters:
      name - the element name
      value - the byte value
      Returns:
      this list tag for fluent operations
      Throws:
      IllegalArgumentException - if list type is not Tag_Byte
      See Also:
    • addShort

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

      Only valid for lists declared as short type.

      Specified by:
      addShort in interface IListTag
      Parameters:
      name - the element name
      value - the short value
      Returns:
      this list tag for fluent operations
      Throws:
      IllegalArgumentException - if list type is not Tag_Short
      See Also:
    • addLong

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

      Only valid for lists declared as long type.

      Specified by:
      addLong in interface IListTag
      Parameters:
      name - the element name
      value - the long value
      Returns:
      this list tag for fluent operations
      Throws:
      IllegalArgumentException - if list type is not Tag_Long
      See Also:
    • setString

      public IListTag setString(int index, String name, String value)
      Description copied from interface: IListTag
      Updates an element at the specified index with a new string value. Only works if this list stores string tags.
      Specified by:
      setString in interface IListTag
      Parameters:
      index - The index to update
      name - The new element name
      value - The new String value
      Returns:
      This list for fluent method chaining
    • setInt

      public IListTag setInt(int index, String name, int value)
      Description copied from interface: IListTag
      Updates an element at the specified index with a new integer value. Only works if this list stores integer tags.
      Specified by:
      setInt in interface IListTag
      Parameters:
      index - The index to update
      name - The new element name
      value - The new Integer value
      Returns:
      This list for fluent method chaining
    • setDouble

      public IListTag setDouble(int index, String name, double value)
      Description copied from interface: IListTag
      Updates an element at the specified index with a new double value. Only works if this list stores double tags.
      Specified by:
      setDouble in interface IListTag
      Parameters:
      index - The index to update
      name - The new element name
      value - The new Double value
      Returns:
      This list for fluent method chaining
    • setCompound

      public IListTag setCompound(int index, String name)
      Description copied from interface: IListTag
      Updates an element at the specified index with a new compound. Only works if this list stores compound tags.
      Specified by:
      setCompound in interface IListTag
      Parameters:
      index - The index to update
      name - The new element name
      Returns:
      This list for fluent method chaining
    • setFloat

      public IListTag setFloat(int index, String name, float value)
      Description copied from interface: IListTag
      Updates an element at the specified index with a new float value. Only works if this list stores float tags.
      Specified by:
      setFloat in interface IListTag
      Parameters:
      index - The index to update
      name - The new element name
      value - The new Float value
      Returns:
      This list for fluent method chaining
    • setByte

      public IListTag setByte(int index, String name, byte value)
      Description copied from interface: IListTag
      Updates an element at the specified index with a new byte value. Only works if this list stores byte tags.
      Specified by:
      setByte in interface IListTag
      Parameters:
      index - The index to update
      name - The new element name
      value - The new Byte value
      Returns:
      This list for fluent method chaining
    • setShort

      public IListTag setShort(int index, String name, short value)
      Description copied from interface: IListTag
      Updates an element at the specified index with a new short value. Only works if this list stores short tags.
      Specified by:
      setShort in interface IListTag
      Parameters:
      index - The index to update
      name - The new element name
      value - The new Short value
      Returns:
      This list for fluent method chaining
    • setLong

      public IListTag setLong(int index, String name, long value)
      Description copied from interface: IListTag
      Updates an element at the specified index with a new long value. Only works if this list stores long tags.
      Specified by:
      setLong in interface IListTag
      Parameters:
      index - The index to update
      name - The new element name
      value - The new Long value
      Returns:
      This list for fluent method chaining
    • setTag

      public IListTag setTag(int index, ITag<?> tag)
      Description copied from interface: IListTag
      Replaces an element at the specified index with a new tag.
      Specified by:
      setTag in interface IListTag
      Parameters:
      index - The index to update
      tag - The new tag to set
      Returns:
      This list for fluent method chaining
    • removeAt

      public IListTag removeAt(int index)
      Description copied from interface: IListTag
      Removes an element at the specified index.
      Specified by:
      removeAt in interface IListTag
      Parameters:
      index - The index to remove
      Returns:
      This list for fluent method chaining
    • remove

      public IListTag remove(ITag<?> tag)
      Description copied from interface: IListTag
      Removes the first element that matches the given tag.
      Specified by:
      remove in interface IListTag
      Parameters:
      tag - The tag to remove
      Returns:
      This list for fluent method chaining
    • clear

      public IListTag clear()
      Description copied from interface: IListTag
      Removes all elements from this list.
      Specified by:
      clear in interface IListTag
      Returns:
      This list for fluent method chaining
    • get

      public ITag<?> get(int index)
      Description copied from interface: IListTag
      Gets the element at the specified index.
      Specified by:
      get in interface IListTag
      Parameters:
      index - The index to retrieve
      Returns:
      The element at the specified index
    • size

      public int size()
      Description copied from interface: IListTag
      Gets the number of elements in this list.
      Specified by:
      size in interface IListTag
      Returns:
      The number of elements
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: IListTag
      Checks if this list is empty (has no elements).
      Specified by:
      isEmpty in interface IListTag
      Returns:
      true if empty, false otherwise
    • 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