How can i make this drops Random? PHP: public function onBreak(BlockBreakEvent $event) { $player = $event->getPlayer(); $block = $event->getBlock(); if ($block->getId() === Block::SPONGE) { $drops = array(); $drops[] = new Item(276, 0, 1); $drops[] = new Item(277, 0, 1); $drops[] = new Item(278, 0, 1); $drops[] = new Item(4, 0, 16); $event->setDrops($drops);
hello, my code is not short but maybe it can help you ! PHP: public function onBreak(BlockBreakEvent $event) { if($event->getBlock()->getId() == 19) { $player = $event->getPlayer(); $rdm = rand(1, 7); $player->getLevel()->addSound((new \pocketmine\level\sound\AnvilFallSound($player)), [$player]); $this->dropItems($event, $player, $rdm); } } public function dropItems($event, $player, $rdm){ switch($rdm){ case "1": $drop1 = array(Item::get(267, 0, 1)); $event->setDrops($drop1); break; case "2": $drop1 = array(Item::get(261,0, 1),Item::get(262,0,16)); $event->setDrops($drop1); break; case "3": $drop1 = array(Item::get(322,0,6),Item::get(272,0,1)); $event->setDrops($drop1); break; case "4": $drop1 = array(Item::get(307,0,1),Item::get(208,0,1)); $event->setDrops($drop1); break; case "5": $drop1 = array(Item::get(306,0,1),Item::get(209, 0,1)); $event->setDrops($drop1); break; case "6": $drop1 = array(Item::get(311,0,1)); $event->setDrops($drop1); break; case "7": $drop1 = array(Item::get(332,0,8)); $event->setDrops($drop1); break; default: break; } }