Item Durability

Discussion in 'Development' started by JarguarLoveMC, Mar 25, 2020.

  1. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    What I want to do is repair a little bit of the pickaxe I'm holding after mining a diamond block

    PHP:
                if($block->getId() == 57) {
                    
    $hand->setDamage($hand->getDamage() + 1000);
                    
    $player->getInventory()->setItemInHand($hand);
    It doesn't work, and there is no error. Someone told me to use

    PHP:
    $item->getMaxDurability()
    but i dont want to repair it to max durability

    Thanks!
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,391
    GitHub:
    HimbeersaftLP
    To repair the pickaxe you need to make the damage number smaller, not larger (make sure you don't make it smaller than zero tho).

    btw You should usually use === and !== for future projects instead of == and !=, see here why: https://stackoverflow.com/a/40392064/11825425
     
    GamakCZ likes this.
  3. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49

    Well, i was testing the + first to see if the durability actually go down or not, but nope it didnt
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,391
    GitHub:
    HimbeersaftLP
    Because 1000 is to much I think
     
  5. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    i dont think that is the case, i even tried value of 100 or less
     
  6. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    152
    GitHub:
    ethaniccc
    Did you register your event listener?
     
  7. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    I did register everything
     
  8. wolfdale

    wolfdale Zombie Pigman

    Messages:
    502
    The server will set the item back regardless whether the item changed duing the event, you would have to delay the set item eg using ClosureTask
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.