Issue with new NBTItem()
EnderStudiosDEV opened this issue · 1 comments
meta.setDisplayName("§3" + name);
meta.setLore(lore);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
Bukkit.broadcastMessage(nbti.getKeys().toString());
Bukkit.broadcastMessage(nbti.getInteger("atk").toString());
i = nbti.getItem();
i.setItemMeta(meta);
NBTItem nbti2 = new NBTItem(i);
System.out.println(nbti2.getInteger("atk").toString());
return i;
I wrote this code to make sure I wanted my custom damage system to work as it should. However, each time it broadcasts different things. And yes I know the first line has spaces on the github, the code formatter was being buggy.
[03:31:44] [Server thread/INFO]: [hp, atk, Damage]
[03:31:44] [Server thread/INFO]: 42
[03:31:44] [Server thread/INFO]: 0
I'm using version 2.8.0 on my 1.17.1 server. Is there some way I can get it to work properly so it carries the nbt data between the 2?
i = nbti.getItem();
i.setItemMeta(meta);
That won't work.
You have to split item meta and nbt into two phases and fully do one thing before doing the other thing. Otherwise, it will overwrite the changes. So: get Item meta, change item meta, set item meta, create nbtitem, change nbt, get the modified item.