Class NbtList

All Implemented Interfaces:
Iterable<NbtElement>, Collection<NbtElement>, List<NbtElement>, SequencedCollection<NbtElement>, AbstractNbtList, NbtElement

public final class NbtList extends AbstractList<NbtElement> implements AbstractNbtList
Represents a mutable NBT list. Its type is 0x9.

To get values from this list, use methods with type names, such as getInt(int). Where applicable, these methods return Java types (e.g. int, long[]) instead of NbtElement subclasses. If type mismatch occurs or the index is out of bounds, it returns the default value for that type instead of throwing or returning null.

Unlike NbtCompound, there is no Java type-based adder, and numeric value getters will not try to cast the values.

Mappings:
Namespace Name
named net/minecraft/nbt/NbtList
intermediary net/minecraft/class_2499
official ug
  • Field Details Link icon

    • HOMOGENIZED_ENTRY_KEY Link icon

      private static final String HOMOGENIZED_ENTRY_KEY
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named HOMOGENIZED_ENTRY_KEY Lnet/minecraft/nbt/NbtList;HOMOGENIZED_ENTRY_KEY:Ljava/lang/String;
      intermediary field_57977 Lnet/minecraft/class_2499;field_57977:Ljava/lang/String;
      official b Lug;b:Ljava/lang/String;
    • SIZE Link icon

      private static final int SIZE
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named SIZE Lnet/minecraft/nbt/NbtList;SIZE:I
      intermediary field_41725 Lnet/minecraft/class_2499;field_41725:I
      official c Lug;c:I
    • TYPE Link icon

      public static final NbtType<NbtList> TYPE
      Mappings:
      Namespace Name Mixin selector
      named TYPE Lnet/minecraft/nbt/NbtList;TYPE:Lnet/minecraft/nbt/NbtType;
      intermediary field_21039 Lnet/minecraft/class_2499;field_21039:Lnet/minecraft/class_4614;
      official a Lug;a:Lvc;
    • value Link icon

      private final List<NbtElement> value
      Mappings:
      Namespace Name Mixin selector
      named value Lnet/minecraft/nbt/NbtList;value:Ljava/util/List;
      intermediary field_11550 Lnet/minecraft/class_2499;field_11550:Ljava/util/List;
      official v Lug;v:Ljava/util/List;
  • Constructor Details Link icon

    • NbtList Link icon

      public NbtList()
    • NbtList Link icon

      NbtList(List<NbtElement> value)
      Mappings:
      Namespace Name Mixin selector
      named <init> Lnet/minecraft/nbt/NbtList;<init>(Ljava/util/List;)V
      intermediary <init> Lnet/minecraft/class_2499;<init>(Ljava/util/List;)V
      official <init> Lug;<init>(Ljava/util/List;)V
  • Method Details Link icon

    • unwrap Link icon

      private static NbtElement unwrap(NbtCompound nbt)
      Mappings:
      Namespace Name Mixin selector
      named unwrap Lnet/minecraft/nbt/NbtList;unwrap(Lnet/minecraft/nbt/NbtCompound;)Lnet/minecraft/nbt/NbtElement;
      intermediary method_68579 Lnet/minecraft/class_2499;method_68579(Lnet/minecraft/class_2487;)Lnet/minecraft/class_2520;
      official a Lug;a(Lua;)Lva;
    • isConvertedEntry Link icon

      private static boolean isConvertedEntry(NbtCompound nbt)
      Mappings:
      Namespace Name Mixin selector
      named isConvertedEntry Lnet/minecraft/nbt/NbtList;isConvertedEntry(Lnet/minecraft/nbt/NbtCompound;)Z
      intermediary method_68583 Lnet/minecraft/class_2499;method_68583(Lnet/minecraft/class_2487;)Z
      official b Lug;b(Lua;)Z
    • wrapIfNeeded Link icon

      private static NbtElement wrapIfNeeded(byte type, NbtElement value)
      Mappings:
      Namespace Name Mixin selector
      named wrapIfNeeded Lnet/minecraft/nbt/NbtList;wrapIfNeeded(BLnet/minecraft/nbt/NbtElement;)Lnet/minecraft/nbt/NbtElement;
      intermediary method_68573 Lnet/minecraft/class_2499;method_68573(BLnet/minecraft/class_2520;)Lnet/minecraft/class_2520;
      official a Lug;a(BLva;)Lva;
    • convertToCompound Link icon

      private static NbtCompound convertToCompound(NbtElement nbt)
      Mappings:
      Namespace Name Mixin selector
      named convertToCompound Lnet/minecraft/nbt/NbtList;convertToCompound(Lnet/minecraft/nbt/NbtElement;)Lnet/minecraft/nbt/NbtCompound;
      intermediary method_68584 Lnet/minecraft/class_2499;method_68584(Lnet/minecraft/class_2520;)Lnet/minecraft/class_2487;
      official b Lug;b(Lva;)Lua;
    • write Link icon

      public void write(DataOutput output) throws IOException
      Writes the NBT element to output.
      Specified by:
      write in interface NbtElement
      Throws:
      IOException
      API Note:
      This is a low-level method for serializing NBT elements; consider using NbtIo, NbtOps, or PacketByteBuf.writeNbt(net.minecraft.nbt.NbtElement) instead.
      Mappings:
      Namespace Name Mixin selector
      named write Lnet/minecraft/nbt/NbtElement;write(Ljava/io/DataOutput;)V
      intermediary method_10713 Lnet/minecraft/class_2520;method_10713(Ljava/io/DataOutput;)V
      official a Lva;a(Ljava/io/DataOutput;)V
    • getValueType Link icon

      byte getValueType()
      Mappings:
      Namespace Name Mixin selector
      named getValueType Lnet/minecraft/nbt/NbtList;getValueType()B
      intermediary method_68587 Lnet/minecraft/class_2499;method_68587()B
      official e Lug;e()B
    • unwrapAndAdd Link icon

      public void unwrapAndAdd(NbtElement nbt)
      Mappings:
      Namespace Name Mixin selector
      named unwrapAndAdd Lnet/minecraft/nbt/NbtList;unwrapAndAdd(Lnet/minecraft/nbt/NbtElement;)V
      intermediary method_68580 Lnet/minecraft/class_2499;method_68580(Lnet/minecraft/class_2520;)V
      official a Lug;a(Lva;)V
    • getSizeInBytes Link icon

      public int getSizeInBytes()
      Specified by:
      getSizeInBytes in interface NbtElement
      Mappings:
      Namespace Name Mixin selector
      named getSizeInBytes Lnet/minecraft/nbt/NbtElement;getSizeInBytes()I
      intermediary method_47988 Lnet/minecraft/class_2520;method_47988()I
      official a Lva;a()I
    • getType Link icon

      public byte getType()
      Returns the type of this NBT element.
      Specified by:
      getType in interface NbtElement
      Returns:
      the type of this NBT element
      Mappings:
      Namespace Name Mixin selector
      named getType Lnet/minecraft/nbt/NbtElement;getType()B
      intermediary method_10711 Lnet/minecraft/class_2520;method_10711()B
      official b Lva;b()B
    • getNbtType Link icon

      public NbtType<NbtList> getNbtType()
      Returns the NBT type definition of this NBT element.
      Specified by:
      getNbtType in interface NbtElement
      Returns:
      the NBT type definition of this NBT element
      Mappings:
      Namespace Name Mixin selector
      named getNbtType Lnet/minecraft/nbt/NbtElement;getNbtType()Lnet/minecraft/nbt/NbtType;
      intermediary method_23258 Lnet/minecraft/class_2520;method_23258()Lnet/minecraft/class_4614;
      official c Lva;c()Lvc;
    • toString Link icon

      public String toString()
      Specified by:
      toString in interface NbtElement
      Overrides:
      toString in class AbstractCollection<NbtElement>
    • remove Link icon

      public NbtElement remove(int int2)
      Specified by:
      remove in interface AbstractNbtList
      Specified by:
      remove in interface List<NbtElement>
      Overrides:
      remove in class AbstractList<NbtElement>
      Mappings:
      Namespace Name Mixin selector
      named remove Lnet/minecraft/nbt/NbtList;remove(I)Lnet/minecraft/nbt/NbtElement;
      intermediary method_10536 Lnet/minecraft/class_2499;method_10536(I)Lnet/minecraft/class_2520;
      official method_10536 Lug;method_10536(I)Lva;
    • isEmpty Link icon

      public boolean isEmpty()
      Specified by:
      isEmpty in interface AbstractNbtList
      Specified by:
      isEmpty in interface Collection<NbtElement>
      Specified by:
      isEmpty in interface List<NbtElement>
      Overrides:
      isEmpty in class AbstractCollection<NbtElement>
    • getCompound Link icon

      public Optional<NbtCompound> getCompound(int index)
      Returns the compound at index, or an empty compound if the index is out of bounds or if this is not a list of compounds.
      Returns:
      the compound at index, or an empty compound if the index is out of bounds or if this is not a list of compounds
      Mappings:
      Namespace Name Mixin selector
      named getCompound Lnet/minecraft/nbt/NbtList;getCompound(I)Ljava/util/Optional;
      intermediary method_10602 Lnet/minecraft/class_2499;method_10602(I)Ljava/util/Optional;
      official a Lug;a(I)Ljava/util/Optional;
    • getCompoundOrEmpty Link icon

      public NbtCompound getCompoundOrEmpty(int index)
      Mappings:
      Namespace Name Mixin selector
      named getCompoundOrEmpty Lnet/minecraft/nbt/NbtList;getCompoundOrEmpty(I)Lnet/minecraft/nbt/NbtCompound;
      intermediary method_68582 Lnet/minecraft/class_2499;method_68582(I)Lnet/minecraft/class_2487;
      official b Lug;b(I)Lua;
    • getList Link icon

      public Optional<NbtList> getList(int index)
      Returns the list at index, or an empty list if the index is out of bounds or if this is not a list of lists.
      Returns:
      the list at index, or an empty list if the index is out of bounds or if this is not a list of lists
      Mappings:
      Namespace Name Mixin selector
      named getList Lnet/minecraft/nbt/NbtList;getList(I)Ljava/util/Optional;
      intermediary method_10603 Lnet/minecraft/class_2499;method_10603(I)Ljava/util/Optional;
      official e Lug;e(I)Ljava/util/Optional;
    • getListOrEmpty Link icon

      public NbtList getListOrEmpty(int index)
      Mappings:
      Namespace Name Mixin selector
      named getListOrEmpty Lnet/minecraft/nbt/NbtList;getListOrEmpty(I)Lnet/minecraft/nbt/NbtList;
      intermediary method_68588 Lnet/minecraft/class_2499;method_68588(I)Lnet/minecraft/class_2499;
      official f Lug;f(I)Lug;
    • getShort Link icon

      public Optional<Short> getShort(int index)
      Returns the short at index, or 0 if the index is out of bounds or if this is not a list of shorts.
      Returns:
      the short at index, or 0 if the index is out of bounds or if this is not a list of shorts
      Mappings:
      Namespace Name Mixin selector
      named getShort Lnet/minecraft/nbt/NbtList;getShort(I)Ljava/util/Optional;
      intermediary method_10609 Lnet/minecraft/class_2499;method_10609(I)Ljava/util/Optional;
      official g Lug;g(I)Ljava/util/Optional;
    • getShort Link icon

      public short getShort(int index, short fallback)
      Mappings:
      Namespace Name Mixin selector
      named getShort Lnet/minecraft/nbt/NbtList;getShort(IS)S
      intermediary method_68578 Lnet/minecraft/class_2499;method_68578(IS)S
      official a Lug;a(IS)S
    • getInt Link icon

      public Optional<Integer> getInt(int index)
      Returns the integer at index, or 0 if the index is out of bounds or if this is not a list of integers.
      Returns:
      the integer at index, or 0 if the index is out of bounds or if this is not a list of integers
      Mappings:
      Namespace Name Mixin selector
      named getInt Lnet/minecraft/nbt/NbtList;getInt(I)Ljava/util/Optional;
      intermediary method_10600 Lnet/minecraft/class_2499;method_10600(I)Ljava/util/Optional;
      official h Lug;h(I)Ljava/util/Optional;
    • getInt Link icon

      public int getInt(int index, int fallback)
      Mappings:
      Namespace Name Mixin selector
      named getInt Lnet/minecraft/nbt/NbtList;getInt(II)I
      intermediary method_68576 Lnet/minecraft/class_2499;method_68576(II)I
      official a Lug;a(II)I
    • getIntArray Link icon

      public Optional<int[]> getIntArray(int index)
      Returns the int array at index, or an empty int array if the index is out of bounds or if this is not a list of int arrays.
      Returns:
      the int array at index, or an empty int array if the index is out of bounds or if this is not a list of int arrays
      API Note:
      Modifying the returned array also modifies the NBT int array.
      Mappings:
      Namespace Name Mixin selector
      named getIntArray Lnet/minecraft/nbt/NbtList;getIntArray(I)Ljava/util/Optional;
      intermediary method_36111 Lnet/minecraft/class_2499;method_36111(I)Ljava/util/Optional;
      official i Lug;i(I)Ljava/util/Optional;
    • getLongArray Link icon

      public Optional<long[]> getLongArray(int index)
      Returns the long array at index, or an empty int array if the index is out of bounds or if this is not a list of long arrays.
      Returns:
      the long array at index, or an empty int array if the index is out of bounds or if this is not a list of long arrays
      API Note:
      Modifying the returned array also modifies the NBT long array.
      Mappings:
      Namespace Name Mixin selector
      named getLongArray Lnet/minecraft/nbt/NbtList;getLongArray(I)Ljava/util/Optional;
      intermediary method_36112 Lnet/minecraft/class_2499;method_36112(I)Ljava/util/Optional;
      official j Lug;j(I)Ljava/util/Optional;
    • getDouble Link icon

      public Optional<Double> getDouble(int index)
      Returns the double at index, or 0.0 if the index is out of bounds or if this is not a list of doubles.
      Returns:
      the double at index, or 0.0 if the index is out of bounds or if this is not a list of doubles
      Mappings:
      Namespace Name Mixin selector
      named getDouble Lnet/minecraft/nbt/NbtList;getDouble(I)Ljava/util/Optional;
      intermediary method_10611 Lnet/minecraft/class_2499;method_10611(I)Ljava/util/Optional;
      official k Lug;k(I)Ljava/util/Optional;
    • getDouble Link icon

      public double getDouble(int index, double fallback)
      Mappings:
      Namespace Name Mixin selector
      named getDouble Lnet/minecraft/nbt/NbtList;getDouble(ID)D
      intermediary method_68574 Lnet/minecraft/class_2499;method_68574(ID)D
      official a Lug;a(ID)D
    • getFloat Link icon

      public Optional<Float> getFloat(int index)
      Returns the float at index, or 0.0f if the index is out of bounds or if this is not a list of floats.
      Returns:
      the float at index, or 0.0f if the index is out of bounds or if this is not a list of floats
      Mappings:
      Namespace Name Mixin selector
      named getFloat Lnet/minecraft/nbt/NbtList;getFloat(I)Ljava/util/Optional;
      intermediary method_10604 Lnet/minecraft/class_2499;method_10604(I)Ljava/util/Optional;
      official l Lug;l(I)Ljava/util/Optional;
    • getFloat Link icon

      public float getFloat(int index, float fallback)
      Mappings:
      Namespace Name Mixin selector
      named getFloat Lnet/minecraft/nbt/NbtList;getFloat(IF)F
      intermediary method_68575 Lnet/minecraft/class_2499;method_68575(IF)F
      official a Lug;a(IF)F
    • getString Link icon

      public Optional<String> getString(int index)
      Returns the stringified value at index, or an empty string if the index is out of bounds.

      Unlike other getters, this works with any type, not just NbtString.

      Returns:
      the stringified value at index, or an empty string if the index is out of bounds
      Mappings:
      Namespace Name Mixin selector
      named getString Lnet/minecraft/nbt/NbtList;getString(I)Ljava/util/Optional;
      intermediary method_10608 Lnet/minecraft/class_2499;method_10608(I)Ljava/util/Optional;
      official m Lug;m(I)Ljava/util/Optional;
    • getString Link icon

      public String getString(int index, String fallback)
      Mappings:
      Namespace Name Mixin selector
      named getString Lnet/minecraft/nbt/NbtList;getString(ILjava/lang/String;)Ljava/lang/String;
      intermediary method_68577 Lnet/minecraft/class_2499;method_68577(ILjava/lang/String;)Ljava/lang/String;
      official a Lug;a(ILjava/lang/String;)Ljava/lang/String;
    • getNullable Link icon

      @Nullable private @Nullable NbtElement getNullable(int index)
      Mappings:
      Namespace Name Mixin selector
      named getNullable Lnet/minecraft/nbt/NbtList;getNullable(I)Lnet/minecraft/nbt/NbtElement;
      intermediary method_68590 Lnet/minecraft/class_2499;method_68590(I)Lnet/minecraft/class_2520;
      official n Lug;n(I)Lva;
    • getOptional Link icon

      private Optional<NbtElement> getOptional(int index)
      Mappings:
      Namespace Name Mixin selector
      named getOptional Lnet/minecraft/nbt/NbtList;getOptional(I)Ljava/util/Optional;
      intermediary method_68591 Lnet/minecraft/class_2499;method_68591(I)Ljava/util/Optional;
      official o Lug;o(I)Ljava/util/Optional;
    • size Link icon

      public int size()
      Specified by:
      size in interface AbstractNbtList
      Specified by:
      size in interface Collection<NbtElement>
      Specified by:
      size in interface List<NbtElement>
      Specified by:
      size in class AbstractCollection<NbtElement>
    • get Link icon

      public NbtElement get(int int2)
      Specified by:
      get in interface AbstractNbtList
      Specified by:
      get in interface List<NbtElement>
      Specified by:
      get in class AbstractList<NbtElement>
      Mappings:
      Namespace Name Mixin selector
      named get Lnet/minecraft/nbt/NbtList;get(I)Lnet/minecraft/nbt/NbtElement;
      intermediary method_10534 Lnet/minecraft/class_2499;method_10534(I)Lnet/minecraft/class_2520;
      official method_10534 Lug;method_10534(I)Lva;
    • set Link icon

      public NbtElement set(int int2, NbtElement nbtElement)
      Specified by:
      set in interface List<NbtElement>
      Overrides:
      set in class AbstractList<NbtElement>
      Mappings:
      Namespace Name Mixin selector
      named set Lnet/minecraft/nbt/NbtList;set(ILnet/minecraft/nbt/NbtElement;)Lnet/minecraft/nbt/NbtElement;
      intermediary method_68585 Lnet/minecraft/class_2499;method_68585(ILnet/minecraft/class_2520;)Lnet/minecraft/class_2520;
      official c Lug;c(ILva;)Lva;
    • add Link icon

      public void add(int int2, NbtElement nbtElement)
      Specified by:
      add in interface List<NbtElement>
      Overrides:
      add in class AbstractList<NbtElement>
      Mappings:
      Namespace Name Mixin selector
      named add Lnet/minecraft/nbt/NbtList;add(ILnet/minecraft/nbt/NbtElement;)V
      intermediary method_68586 Lnet/minecraft/class_2499;method_68586(ILnet/minecraft/class_2520;)V
      official d Lug;d(ILva;)V
    • setElement Link icon

      public boolean setElement(int index, NbtElement element)
      Sets the element at index to element. Does nothing if the types were incompatible.
      Specified by:
      setElement in interface AbstractNbtList
      Returns:
      whether the element was actually set
      Mappings:
      Namespace Name Mixin selector
      named setElement Lnet/minecraft/nbt/AbstractNbtList;setElement(ILnet/minecraft/nbt/NbtElement;)Z
      intermediary method_10535 Lnet/minecraft/class_2483;method_10535(ILnet/minecraft/class_2520;)Z
      official a Ltz;a(ILva;)Z
    • addElement Link icon

      public boolean addElement(int index, NbtElement element)
      Inserts element at index. Does nothing if the types were incompatible.
      Specified by:
      addElement in interface AbstractNbtList
      Returns:
      whether the element was actually added
      Mappings:
      Namespace Name Mixin selector
      named addElement Lnet/minecraft/nbt/AbstractNbtList;addElement(ILnet/minecraft/nbt/NbtElement;)Z
      intermediary method_10533 Lnet/minecraft/class_2483;method_10533(ILnet/minecraft/class_2520;)Z
      official b Ltz;b(ILva;)Z
    • copy Link icon

      public NbtList copy()
      Description copied from interface: NbtElement
      Returns an NBT element of equal value that won't change with this element.
      Specified by:
      copy in interface NbtElement
      Returns:
      an NBT element of equal value that won't change with this element
      Mappings:
      Namespace Name Mixin selector
      named copy Lnet/minecraft/nbt/NbtList;copy()Lnet/minecraft/nbt/NbtList;
      intermediary method_10612 Lnet/minecraft/class_2499;method_10612()Lnet/minecraft/class_2499;
      official g Lug;g()Lug;
    • asNbtList Link icon

      public Optional<NbtList> asNbtList()
      Specified by:
      asNbtList in interface NbtElement
      Mappings:
      Namespace Name Mixin selector
      named asNbtList Lnet/minecraft/nbt/NbtElement;asNbtList()Ljava/util/Optional;
      intermediary method_68592 Lnet/minecraft/class_2520;method_68592()Ljava/util/Optional;
      official t_ Lva;t_()Ljava/util/Optional;
    • equals Link icon

      public boolean equals(Object o)
      Specified by:
      equals in interface Collection<NbtElement>
      Specified by:
      equals in interface List<NbtElement>
      Overrides:
      equals in class AbstractList<NbtElement>
      Mappings:
      Namespace Name Mixin selector
      named equals Lnet/minecraft/nbt/NbtList;equals(Ljava/lang/Object;)Z
      intermediary equals Lnet/minecraft/class_2499;equals(Ljava/lang/Object;)Z
      official equals Lug;equals(Ljava/lang/Object;)Z
    • hashCode Link icon

      public int hashCode()
      Specified by:
      hashCode in interface Collection<NbtElement>
      Specified by:
      hashCode in interface List<NbtElement>
      Overrides:
      hashCode in class AbstractList<NbtElement>
    • stream Link icon

      public Stream<NbtElement> stream()
      Specified by:
      stream in interface AbstractNbtList
      Specified by:
      stream in interface Collection<NbtElement>
    • streamCompounds Link icon

      public Stream<NbtCompound> streamCompounds()
      Mappings:
      Namespace Name Mixin selector
      named streamCompounds Lnet/minecraft/nbt/NbtList;streamCompounds()Ljava/util/stream/Stream;
      intermediary method_68589 Lnet/minecraft/class_2499;method_68589()Ljava/util/stream/Stream;
      official j Lug;j()Ljava/util/stream/Stream;
    • accept Link icon

      public void accept(NbtElementVisitor visitor)
      Specified by:
      accept in interface NbtElement
      Mappings:
      Namespace Name Mixin selector
      named accept Lnet/minecraft/nbt/NbtElement;accept(Lnet/minecraft/nbt/visitor/NbtElementVisitor;)V
      intermediary method_32289 Lnet/minecraft/class_2520;method_32289(Lnet/minecraft/class_5627;)V
      official a Lva;a(Lve;)V
    • clear Link icon

      public void clear()
      Specified by:
      clear in interface AbstractNbtList
      Specified by:
      clear in interface Collection<NbtElement>
      Specified by:
      clear in interface List<NbtElement>
      Overrides:
      clear in class AbstractList<NbtElement>
    • doAccept Link icon

      public NbtScanner.Result doAccept(NbtScanner visitor)
      Specified by:
      doAccept in interface NbtElement
      Mappings:
      Namespace Name Mixin selector
      named doAccept Lnet/minecraft/nbt/NbtElement;doAccept(Lnet/minecraft/nbt/scanner/NbtScanner;)Lnet/minecraft/nbt/scanner/NbtScanner$Result;
      intermediary method_39850 Lnet/minecraft/class_2520;method_39850(Lnet/minecraft/class_6836;)Lnet/minecraft/class_6836$class_6838;
      official a Lva;a(Lux;)Lux$b;