Hello, This piece of code isn't working: PHP: $sender->getInventory()->getItemInHand()->setDamage(0); $sender->sendMessage("Item damage was set to 0 (tool fixed)"; It doesn't set the sender's hand item damage to 0... What am I doing wrong?
Try this: Code: $sender->getInventory()->setItemInHand($sender->getInventory()->getItemInHand()->setDamage(0)); $sender->sendMessage("Item damage was set to 0 (tool fixed)";
Argument 1 passed to pocketmine\inventory\PlayerInventory::setItemInHand() must be an instance of pocketmine\item\Item, null given, called in etc/etc.
PHP: $item = $sender->getInventory()->getItemInHand();$item->setDamage(0);$sender->getInventory()->setItemInHand($item);$sender->sendMessage("Item damage was set to 0 (tool fixed)";
When modifying damage values you may need to resend the inventory contents to the player for the changes to become visible. $player->getInventory()->sendContents($player);
Thank you , it worked @ImagicalGamer thanks for the explanation In brief words @MCPEPIG thank for the code @ImagicalGamer thank for the explanation