Class HeterogeneousNbtList

java.lang.Object
org.geysermc.adventure.text.serializer.nbt.HeterogeneousNbtList

public final class HeterogeneousNbtList extends Object
Constructs and parses Java Edition's heterogeneous NBT lists.

NBT lists must have a single element type. Java Edition stores mixed lists as compound lists, wrapping each non-compound value in a compound with a single empty-string key.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(com.viaversion.nbt.tag.Tag value)
    Adds a tag to the list.
    com.viaversion.nbt.tag.ListTag<?>
    Encodes the accumulated values as a homogeneous NBT list.
    static <T extends com.viaversion.nbt.tag.Tag>
    Collector<T, ?, com.viaversion.nbt.tag.ListTag<?>>
    Collects a stream of tags into an encoded NBT list.
    static List<? extends com.viaversion.nbt.tag.Tag>
    getList(com.viaversion.nbt.tag.CompoundTag map, String key)
    Reads and unwraps a list from a compound, returning an empty list if absent.
    static com.viaversion.nbt.tag.ListTag<?>
    of(com.viaversion.nbt.tag.Tag... values)
    Constructs a homogeneous NBT list, wrapping mixed values when necessary.
    static List<? extends com.viaversion.nbt.tag.Tag>
    tryUnwrap(com.viaversion.nbt.tag.ListTag<?> list)
    Unwraps single-empty-key compounds in a compound list.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HeterogeneousNbtList

      public HeterogeneousNbtList()
  • Method Details

    • of

      public static com.viaversion.nbt.tag.ListTag<?> of(com.viaversion.nbt.tag.Tag... values)
      Constructs a homogeneous NBT list, wrapping mixed values when necessary.
      Parameters:
      values - the tags to include
      Returns:
      the encoded list
    • getList

      public static List<? extends com.viaversion.nbt.tag.Tag> getList(com.viaversion.nbt.tag.CompoundTag map, String key)
      Reads and unwraps a list from a compound, returning an empty list if absent.
      Parameters:
      map - the compound
      key - the list key
      Returns:
      the unwrapped tags
    • tryUnwrap

      public static List<? extends com.viaversion.nbt.tag.Tag> tryUnwrap(com.viaversion.nbt.tag.ListTag<?> list)
      Unwraps single-empty-key compounds in a compound list.
      Parameters:
      list - the encoded list
      Returns:
      the unwrapped tags, or the original values for a non-compound list
    • add

      public void add(com.viaversion.nbt.tag.Tag value)
      Adds a tag to the list.
      Parameters:
      value - the tag
    • build

      public com.viaversion.nbt.tag.ListTag<?> build()
      Encodes the accumulated values as a homogeneous NBT list.
      Returns:
      the encoded list
    • collector

      public static <T extends com.viaversion.nbt.tag.Tag> Collector<T, ?, com.viaversion.nbt.tag.ListTag<?>> collector()
      Collects a stream of tags into an encoded NBT list.
      Type Parameters:
      T - the tag type
      Returns:
      the collector