Solved How to add the Unbreakable tag

Discussion in 'Plugin Help/Development/Requests' started by hii488, Jun 25, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    hii488

    I've been looking for several hours now, and everything I tried has been out of date or not working for some other reason.

    Can anyone give code (preferably with explanation) for how to add the Unbreakable nbt tag to an ItemStack? Also it would be very appreciated if you started from a Bukkit ItemStack and ended on one too.

    Thanks in advance :)
    (also sorry if I don't reply to any answers/questions as to why for a while, I haven't had much free time lately)
     
  2. Offline

    MnMaxon

    @hii488
    I am really bad at nbt, so I can't really help you with that. But there's a pretty easy way to do it, if you are using Spigot 1.8.
    Code:
    ItemStack is= new ItemStack(Material.DIAMOND_AXE);
    is.addUnsafeEnchantment(Enchantment.DURABILITY, 20);
    ItemMeta im = stone.getItemMeta();
    im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
    is.setItemMeta(im);
    If you're not using 1.8, I'm sorry that I'm not helpful.


    Also, am I allowed to talk about Spigot here, or can I only do that in the Bukkit Alternatives section?
     
  3. Offline

    Konato_K

    @MnMaxon You're just adding unbreaking 20, you can do that in any version with enchantments.
     
  4. Offline

    MnMaxon

    @Konato_K
    Yeah, but there's a hide enchantment thing, which I was pretty sure was only 1.8. I was guessing that's why you wanted the tag, because you didn't want the enchantment to show.
     
  5. Offline

    megamichiel

    I know exactly how-to :p. Here's a simple example:
    Code:
    net.minecraft.server.v1_8_R2.ItemStack stack = new net.minecraft.server.v1_8_R2.ItemStack(Item.getById(<someid>), [amount], [datavalue]); //Create the NMS Stack using it's constructor, OR:
    net.minecraft.server.v1_8_R2.ItemStack stack = CraftItemStack.asNMSCopy(someBukkitItemStack());
    NBTTagCompound tag = new NBTTagCompound(); //Create the NMS Stack's NBT (item data)
    tag.setBoolean("Unbreakable", true); //Set unbreakable value to true
    stack.setTag(tag); //Apply the tag to the item
    ItemStack is = CraftItemStack.asCraftMirror(stack); //Get the bukkit version of the stack
    doSomeStuffWithThisItemStack(is);
     
    Last edited: Jun 26, 2015
    hii488 likes this.
  6. Offline

    AdamQpzm

    @hii488 Well that all depends. What version of CraftBukkit are you using?
     
  7. Offline

    hii488

    Thank you so much, seriously, works a charm :D
     
  8. Offline

    timtower Moderator Moderator

    Moved to Bukkit alternatives
     
  9. Offline

    JuicyDev

Thread Status:
Not open for further replies.

Share This Page