Class HeterogeneousNbtList
java.lang.Object
org.geysermc.adventure.text.serializer.nbt.HeterogeneousNbtList
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(com.viaversion.nbt.tag.Tag value) Adds a tag to the list.com.viaversion.nbt.tag.ListTag<?> build()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> 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.
-
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
-
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
-