Class NbtList

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

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

An NBT list holds values of the same NBT type. The NBT type of an NBT list is determined once its first element is inserted; empty NBT lists return NbtElement.END_TYPE as their held NBT type.

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 vd
  • Field Details

    • SIZE

      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 b Lvd;b:I
    • TYPE

      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 Lvd;a:Lvw;
    • value

      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 c Lvd;c:Ljava/util/List;
    • type

      private byte type
      Mappings:
      Namespace Name Mixin selector
      named type Lnet/minecraft/nbt/NbtList;type:B
      intermediary field_11551 Lnet/minecraft/class_2499;field_11551:B
      official w Lvd;w:B
  • Constructor Details

    • NbtList

      NbtList(List<NbtElement> list, byte type)
      Mappings:
      Namespace Name Mixin selector
      named <init> Lnet/minecraft/nbt/NbtList;<init>(Ljava/util/List;B)V
      intermediary <init> Lnet/minecraft/class_2499;<init>(Ljava/util/List;B)V
      official <init> Lvd;<init>(Ljava/util/List;B)V
    • NbtList

      public NbtList()
  • Method Details

    • write

      public void write(DataOutput output) throws IOException
      Writes the NBT element to output.
      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 Lvu;a(Ljava/io/DataOutput;)V
    • getSizeInBytes

      public int getSizeInBytes()
      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 Lvu;a()I
    • getType

      public byte getType()
      Returns the type of this NBT element.
      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 Lvu;b()B
    • getNbtType

      public NbtType<NbtList> getNbtType()
      Returns the NBT type definition of this NBT element.
      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 Lvu;c()Lvw;
    • toString

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

      private void forgetTypeIfEmpty()
      Mappings:
      Namespace Name Mixin selector
      named forgetTypeIfEmpty Lnet/minecraft/nbt/NbtList;forgetTypeIfEmpty()V
      intermediary method_17809 Lnet/minecraft/class_2499;method_17809()V
      official g Lvd;g()V
    • remove

      public NbtElement remove(int int2)
      Specified by:
      remove in interface List<NbtElement>
      Specified by:
      remove in class AbstractNbtList<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 Lvd;method_10536(I)Lvu;
    • isEmpty

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

      public 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)Lnet/minecraft/nbt/NbtCompound;
      intermediary method_10602 Lnet/minecraft/class_2499;method_10602(I)Lnet/minecraft/class_2487;
      official a Lvd;a(I)Lux;
    • getList

      public 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)Lnet/minecraft/nbt/NbtList;
      intermediary method_10603 Lnet/minecraft/class_2499;method_10603(I)Lnet/minecraft/class_2499;
      official b Lvd;b(I)Lvd;
    • getShort

      public 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)S
      intermediary method_10609 Lnet/minecraft/class_2499;method_10609(I)S
      official d Lvd;d(I)S
    • getInt

      public int 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)I
      intermediary method_10600 Lnet/minecraft/class_2499;method_10600(I)I
      official e Lvd;e(I)I
    • getIntArray

      public 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)[I
      intermediary method_36111 Lnet/minecraft/class_2499;method_36111(I)[I
      official f Lvd;f(I)[I
    • getLongArray

      public 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)[J
      intermediary method_36112 Lnet/minecraft/class_2499;method_36112(I)[J
      official g Lvd;g(I)[J
    • getDouble

      public 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)D
      intermediary method_10611 Lnet/minecraft/class_2499;method_10611(I)D
      official h Lvd;h(I)D
    • getFloat

      public 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)F
      intermediary method_10604 Lnet/minecraft/class_2499;method_10604(I)F
      official i Lvd;i(I)F
    • getString

      public 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/lang/String;
      intermediary method_10608 Lnet/minecraft/class_2499;method_10608(I)Ljava/lang/String;
      official j Lvd;j(I)Ljava/lang/String;
    • size

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

      public NbtElement get(int int2)
      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 k Lvd;k(I)Lvu;
    • set

      public NbtElement set(int int2, NbtElement nbtElement)
      Specified by:
      set in interface List<NbtElement>
      Specified by:
      set in class AbstractNbtList<NbtElement>
      Mappings:
      Namespace Name Mixin selector
      named set Lnet/minecraft/nbt/NbtList;set(ILnet/minecraft/nbt/NbtElement;)Lnet/minecraft/nbt/NbtElement;
      intermediary method_10606 Lnet/minecraft/class_2499;method_10606(ILnet/minecraft/class_2520;)Lnet/minecraft/class_2520;
      official method_10606 Lvd;method_10606(ILvu;)Lvu;
    • add

      public void add(int int2, NbtElement nbtElement)
      Specified by:
      add in interface List<NbtElement>
      Specified by:
      add in class AbstractNbtList<NbtElement>
      Mappings:
      Namespace Name Mixin selector
      named add Lnet/minecraft/nbt/NbtList;add(ILnet/minecraft/nbt/NbtElement;)V
      intermediary method_10531 Lnet/minecraft/class_2499;method_10531(ILnet/minecraft/class_2520;)V
      official method_10531 Lvd;method_10531(ILvu;)V
    • setElement

      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 class AbstractNbtList<NbtElement>
      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 Luw;a(ILvu;)Z
    • addElement

      public boolean addElement(int index, NbtElement element)
      Inserts element at index. Does nothing if the types were incompatible.
      Specified by:
      addElement in class AbstractNbtList<NbtElement>
      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 Luw;b(ILvu;)Z
    • canAdd

      private boolean canAdd(NbtElement element)
      Mappings:
      Namespace Name Mixin selector
      named canAdd Lnet/minecraft/nbt/NbtList;canAdd(Lnet/minecraft/nbt/NbtElement;)Z
      intermediary method_10605 Lnet/minecraft/class_2499;method_10605(Lnet/minecraft/class_2520;)Z
      official a Lvd;a(Lvu;)Z
    • copy

      public NbtList copy()
      Description copied from interface: NbtElement
      Returns an NBT element of equal value that won't change with this element.
      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 e Lvd;e()Lvd;
    • equals

      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 Lvd;equals(Ljava/lang/Object;)Z
    • hashCode

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

      public void accept(NbtElementVisitor visitor)
      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 Lvu;a(Lvy;)V
    • getHeldType

      public byte getHeldType()
      Gets the type of element that this list holds.
      Specified by:
      getHeldType in class AbstractNbtList<NbtElement>
      Returns:
      the type of element that this list holds
      Mappings:
      Namespace Name Mixin selector
      named getHeldType Lnet/minecraft/nbt/AbstractNbtList;getHeldType()B
      intermediary method_10601 Lnet/minecraft/class_2483;method_10601()B
      official f Luw;f()B
    • clear

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

      public NbtScanner.Result doAccept(NbtScanner visitor)
      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 Lvu;a(Lvr;)Lvr$b;