NBT tag Help?

Discussion in 'Plugin Development' started by bobnixon1, Dec 13, 2012.

  1. Offline

    bobnixon1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    So I am making a plugin and i want to rename my items and set their lore. I have looked on NBT tags and changing them but I don't quite understand how they work. Using the code others have made, I cant make an Itemstack that has a item so when I use inv.setItem(0, ITEM); I cant have ITEM already be renamed. Can Someone please explain how this whole NBT tags thingy works and How I can directly rename an Itemstack?
  2. Offline

    Gravity BukkitDev Team Lead Moderator BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Moved to the correct section
  3. Offline

    fireblast709

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    You would need to use Craftbukkit (as library, instead of bukkit)
    Code:java
    1. CraftItemStack cis = new CraftItemStack(originalItemStack);
    2. cis.getHandle().c("new name");
    3. // then set the item to cis
    chasechocolate likes this.
  4. Offline

    bobnixon1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    umm this doesn't work . I can make my ItemStack into a CraftItemStack but getHandler() deosn't seem to be a thing you can do with cis.

    This post has been edited 1 time. It was last edited by c0mp Dec 14, 2012.
  5. Offline

    fireblast709

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    read the first line: you need Craftbukkit instead of Bukkit
  6. Offline

    bobnixon1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    sorry, but im new to this and i dont know whatt a craftbukkit library is I know what CraftItemStack is but I dont know how to edit NBT tags either

    This post has been edited 2 times. It was last edited by c0mp Dec 14, 2012.
  7. Offline

    fireblast709

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    the library would mean: instead of using the Bukkit jar in your projects, use Craftbukkit.jar (the server file)
  8. Offline

    bobnixon1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  9. Offline

    fireblast709

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    then what is the problem?
  10. Offline

    bobnixon1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    well, i don't know how to edit NBT tags
  11. Offline

    fireblast709

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    you don't have to. My code should be enough :3 (which internally edits the NBT tags, if you want to know)
  12. Offline

    bobnixon1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Your code desn't seem to work. the getHandle() thingy does not work. if the bukkit libray is called craftbukkit than i am not using the craftbukkit library

    This post has been edited 1 time. It was last edited by TnT Dec 14, 2012.
  13. Offline

    Jogy34

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    What he means by that is the actual .jar file you should be importing is the one that you use to run the actual server. You can find it here: http://dl.bukkit.org/downloads/craftbukkit/ The newest Beta build works fine for NBTTags.
  14. Offline

    bobnixon1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    thanks i got that but i don't know how to edit NBT tags. could you tell me?
  15. Offline

    Tirelessly

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  16. Offline

    gomeow BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    You don't need to edit them to change what their name is. The c(String) method handles it for you
  17. Offline

    bobnixon1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I have made the itemstack but when i do cis.getHandle().c("itemname"); it says identifier expected after getHandle() token. Help?

    This post has been edited 1 time. It was last edited by bobnixon1 Dec 18, 2012.
  18. Offline

    fireblast709

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Since the latest Bukkit dev build, this is no longer neccesary. Now you can use ItemMeta, which is implemented by Bukkit
    Code:java
    1. ItemStack is = new ItemStack(Material.GOLD_SWORD, 1);
    2. ItemMeta im = is.getItemMeta();
    3. im.setDisplayName("Demon Banisher");
    4. ArrayList<String> lore = new ArrayList<String>();
    5. lore.add("Banishes demons");
    6. lore.add("And cooks your pork");
    7. im.setLore(lore);
    8. is.setItemMeta(im);
  19. Offline

    bobnixon1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    i tried im.setDisplayName("myname"); but it is not working. the "." next to im has an error saying syntax error on token(s) misplaced construct(s) and "myname" has an error saying syntax error on "myname", delete this token.
  20. Offline

    bobnixon1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    do you know how to use the new ItemMeta in the new dev buil dof bukkit? it dens't seem to work for me
  21. Offline

    SnowGears

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Im trying this with the newest dev build and getting a "No Such Method Error" for is.getItemMeta();
    It compiles fine but on starting the server it spams with it...

    This post has been edited 1 time. It was last edited by Tooner101 Dec 18, 2012.
  22. Offline

    fireblast709

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @Tooner101 you probably should get the latest CB for it to work
    @bobnixon1 getItemMeta() returns a copy of the ItemMeta, so after you modified it, call setItemMeta(modified ItemMeta)
  23. Offline

    SnowGears

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I have the latest dev build and it still gives the error. Does it work for you?
  24. Offline

    tommycake50

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    You can do that now :D?

    This post has been edited 2 times. It was last edited by tommycake50 Dec 18, 2012.
  25. Offline

    fireblast709

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @tommycake50 yes
    @Tooner101 @bobnixon1 I could compile perfectly fine with the latest CB dev build, so it is added in the latest CB. Updating your server-used Craftbukkit should solve the problem

    This post has been edited 1 time. It was last edited by fireblast709 Dec 18, 2012.
  26. Offline

    SnowGears

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Ohhhh.... That must be it. I forgot to update the craftbukkit the server is running on. Thanks! I will try that when I get home.
  27. Offline

    bobnixon1

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    i did have that, buit i am doing all of this in a sperate class. do i need to have this code in something or add something in my main plugin class?

    This post has been edited 1 time. It was last edited by bobnixon1 Dec 22, 2012.

Share This Page