Crash because of item with custom NBTTag

Discussion in 'Plugin Development' started by Sylian, Aug 1, 2019.

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

    Sylian

    Hello so im trying my best to create a custom NBTTag for a weapon and im calling the
    attribute mana

    Now i can spawn the weapon in and all without problems but as soon as the player clicks on it in the backpack it crashes the player with this error: io.netty.handler.codec.decoderexception: java.lang.ArrayIndexOutOfBoundsException 1


    Code:
    damage.set("AttributeName", new NBTTagString("Mana"));
           
            damage.set("Name", new NBTTagString("Mana"));
           
           
            damage.set("Slot", new NBTTagString("mainhand"));
           
            damage.set("Operation", new NBTTagInt(0));
           
            damage.set("Amount", new NBTTagInt(12));
           
            damage.set("UUIDMost", new NBTTagInt(rand.nextInt(64000) + 32001));
           
            damage.set("UUIDLeast", new NBTTagInt(rand.nextInt(128000) + 64001));
    Im new to NBTTags so please dont rip my head off if i dont understand xD
     
  2. Offline

    KarimAKL

    @Sylian Which line causes the error? That's an ArrayIndexOutOfBoundsException, do you have a list or array somewhere?
     
  3. Offline

    Machine Maker

  4. Offline

    Sylian

    I dont know what line does it since i dont have any array that is used for this stuff.

    If i remove all my custom nbttag stuff it all works with the gernic.attackDamage

    Here is all the code i have for the nbtTag

    Code:
            // DOWN HERE IS WHERE I TEST NEW THINGS!
           
            net.minecraft.server.v1_14_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(weapon);
           
            NBTTagCompound tag = nmsStack.getOrCreateTag();
           
            NBTTagList atrModifers = new NBTTagList();
           
            NBTTagCompound damage = new NBTTagCompound();
           
            NBTTagCompound atkSpeed = new NBTTagCompound();
           
            Random rand = new Random();
           
           
           
            atkSpeed.setString("AttributeName", "generic.attackSpeed");
           
            atkSpeed.setString("Name", "generic.attackSpeed");
           
            atkSpeed.setString("Slot", "mainhand");
           
            atkSpeed.setInt("Operation", 0);
           
            atkSpeed.setDouble("Amount", 0.6);
           
            atkSpeed.setLong("UUIDMost", rand.nextInt(32000) + 1);
           
            atkSpeed.setLong("UUIDLeast", rand.nextInt(64000) + 32001);
           
            /*
           
    // If i uncommend this and remove the other stuff below that does the damage.setString and so on then i get that error but if its like it is right now there is no problems with it.
    
            damage.set("AttributeName", new NBTTagString("Mana"));
           
            damage.set("Name", new NBTTagString("Mana"));
           
           
            damage.set("Slot", new NBTTagString("mainhand"));
           
            damage.set("Operation", new NBTTagInt(0));
           
            damage.set("Amount", new NBTTagInt(12));
           
            damage.set("UUIDMost", new NBTTagInt(rand.nextInt(64000) + 32001));
           
            damage.set("UUIDLeast", new NBTTagInt(rand.nextInt(128000) + 64001));
           
            */
           
           
           
            damage.setString("AttributeName", "generic.attackDamage");
           
            damage.setString("Name", "generic.attackDamage");
           
           
           
            damage.setString("Slot", "mainhand");
           
            damage.setInt("Operation", 0);
           
            damage.setDouble("Amount", 1337);
           
            damage.setLong("UUIDMost", rand.nextInt(64000) + 32001);
           
            damage.setLong("UUIDLeast", rand.nextInt(128000) + 64001);
           
           
           
            atrModifers.add(damage);
           
           
           
           
            atrModifers.add(atkSpeed);
           
            tag.set("AttributeModifiers", atrModifers);
           
           
           
            nmsStack.setTag(tag);
    
           
            ItemStack updatedItem = CraftItemStack.asCraftMirror(nmsStack);
           
            // Returns the newly created weapon!
            //return weapon;
            return updatedItem;
     
    Last edited: Aug 1, 2019
  5. Offline

    KarimAKL

    @Sylian The stacktrace let's you know what line caused the error.
     
  6. Offline

    Sylian

    I just added the stacktrace you asked for and in the image below you can see what it tells me.

    As you see i issue the /createweapon command and it works since it would give me an error if not.
    It gives me the item and i can see the Attribute that i created.

    I can even use it and kill mobs and so on but as soon as i open the inventory and click on it it simply gives me that error.
     

    Attached Files:

  7. Offline

    KarimAKL

    @Sylian Huh, i'm not exactly sure why that happens, i've never gotten anything like that.
     
  8. Offline

    Sylian

    Im so lost since no one i have asked can help me here.

    Even opened the player.dat in a NBTViewer and as far as i can see there are no errors in any of the tags.
     

    Attached Files:

  9. Offline

    Machine Maker

    @Sylian So in that block of code you have commented out. If you uncomment just one of those lines it throws the error? Try to see exactly what line is causing the issue.
     
  10. Offline

    Sylian

    I think its the

    Code:
    damage.set("Name", new NBTTagString("mana"));
    Since i just tried with only the AttributeName one and then it said name cannot be empty which i already knew i cant be empty so i uncommend the line i show above and then it gave same error.

    As you can see here both the AttributeName and Name is the same.

    Code:
    damage.set("AttributeName", new NBTTagString("mana"));
    damage.set("Name", new NBTTagString("mana"));
    
    What am i doing wrong in the name ?
     
    Last edited: Aug 1, 2019
  11. Offline

    Machine Maker

    Is Name maybe already a tag? Or a reserved name or something? I’m grasping here cause I have no clue.
     
  12. Offline

    KarimAKL

    @Sylian I'm not sure if the full error is saved somewhere, but if you can find it then could you post that and your version?
    Maybe the 'crash-reports' folder in the %appdata%/.minecraft folder (on Windows)
     
  13. Offline

    Sylian

    Just tried and same happeneds.

    Nothing in there besides the same error as server gives me :/

    A little bit off topic but whatever xD

    So i want to make a text that hover above the player using the ArmorStand and i got the thing to hover above my head now by setting the armor stand as passennger on my player.

    Now i want to move it 1 or 2 blocks down so its closer to my head instead of far away from my head. Kinda like your name when people look at you maybe right above the name tag.

    How can i change the postion of a passengers Y pos ?

    I have tried but if i do it right after it overrides it as i already gussed it would so i cant really figure out how i can do it other ways.

    You got any good idea ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 1, 2019
  14. Offline

    KarimAKL

    @Sylian I don't think it's possible to move the passenger. Maybe making the armorstand follow the player by updating it's location in the PlayerMoveEvent would work?
     
  15. Offline

    Sylian

    Yeah i thought of that but wouldnt that make the server lag if we say 50+ players are on
     
  16. Offline

    KarimAKL

    @Sylian Probably, but i don't know how you would do it otherwise. :p
     
  17. Offline

    Sylian

    Hey i got another question xD

    So i have been thinking about how to keep on creating this plugin and i choose to do it the lore way instead of stressing out about all the NBT tags and NMS stuff.

    Now my question is how would i go around removing lets say all attributes from a Wooden sword without the NBTTags and NMS stuff ?

    And next thing i would want to ask is after i removed the attributes how would i go around making my items use the lore named "Attack Speed" for the attack speed ?
     
  18. Offline

    Sylian

    Recreated my code that creates the weapon and got it working and found out i needed to call the custom attribute name using the generic.<custom name>

    However....

    When i now move the item around in my backpack it removes the tag completely from the item.

    Do you have any idea on how i can fix this ?
     
  19. Offline

    KarimAKL

    @Sylian Do you do anything with the item in the InventoryClickEvent?
     
  20. Offline

    Sylian

    Nope. My plan was to do something with getting the tag and make it so it would apply the tag again.
     
Thread Status:
Not open for further replies.

Share This Page