getting the max durability of an item

Discussion in 'Plugin Development' started by tommycake50, Sep 23, 2012.

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

    tommycake50

    well im creating a plugin to fix tools and this is the fixing code
    Code:
    player.getItemInHand().setDurability(player.getItemInHand().getType().getMaxDurability());
    which should set the item to maximum durability but instead it sets it to 1 hit break can anyone help out here?
     
  2. Offline

    LukeSFT

    try it with getMinDurability()
    Maybe this works
     
  3. Offline

    tommycake50

    or maybe short x = getMaxDurability() -getMaxDurability()+1 xD
     
  4. tommycake50 the durability goes from 0 (no damage) to getMaxDurability() (max. damage) IIRC.

    //EDIT: BTW: getMaxDurability() - getMaxDurability() = 0
     
    tommycake50 likes this.
  5. Offline

    tommycake50

    oh thanks so much for clarifying.
    EDIT: V10lator
    this doesnt work either tho
    Code:
    player.getItemInHand().setDurability((short)0);
     
  6. @tommycake40 Try calling player.updateInventory(); after that.
     
  7. Offline

    tommycake50

    V10lator that method is deprecated and btw wouldnt work anyway cos when i do that code it goes to 1 block left.
     
  8. tommycake50 This code is deprecated singe ages but still not remove cause it's needed in some cases. Yours could be one.
    What do you mean with "goes 1 block left"?

    //EDIT: What updateInventory() does is sending the whole server inventory to the client, so it updates it if the clients inventor is out of sync with the server (which should not happen but does. IIRC especially if you set durability).
     
  9. Offline

    tommycake50

    oh i see and i mean one use and it breaks
     
  10. tommycake50 Then I might have been wrong that 0 is no damage. But it either has to be 0 or getMaxDurability() - it can't be that both is max. damage.
     
  11. Offline

    MCForger

    Some thing I did is this.
    Code:
                short dura = inHand.getDurability();
                short matDura = inHand.getType().getMaxDurability();
                double d = matDura - dura;
                double perc = (d / matDura) * 100;
    This is how I got the percent back from the damaged item in the hand of the player.
     
Thread Status:
Not open for further replies.

Share This Page