is there a way to get the "health bar" for a item.

Discussion in 'Plugin Development' started by kasszz, May 3, 2013.

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

    kasszz

    I'm making a custom item and everything is working, i'm destoring it when I used it 30 times.
    but is there a way to have that health bar for a custom item?

    code:
    Code:
                                player.getItemInHand().setDurability((short) (player.getItemInHand().getDurability() + 1));
                                System.out.print("var = " + player.getItemInHand().getDurability());
                                if(player.getItemInHand().getDurability() == 30){
                                    player.setItemInHand(null);
                                    player.playSound(player.getLocation(), Sound.ITEM_BREAK, 10, 1);
     
  2. Offline

    SunsetWarrior

    no i think that healthbar only is for items that have the healthbar already.
     
  3. You need to get the maximum usage for the original item you are using and then set it's percent usage. Let's say the item has a max durability of 300, then you would add 10 each time you use this:

    Code:java
    1. item.setDurability(item.getDurability() + (maxDurability / 30));
     
  4. Offline

    kasszz

    And if the item has no durability, I'm using a stick xD
     
  5. Offline

    SpaceManiac

    If the item already has no 'health bar' you can't make it show one.
     
  6. Offline

    kasszz

    that is stupid :( are you 100% sure about that ?

    Isn't there a way to make it with itemMeta or something ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  7. Offline

    Rprrr

    kasszz
    It's not stupid, it's the way it is. You can't add pink unicorns to the game either.. although I wóuld enjoy them.
     
    devilquak likes this.
  8. Offline

    kasszz

    Rprrr
    That would be awesome xD but okay, then I need to thing of another way to do this, thank for the information/help :)
    Could you give me an example when I use for an item that has duration or is it really as simple as:
    item.setDurability(item.getDurability()+(maxDurability /30));
     
Thread Status:
Not open for further replies.

Share This Page