PHP: $tools = 0;foreach($player->getInventory()->getContents() as $item) if($item instanceof \pocketmine\item\Tool) $tools++;#do smth with $tools
This does not solve the problem. OP asked to get the number of all the tools in the inventory, not to get the count of each item. Your suggestion loops through each item in the inventory and gets it's count regardless of item type. The solution by wolfdale is the correct one, as it counts only tools.
PHP: $opt = 0;/** @var Player $player */foreach ($player->getInventory()->getContents() as $item) { if ($item instanceof Tool) $opt += $item->getCount();}//return $opt;
In PE yes, in PocketMine, no. The server handles the inventory, unless you overwrite the item and increase the max stack size you will never be able to have multiple tools, even of the same type, in one slot.