How exactly does ItemStack.getDamage() work?

Discussion in 'Plugin Development' started by luciddream, Jan 22, 2011.

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


    I've been trying to get the percent that a tool is damaged, but getDamage() is giving me some trouble. It seems that it increases from 0 as the tool is used, but once it goes past 127 it flips to -128 and keeps increasing up to 127 again. I guess this makes sense given that getDamage() returns a byte, but how can I use that to figure out the percent an item has been damaged? For that matter, how can diamond tools have a durability of 1562 if the damage is stored as a byte?
  2. Offline


    It doesnt work properly atm and you havent been the only one to have issues with it. Docs say its a percentage, but currently its treated as hitpoints.
    I wrote a bug report on it, hopefully it should get fixed to properly work as either way.
  3. Offline

    Chuck Lieb

    If it's simply returning an improperly formatted or incorrect kind of variable, is it possible that we can format/correct it now while we wait for a fix later?

    Would this even be possible, considering that it could return the same number twice?
  4. Offline


    Currently the methods setDamage and getDamage return a byte. If it is meant to work like hitpoints then it needs to return a short. If its meant to be a percentage it needs an overhaul.
  5. Offline


    You can use reflection to access protected CraftItemStack.item.d, and get\set it manualy... but it dirty hack
Thread Status:
Not open for further replies.

Share This Page