Solved NBTTagList in 1.17

Discussion in 'Plugin Development' started by Tim_M, Aug 8, 2021.

Thread Status:
Not open for further replies.
  1. Offline

    Tim_M

    In version pre-1.17 to add something to a NBTTagList you needed to run NBTTagList.add(NBTBase nbt) and all would be fine. But now the method has been changed to: NBTTagList.add(int index, NBTBase nbt). You now need to set the index! But it never works since the size of the NBTTagList is 0 by default. How can I set the size of an NBTTagList??
     
  2. Offline

    Shqep

    @Tim_M
    That's weird that you can't find the add(NBTBase) method as it's still there. Both add(NBTBase) and add(int, NBTBase) are there. NBTTagList inherits methods from AbstractList.

    Are you sure the IDE is spewing errors and saying not found, or did you look through the class and couldn't find it? Because auto-completion also shows the add method.

    Also, about the add(int, item) method. It differs from set(int, item). Here's the difference when used:
    PHP:
    final List<String> list = Arrays.asList("Never""gonna""give""you""up");

    // Sets the item at index 4 to a value.
    list.set(4"pewdiepie"); // The list is now [Never, gonna, give, you, pewdiepie]

    // Appends an item at index 4. The item at index 4 previously moves to index 5, and so on.
    list.add(4"pewdiepie"); // The list is now [Never, gonna, give, you, pewdiepie, up]
    So yes, you can add an item to an empty list via add(0, item).
     
  3. Offline

    Tim_M

    I have fixed it. The issue is that the NBTTagList doesnt have the .add(NBTBase nbt) anymore. I had to get it's superclass and call it. Then it worked.
     
    Last edited: Aug 8, 2021
  4. Offline

    KarimAKL

    It is inherited from the superclass, though. It is probably just your IDE acting up.
     
  5. Offline

    Tim_M

    oh no it wasn't, the error was happening during rutime.
     
Thread Status:
Not open for further replies.

Share This Page