#Changing the NBT data

1 messages · Page 1 of 1 (latest)

minor hinge
#

Hello. Why don't my NBT tags get removed from the item?
My code to remove the tags:

    public ItemStack fixSign(ItemStack itemStack) {
        if(!itemStack.getType().toString().contains("SIGN")) return itemStack;

        net.minecraft.server.v1_12_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
        NBTTagCompound tag = nmsItem.getTag();

        if (tag == null) return itemStack;
        NBTTagCompound blockEntityTag = tag.getCompound("BlockEntityTag");
        if (blockEntityTag == null) return itemStack;

        System.out.println("Before removal: " + blockEntityTag);

        blockEntityTag.remove("Text1");
        blockEntityTag.remove("Text2");
        blockEntityTag.remove("Text3");
        blockEntityTag.remove("Text4");

        System.out.println("After removal: " + blockEntityTag);

        tag.set("BlockEntityTag", blockEntityTag);
        nmsItem.setTag(tag);

        return CraftItemStack.asBukkitCopy(nmsItem);
    }

And then I just set the item:

                if(event.getHand() == EquipmentSlot.HAND) player.getInventory().setItemInMainHand(nbtManager.fixSign(itemStack));
                else player.getInventory().setItemInOffHand(nbtManager.fixSign(itemStack));

the respective output in the console:

[20:42:13 INFO]: Before removal: {Text4:"{\"text\":\"\"}",Text3:"{\"text\":\"\"}",Text2:"{\"text\":\"\"}",Text1:"{\"text\":\"\"}"}
[20:42:13 INFO]: After removal: {}

Also I printed the tag to the console: tag: {BlockEntityTag:{},display:{Name:"Краш табличка"}}

cedar stag
#

So when are you fixing the item