Solved NBT not work!

Discussion in 'Spigot Plugin Development' started by Lemar98, Mar 6, 2020.

Thread Status:
Not open for further replies.
  1. Hello
    I use paper 1.12.2

    My problem in check my itemStack for nbt tags.
    I spawn random items in my chest every 1 minute and if items contains wood axe, it must be contain some nbt tags.

    Tags has been set successfull, we confirm this information on the axe [​IMG]

    But when I use this method
    Code (Java):
        public static String getValue(ItemStack itemStack, String key) {
            if(hasKey(itemStack, key)) {
                net.minecraft.server.v1_12_R1.ItemStack nbtStack = CraftItemStack.asNMSCopy(itemStack);
                NBTTagCompound nbtTag = nbtStack.hasTag() ? nbtStack.getTag() : new NBTTagCompound();
                return nbtTag.getString(key);
            }
            return null;
        }
    it return null, because my hasKey method is false. My hasKey method
    Code (Java):
      public static boolean hasKey(ItemStack itemStack, String key) {
            net.minecraft.server.v1_12_R1.ItemStack nbtStack = CraftItemStack.asNMSCopy(itemStack);
            NBTTagCompound nbtTag = nbtStack.hasTag() ? nbtStack.getTag() : new NBTTagCompound();
            return nbtTag.hasKey(key);
        }
     
    I don’t understand why in the photo above these tags are, but when they are checked, they are not

    P.S. How I check axe for tags:

    Code (Java):
    System.out.println(NbtUtils.hasKey(this.itemStack, "chance"));
            System.out.println(NbtUtils.hasKey(this.itemStack, "level"));
            System.out.println(NbtUtils.hasKey(this.itemStack, "dmg"));
    P.S.S sorry for my bad English =(
     
  2. Does 1.12 not have the persistentdata that spigot introduces? Would make things much easyer for you and also avoid nms
     
  3. I know it, but 1.12 really not contain pers.data
     
Thread Status:
Not open for further replies.