1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Unbreakable item

Discussion in 'Help' started by SkySeven, Oct 16, 2017.

  1. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    Because Item::get() returns an instance of an Item, not an instance of the Durable class, where the setUnbreakable function is housed.
     
    jasonwynn10 and SkySeven like this.
  2. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    How to do ?
     
  3. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    PHP:
    $item Item::get(Item::WOODEN_SHOVEL);
    if(
    $item instanceof Durable) {
        
    $item->setUnbreakable();
        
    $player->getInventory()->setItem(0$item);
    }
     
    jasonwynn10 and SkySeven like this.
  4. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    But $item is always an item no ?
     
  5. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    You're complicating it for yourself. Just know that Item::get() returns an Item, but by testing if it's also an instance of the Durable class, you get the methods that the Durable class has(i.e. the setUnbreakable() function)

    But the parent class of Durable is Item, so you'll have access to those methods too.
     
    jasonwynn10 and SkySeven like this.
  6. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    PHP:
    if($item instanceof Durable){
           
    $item->setUnbreakable();   
    }
    it's still not work for me :/
     
  7. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    Did you use the Durable class?

    i.e.
    PHP:
    use pocketmine\item\Durable;
     
  8. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    Yes, normal
     
  9. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
  10. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
  11. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    I'm not sure what exactly it's for, but try setting it unbreakable *before* giving it to the player.
     
    jasonwynn10 and SkySeven like this.
  12. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    Oh ok, thx I will try this later :)
     
  13. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    thx, It's work x)
     
  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.