Why is there no detailed information on manipulating NBT tags?

Discussion in 'Spigot Plugin Development' started by FlyingLlama, May 28, 2015.

Thread Status:
Not open for further replies.
  1. I have begun learning the bukkit/spigot API for the sole reason of making a simple plugin to modify nbt tags on items, and have run into a major issue:
    there are absolutely no tutorials, documentation, or any sort of information about how to do this, just threads with lots of people saying to use APIs from 1.4, or saying "why would you want to modify NBT?".

    Getting an item or entity nbt data as a 3-dimensional array, or even a string as it appears in vanilla command block usage, and setting a similar string back to the entity seems very basic, vanilla already includes commands that do this (/entitydata, /blockdata).

    For anyone wondering what NBT data tags are, they are the save data format for everything in minecraft not covered by the region files (player health, hunger, potion effects, movespeed, armor, inventory, item durability, enchantments, attributes (damage, health, speed, special mob parameters), chest and mob inventory, slime size, creeper fuse length, arrow velocity, horse jump height..

    I hope this turns into a megathread with useful information for the large number of people who seem to be seeking exactly this, since getting/setting these commands is very easy for new items in vanilla, but modifying single tags in existing items is impossible. Bukkit/Spigot api can fix this.

    Are there any functional APIs for 1.8+ for modifying entity/item nbt data in its entirety?
    Is a way to edit NTB data build into spigot already, well-hidden? i have found multiply references to tag.set, which is (as far as i can tell) not included in spigot javadocs anywhere.

    Edited to add the actual post, because the "spam" filter seems to have gone berserk.
    • Useful Useful x 1
  2. I have seen that already, and it is mostly people asking the same question i am asking here, with no working solutions.
    vanilla NBT tags are unrelated to bukkit metadata, from the documentation for metadata i have seen.

    I did find this: http://dev.bukkit.org/bukkit-plugins/powernbt/pages/commands/
    Close, but not very usable by other plugins.
    This is what should be build into spigot, imo. It is extremely important to any mapmaker, anyone making special games, dungeons, special mobs, ect.
    • Like Like x 1
  3. Personally, I don't see how it is important at all. Outside Spigot, maybe, but you can do just about anything with NBT tags using the API. What exactly do you need them for?
  4. I am aware it is possible, my question (and that of many people, guessing by the number of similar threads) is how to do this with the spigot API
  5. @FlyingLlama the Spigot API does not offer any solution with regards to direct NBT manipulation. You will have to depend on Spigot (the implementation) as well, so you can use the related net.minecraft.server classes.
    • Agree Agree x 1
  6. This is all fine, except there is no documentation for net.minecraft.server due to the DMCA takedown, and all related code samples i can find are from 2012 or 2013.

    ..Which leads back to the original issue.
  7. NBT manipulation is a very complex subject. First you've got the retrieval of the NBT data in the first place, then the actual value setting and making sure you're making a structure that Minecraft understands. You're not going to find a "complete" guide out there, however one of the best things you can do is look at source code for other plugins to see how they access and set NBT data. Another tool you might want to use is NBTExplorer to take a look at the NBT structure in a standard player file to get more of an understanding on the structure and how it all fits together.
  8. I am completely familiar with nbt structure already and use it heavily with vanilla commands. Considering how simple it is to set this data with vanilla commands, i am perplexed by how needlessly complex it seems to be with spigot.

    i have been messing around with this: http://www.spigotmc.org/threads/solved-modifying-item-attributes-how-nms-noob-1-8.44774/

    And am getting an error from:

    ItemStack i = new ItemStack(Material.IRON_SWORD);

    IRON_SWORD cannot be resolved or is not a field.

    Allowed Materials seem to be air, cactus, cake, ect, only some blocks and no items.
    I am unable to access the net.minecraft.server files or find any documentation for them, anywhere. is this an error on my end, or am i missing something? This code was meant for 1.8 R1, as far as i can tell, i am using 1.8 R2.

    Edit 2: I suck at java. was using net.minecraft.server Material instead of org.bukkit.

    Edit: IRON_SWORD shows up just fine as an entry in Material, in the spigot javadocs.
    public static final Material IRON_SWORD
    #9 FlyingLlama, May 31, 2015
    Last edited: May 31, 2015
  9. net.minecraft.server doesn't have any javadocs, becaise it is not an API, it is the implementation.
    So if you want to work with nbt tags you will have to figure it out yourself.
  10. Is there a similar documentation for net.minecraft.server that anyone has written?

    Some messing around produced:

    Player p = (Player)sender;
    PlayerInventory getinv = (p.getInventory());
    ItemStack itemget = new ItemStack(getinv.getItemInHand());
    net.minecraft.server.v1_8_R2.ItemStack stack = CraftItemStack.asNMSCopy(itemget);
    NBTTagCompound tag = stack.hasTag() ? stack.getTag() : new NBTTagCompound();
    tag.set("RepairCount", new NBTTagByte((byte)1));
    itemget = CraftItemStack.asBukkitCopy(stack);

    Seems to work fine, it gets the held item of the command sender, gets the nbt tag, inserts a new tag, and replaces the item.
    This is very simple. The lack of proper official or community documentation/guides for this is alarming.
  11. You would rather use NMS than a public NBT library? What in the world.
  12. Although that public NBT library looks really cool it's uses are limited to reading data on disk, not in memory. If you're wanting to manipulate NBT data inside of the game itself you're much better off using NMS. Each one has it's uses, one is for editing stored data, one is for editing data in memory.
  13. I would rather use what actually works without extreme limitations. NMS seems to.
  14. Now how long will it take before it gets DMCA'd? Note that you can easily get (some of) the source through BuildTools.
  15. Or you could get all of the source here: http://www.modcoderpack.com/website/content/mcp-910 It has different mappings, but it's still the same code.
    • Useful Useful x 1
Thread Status:
Not open for further replies.