Solved Damage to the item in hand?

Discussion in 'Plugin Development' started by isleepzzz, Dec 10, 2012.

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

    isleepzzz

    what is the code to put damage or make the health lower in an item such as a sword or etc.
     
  2. Offline

    tommycake50

    itemstack.setDurability();
     
  3. Offline

    isleepzzz

    is there like a nice big list or something? were do u get these codes?
     
  4. Offline

    tommycake50

  5. Offline

    RainoBoy97

    Player player = event.getPlayer();
    ItemStack item = player.getItemInHand();
    item.setDurability();
     
  6. Offline

    isleepzzz

    but if i do:
    itemstack.setDurability();
    that wudnt make damage to the tool wud it? cuz were am i saying take damage to the tool.
    it seems lyk tht code wud only set the tool's health value.
     
  7. Offline

    fireblast709

    the 'set' prefix of the method usually refers to something called a setter method in programming, it sets a value. So if you want to lower the damage you need to get the damage (now guess how you would do that), substract an amount, and set it to that new value
     
  8. Offline

    tommycake50

    item.setDurability(item.getDurability() - 1);
    EDIT: lol fire beat me to it
     
  9. Offline

    isleepzzz

    haha thnx guys, i understand now:)
     
  10. Offline

    Barinade

    Isn't durability effed up where the 'max durability' is actually the lowest?

    In other words, durability is the damage it's gotten

    So subtracting one from it's current durability would actually repair it by 1?

    I may be wrong there, but I'm pretty sure that's how it was the last time I messed with it.
     
  11. Offline

    isleepzzz

    I did not comprehend that?:/

    But also,
    Code:
    item.setDurability(item.getDurability() - 1);
    is giving me an error on the "setDurability"
    Eclipse is saying:
     
  12. Offline

    Barinade

    Basically what I was saying is durability zero means the items is completely repaired, untouched, full health, undamaged. Not used.

    In basic terms, if you subtract from its durability, you are actually repairing it.
    Imagine that durability is just "damage it has taken" and once it reaches a certain damage level (max durability) then it breaks.

    Also, try this

    item.setDurability((short) item.getDurability() - 1);

    Or, if you listened to what I said and want to damage the item

    item.setDurability((short) item.getDurability() + 1);
     
    TheTinySpider likes this.
  13. Offline

    isleepzzz

    I did exactly:
    Code:
    i.setDurability((short) i.getDurability() + 1);
    
    and still the same error its saying:/



    MY i is:
    ItemStack i = p.getItemInHand();
     
  14. Offline

    Barinade

    There should be no errors. What does the error say?
     
  15. Offline

    isleepzzz

    Same thing above:
     
  16. Offline

    Barinade

    Save your code, that is wrong.

    Edit:
    ItemStack i2 = e.getPlayer().getItemInHand();
    i2.setDurability((short) (i2.getDurability() - 1));
    This gives me no error.

    Edit2: There's the problem, you have
    (short) i.getDurability() - 1
    change to
    (short) (i.getDurability() - 1)

    That was my bad btw, was writing outside of IDE
     
  17. Offline

    isleepzzz

    u got teamviewer? i can show u rite now. cuuz i need help:p
     
  18. Offline

    Barinade

    Yeah, go for it. PM me info.
     
  19. Offline

    isleepzzz

    :DDDDDDD EXCELLENT!
    You are by far the best:)

    Except, how would i make it say, if the item has Durability > 0 then destory the item (like it broke)
    because it just goes all the way down, and doesnt break haha:p

    :DDDDDDD EXCELLENT!
    You are by far the best:)

    Except, how would i make it say, if the item has Durability > 0 then destory the item (like it broke)
    because it just goes all the way down, and doesnt break haha:p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  20. Offline

    Barinade

    if (i.getMaxDurability() == i.getDurability()) {
    i.setType(Material.AIR);
    }
     
  21. Offline

    bossomeness

    any idea how i set the damage on an item? like how much damage a sword can do?
     
Thread Status:
Not open for further replies.

Share This Page