Hello, so I've searched before but I couldn't find what I was looking for. so I'm making somewhat of grinding thing. What I do is PHP: $event->setCancelled(); To simply cancel the event when he breaks it and he receive the block. Although id like that it completly remove the block and replace it so the Pickaxe can actually lose durability. Any idea on how to?
PHP: public function onBreak(BlockBreakEvent $event) { $block = $event->getBlock(); $player = $event->getPlayer(); $level = $player->getLevel(); if ($block->getId() == Block::STONE) { $event->setDrops([]); $pos = $block->floor(); $level->setBlock($pos , new Stone()); } It doesnt set the block, do I need to get the pos of the broken block before?
By stealing drop logic from here. We can come up with this code that cancels the event (cuz replacing the block would still do blockupdates and stuff) and still gives drops: PHP: public function onBreak(BlockBreakEvent $event){ $block = $event->getBlock(); $player = $event->getPlayer(); $level = $player->getLevel(); $event->setCancelled(); if ($block->getId() == Block::STONE) { $drops = $event->getDrops(); if(!empty($drops)){ $dropPos = $block->add(0.5, 0.5, 0.5); foreach($drops as $drop){ if(!$drop->isNull()){ $level->dropItem($dropPos, $drop); } } } }}