Solved [1.9] Hide Durability Bar while keeping the texture?

Discussion in 'Spigot Plugin Development' started by ta1ha, May 31, 2016.

  1. Hello,
    I want to use the different textures for the same item that changes according to its durability. However, i want to hide its durability bar.
    I tried adding `Unbreakable` tag to the item. However, when an item is unbreakable, i think it does not use the durability texture anymore. It shows as its durability is maxed.

    The item without Unbreakable Tag (Don't mind the number under it):
    [​IMG]
    as you can see the shield is broken.
    With Unbreakable Tag:
    [​IMG]
    it is not broken anymore

    My Code:
    Code (Text):

            Item item = Item.getItem(id); // I have  a class `Item` that i use for custom items
            ItemStack is = new ItemStack(item.getItemStack().getType());
     
            //META
            ItemMeta meta = is.getItemMeta();
            meta.setDisplayName("Durability :" + item.getDurability());
            meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
            is.setItemMeta(meta);
            is.setDurability((short) item.getDurability());
     
            //TAG
            net.minecraft.server.v1_9_R1.ItemStack stack = CraftItemStack.asNMSCopy(is);
            NBTTagCompound tag = ( stack).hasTag() ? stack.getTag() : new NBTTagCompound();
            tag.setBoolean("Unbreakable", true);
            stack.setTag(tag);
     
            i = CraftItemStack.asBukkitCopy(stack);
    How can i do it?

    Edit: I tried adding `meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);`
     
    #1 ta1ha, May 31, 2016
    Last edited: May 31, 2016
  2. Try setting the int "HideFlags" to 63
     
    • Like Like x 1
  3. I believe that is `HIDE_UNBREAKABLE`.
    It hides the text.
    However, texture does not change :(
    [​IMG]
     
  4. No, 63 is all flags.
    Code (Text):
    {HideFlags:1-63} (1 = Enchantments, 2 = Attributes modifiers, 4 = Unbreakable, 8 = CanDestroy, 16 = CanPlaceOn, 32 = Others, such as potion effects)
     
    • Useful Useful x 1
  5. It is good to learn that. However it does not solve my problem.
     
  6. Well the texture should change as long as the durability is set.
     
    • Like Like x 1
  7. I agree. But it does not :/
     
  8. Perhaps you've done it the textures wrong.
     
    • Like Like x 1
  9. Then it would not work without the `unbreakable` tag. but it works without it.

    Am i missing something?
     
  10. Have you looked into the minecraft bug reports whether it is known to be broken?
     
    • Like Like x 1
  11. That thread you linked here said that you add the unbreakable tag and then you set the durability. I think that will work because other items like dye also have durability values but for the colors of dye
     
    • Like Like x 1
  12. You mean like this?
    Code (Text):

            Item item = Item.getItem(id); // I have  a class `Item` that i use for custom items
            ItemStack is = new ItemStack(item.getItemStack().getType());

            //META
            ItemMeta meta = is.getItemMeta();
            meta.setDisplayName("Durability :" + item.getDurability());
            meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
            is.setItemMeta(meta);

            //TAG
            net.minecraft.server.v1_9_R1.ItemStack stack = CraftItemStack.asNMSCopy(is);
            NBTTagCompound tag = ( stack).hasTag() ? stack.getTag() : new NBTTagCompound();
            tag.setBoolean("Unbreakable", true);
            stack.setTag(tag);

            i = CraftItemStack.asBukkitCopy(stack);
            i.setDurability((short) item.getDurability());
     
  13. Yes. I think a so. That's at least what that thread said. If that didn't work. Maybe try the method setData() instead of durability. It knight be named differently the setData () but I think that those methods basically do the same
     
    • Like Like x 1
  14. The thread was solved before the 1.9.4 update I think.
     
    • Like Like x 1
  15. I've done some investigation...

    Even after directly modifying the NMS item's "damage" field, when the item is given to the player, something resets the durability because it has the unbreaking tag. I know that the damage variable was modified because I printed the variable and it was definitely a number greater than 0

    Edit: The client is probably ignoring the damage field because I don't have a custom resourcepack, I was expecting the damage to show up in the F3 + H menu
     
    #16 Plo457, May 31, 2016
    Last edited: May 31, 2016
    • Like Like x 1
  16. oo talha bey bizi etiketlemeyin zaten ;(
     
    • Like Like x 1