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

Help me to change the durability of an item or an armor

Discussion in 'Help' started by Noxi69, Jun 10, 2020.

  1. Noxi69

    Noxi69 Spider

    Messages:
    10
    So i want to change the durability of an item and an armor but it dont work can you help me ?

    I try to recode the armor

    public function getDefensePoints() : int
    {
    return 3;
    }

    public function getMaxDurability() : int
    {
    return 1300;
    }

    this dont work and for the item


    public function __construct($meta = 0, $count = 1){
    parent::__construct(285, 0, "Gold Pickaxe");

    }

    public function getMaxDurability(): int
    {

    return 1000;
    }

    public function getMaxStackSize(): int{
    return 1;
    }

    public function onDestroyBlock(Block $block): bool
    {
    var_dump($this->getDamage());

    $this->applyDamage(mt_rand(1,2));
    return true;
    }

    This work but the durability bar is bug so have you got any solution to up the durability ?
    Thanks for help me
     
  2. Joao Nunes

    Joao Nunes Spider Jockey

    Messages:
    30
    GitHub:
    joaonunes12
    PHP:
    public function onBreak(BlockBreakEvent $event) : void{

    $item $event->getPlayer()->getInventory()->getItemInHand();

    $event->getPlayer()->getInventory()->setItemInHand($item->setDamage(rand(1,2)));

    }
     
  3. Noxi69

    Noxi69 Spider

    Messages:
    10
    and for armor ? the same but with the event EntityDamageByEntityEvent ?
     
  4. Joao Nunes

    Joao Nunes Spider Jockey

    Messages:
    30
    GitHub:
    joaonunes12
    PHP:
    public function onDamage(EntityDamageEvent $event) : void{

    $player $event->getEntity();

    if(!
    $player instanceof Player){
    return;
    }

    $player->getArmorInventory()->setHelmet($player->getArmorInventory()->getHelmet()->setDamage($player->getArmorInventory()->getHelmet()->getDamage()++));

    $player->getArmorInventory()->setChestplate($player->getArmorInventory()->getChestplate()->setDamage($player->getArmorInventory()->getChestplate()->getDamage()++));

    $player->getArmorInventory()->setLeggings($player->getArmorInventory()->getLeggings()->setDamage($player->getArmorInventory()->getLeggings()->getDamage()++));

    $player->getArmorInventory()->setBoots($player->getArmorInventory()->getBoots()->setDamage($player->getArmorInventory()->getBoots()->getDamage()++));

    }
     
  5. Noxi69

    Noxi69 Spider

    Messages:
    10
    thanks
     
  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.