(Item/Entity/Tile) NBT API 1.5.1

Add custom NBT tags or modify tags of Items/Entities/Tiles without NMS!

  1. tr7zw
    Tested Minecraft Versions:
    • 1.7
    • 1.8
    • 1.9
    • 1.10
    • 1.11
    • 1.12
    Source Code:
    https://github.com/tr7zw/Item-NBT-API
    (Item/Entity/Tile) NBT API
    The NBT API allows you to add custom NBT tags to Itemstacks, TileEntities and Entities, or modify excisting ones!
    It completely uses reflections to interact with NMS code and works with all the latest versions. On server start the plugin checks all reflections.

    Tested on Spigot
    • 1.7*-1.12
    • On startup you will get a notification if there is a version problem!
    * 1.7 Notes: Use a 1.7 with R4 (1.7.10), NBTLists may not work, everything using Gson is disabled(Add Gson before the NBTAPI loads, to turn it back on), and you can't get the NBTTypes, because 1.7 is missing this feature.

    What do I have to do as server owner?
    Just download the jar and drop it in the plugins folder. Done.

    How can I use the API as developer?
    Create the NBT Wrapper:
    Code (Text):
    NBTItem nbti = new NBTItem(item);
    NBTEntity nbtent = new NBTEntity(zombie);
    NBTTileEntity tent = new NBTTileEntity(block.getState());
     
    Add/Get/Override NBT tags:
    Code (Text):
    //Set
    nbti.setString("Stringtest", "Teststring");
    nbti.setInteger("Inttest", 42);
    nbti.setDouble("Doubletest", 1.5d);
    nbti.setBoolean("Booleantest", true);
    //More are avaible!
    //Get
    nbti.getString("Stringtest");
    nbti.getInteger("Inttest");
    nbti.getDouble("Doubletest");
    nbti.getBoolean("Booleantest");
    //Get all Tags
    nbti.getKeys();
    //Check for an tag
    nbti.hasKey("Key");
    //Remove a tag
    nbti.removeKey("Key");
    //or
    nbti.setString("Stringtest", null);
    //Create NBTTagCombounds(Imagine folders)
    nbti.addCompound("subtag");
    //Get Compound
    NBTCompound comp = nbti.getCompound("subtag");
    //Get Compound parent(null at root)
    comp.getParent();
    //Save Objects via Gson
    nbti.setObject("myobject", new SimpleJsonTestObject());
    //Get Objects
    SimpleJsonTestObject simpleObject = nbti.getObject("myobject", SimpleJsonTestObject.class);

    //Access/create lists
    nbtent.getList("Attributes", NBTType.NBTTagCompound);
     
    And finally get back the Bukkit Itemstack(Changes on Tiles/Entities will happen directly):
    Code (Text):
    nbti.getItem();
    Example Code
    Code (Text):

     Zombie z = (Zombie) b.getWorld().spawnEntity(b.getLocation().add(0, 1, 0), EntityType.ZOMBIE);
                    NBTEntity nbtent = new NBTEntity(z);
                    nbtent.setByte("CanPickUpLoot", (byte) 1);
                    NBTList list = nbtent.getList("Attributes", NBTType.NBTTagCompound);
                    for(int i = 0; i < list.size(); i++){
                        NBTListCompound lc = list.getCompound(i);
                        if(lc.getString("Name").equals("generic.attackDamage")){
                            lc.setDouble("Base", 0.5d);
                        }
                    }
     

    Code (Text):

            ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
            NBTItem nbti = new NBTItem(head);
            NBTCompound disp = nbti.addCompound("display");
            disp.setString("Name", "Testitem");
            NBTList l = disp.getList("Lore", NBTType.NBTTagString);
            l.addString("Some lore");
            NBTCompound skull = nbti.addCompound("SkullOwner");
            skull.setString("Name", "tr7zw");
            skull.setString("Id", "fce0323d-7f50-4317-9720-5f6b14cf78ea");
            NBTListCompound texture = skull.addCompound("Properties").getList("textures", NBTType.NBTTagCompound).addCompound();
            texture.setString("Signature", "XpRfRz6/vXE6ip7/vq+40H6W70GFB0yjG6k8hG4pmFdnJFR+VQhslE0gXX/i0OAGThcAVSIT+/W1685wUxNofAiy+EhcxGNxNSJkYfOgXEVHTCuugpr+EQCUBI6muHDKms3PqY8ECxdbFTUEuWxdeiJsGt9VjHZMmUukkGhk0IobjQS3hjQ44FiT1tXuUU86oAxqjlKFpXG/iXtpcoXa33IObSI1S3gCKzVPOkMGlHZqRqKKElB54I2Qo4g5CJ+noudIDTzxPFwEEM6XrbM0YBi+SOdRvTbmrlkWF+ndzVWEINoEf++2hkO0gfeCqFqSMHuklMSgeNr/YtFZC5ShJRRv7zbyNF33jZ5DYNVR+KAK9iLO6prZhCVUkZxb1/BjOze6aN7kyN01u3nurKX6n3yQsoQQ0anDW6gNLKzO/mCvoCEvgecjaOQarktl/xYtD4YvdTTlnAlv2bfcXUtc++3UPIUbzf/jpf2g2wf6BGomzFteyPDu4USjBdpeWMBz9PxVzlVpDAtBYClFH/PFEQHMDtL5Q+VxUPu52XlzlUreMHpLT9EL92xwCAwVBBhrarQQWuLjAQXkp3oBdw6hlX6Fj0AafMJuGkFrYzcD7nNr61l9ErZmTWnqTxkJWZfZxmYBsFgV35SKc8rkRSHBNjcdKJZVN4GA+ZQH5B55mi4=");
            texture.setString("Value", "eyJ0aW1lc3RhbXAiOjE0OTMwNDkwMTcxNTIsInByb2ZpbGVJZCI6ImZjZTAzMjNkN2Y1MDQzMTc5NzIwNWY2YjE0Y2Y3OGVhIiwicHJvZmlsZU5hbWUiOiJ0cjd6dyIsInNpZ25hdHVyZVJlcXVpcmVkIjp0cnVlLCJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTI3NDZlNWU5OGMwZWRmZTU1YTI3ZGRjNjUxMmJmNjllYzJiYmNlNmM3ZmNhNTQ5YmEzNjZkYThiNTRjZTRkYiJ9fX0=");

            NBTList attribute = nbti.getList("AttributeModifiers", NBTType.NBTTagCompound);
            NBTListCompound mod1 = attribute.addCompound();
            mod1.setInteger("Amount", 10);
            mod1.setString("AttributeName", "generic.maxHealth");
            mod1.setString("Name", "generic.maxHealth");
            mod1.setInteger("Operation", 0);
            mod1.setInteger("UUIDLeast", 59664);
            mod1.setInteger("UUIDMost", 31453);

            nbti.setInteger("HideFlags", 4);
            nbti.setBoolean("Unbreakable", true);
            head = nbti.getItem();
            e.getPlayer().getInventory().addItem(head);
     

    Code (Text):

                    Ocelot m = (Ocelot) e.getPlayer().getWorld().spawnEntity(e.getPlayer().getLocation(), EntityType.OCELOT);
                    NBTEntity ent = new NBTEntity(m);
                    System.out.println(ent);
     
    Output:
    Code (Text):

    -AgeLocked: 0b
    -HurtByTimestamp: 0
    -CatType: 0
    -Leashed: 0b
    -Health: 10.0f
    -Sitting: 0b
    -Attributes: [0:{Base:10.0d,Name:"generic.maxHealth"},1:{Base:0.0d,Name:"generic.knockbackResistance"},2:{Base:0.30000001192092896d,Name:"generic.movementSpeed"},3:{Base:0.0d,Name:"generic.armor"},4:{Base:0.0d,Name:"generic.armorToughness"},5:{Base:16.0d,Modifiers:[0:{UUIDMost:-8783172028836920024L,UUIDLeast:-6820414278857408689L,Amount:-0.030166473586416633d,Operation:1,Name:"Random spawn bonus"}],Name:"generic.followRange"}]
    -FallFlying: 0b
    -LeftHanded: 0b
    -ForcedAge: 0
    -AbsorptionAmount: 0.0f
    -HandItems: [0:{},1:{}]
    -ArmorDropChances: [0:0.085f,1:0.085f,2:0.085f,3:0.085f]
    -OwnerUUID: ""
    -InLove: 0
    -DeathTime: 0s
    -ArmorItems: [0:{},1:{},2:{},3:{}]
    -CanPickUpLoot: 0b
    -HandDropChances: [0:0.085f,1:0.085f]
    -PersistenceRequired: 0b
    -HurtTime: 0s
    -Age: 0
     

    Code (Text):
                    NBTTileEntity tent = new NBTTileEntity(b.getState());
                    tent.setString("Lock", "test");

    More Infos:

    This API can't be used for:
    • Adding custom tags to TileEntities/Entities
    Git: https://github.com/tr7zw/Item-NBT-API
    Feel free to create forks for your need! (Send me a message on Spigot if you want stuff to be added)
    Yes you are allowed to integrate the API into your plugin! (Send me a link to your project so I can check it out ;))

    If you like this Resource, donate me a Coffee :) Paypal.me
    Thank for the donations made by N3kas, MrDienns, and evilLamer!
    N3kas, Leomixer17, girtacos and 11 others like this.

Recent Reviews

  1. Shmozo
    Shmozo
    5/5,
    Version: 1.5
    The perfect solution to my problem, I'm fortunate to have stumbled upon this plugin as I was preparing to create my own wrapper.
  2. Moderance
    Moderance
    5/5,
    Version: 1.4
    Working with 1.7.10, love it, thanks. I recommend this to anyone having problems with NBTTags as this is a really simple API to understand.
  3. MrDienns
    MrDienns
    5/5,
    Version: 1.4
    Works without a hitch. Very simple, extremely effective, and overall simply gets the job done. Does everything you expect it to do. Thanks for making this!
  4. Tabarnak00
    Tabarnak00
    5/5,
    Version: 1.4
    Really nice, easy and useful api. I am really glad I have found it, it is a much cleaner solution than storing data in the lore.
  5. ReBraLa
    ReBraLa
    5/5,
    Version: 1.4
    Using it for my CommandTools plugin, works great.. Creator is fast at responding to questions

    5/5 for dev
    5/5 for plugin!

    Keep going man!
  6. evilLamer
    evilLamer
    5/5,
    Version: 1.3.1
    AMAZING! Now I don't need to store informations in the lore of the item :D

    BTW are nbt tags persistents on server restarts?
    1. tr7zw
      Author's Response
      In my tests they were! On items on the ground, in chests or the inventory :)
  7. Kicjow
    Kicjow
    5/5,
    Version: 1.3.1
    Very nice plugin. I think I may have a use for it if I decide to switch to nbt tags for my plugin called Crazy Enchantments.
  8. Her3sy
    Her3sy
    5/5,
    Version: 1.3.1
    Great Plugin ! I love it, it's perfect !!!
    Can you update for minecraft spigot 1.11 ?
    Sorry for my bad english, I'm french...
    1. tr7zw
      Author's Response
      It works in 1.11 without changes ;)
  9. RobinMC
    RobinMC
    5/5,
    Version: 1.3.1
    Ignore the bad reviews, it works, even in the latest version. I no longer use this api because using NMS is way more flexible, but for the average person this is more than enough and works absolutely beautifully!
  10. Benjamint
    Benjamint
    1/5,
    Version: 1.2
    It doesn't work in version 1.10.2.
    I wasted hours on it just to find out that it doesn't work.
    Love the concept but it's useless to me if the data only stays saved inside the instance then gets lost through sessions.