Hello! I have problem, because setBlock dont work why? Code: $e->getBlock()->getLevel()->setBlock(new Vector3($e->getBlock()->getX(), $e->getBlock()->getY(), $e->getBlock()->getZ()), Block::get(1, 0)); 0 errors, but dont work, why?
PHP: $e->getBlock()->getLevel()->setBlock(new Vector3($e->getBlock()->getX(), $e->getBlock()->getY(), $e->getBlock()->getZ()), Block::get(Block::STONE));
Now 0 errors, but setBlock dont work.. My Event: Code: public function onBlockBreakEvent(BlockBreakEvent $e) { if($e->getBlock()->getId() === 1) { $blockUnder = $e->getBlock()->getLevel()->getBlock(new Vector3($e->getBlock()->x, $e->getBlock()->y - 1, $e->getBlock()->z)); if($blockUnder->getId() === 121) { $e->getBlock()->getLevel()->setBlock(new Vector3($e->getBlock()->x, $e->getBlock()->y, $e->getBlock()->z), Block::get(Block::STONE)); $e->getPlayer()->sendMessage("Na dole jest kamien!"); } } } }
Yes, just setBlock dont work . All Class: Code: <?php namespace StoneGenerator; use pocketmine\plugin\PluginBase; use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\Listener; use pocketmine\math\Vector3; use pocketmine\block\Block; use pocketmine\level\Level; class Main extends PluginBase implements Listener { public function onEnable() { $this->saveDefaultConfig(); $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onDisable() { } public function onBlockBreakEvent(BlockBreakEvent $e) { if($e->getBlock()->getId() === 1) { $blockUnder = $e->getBlock()->getLevel()->getBlock(new Vector3($e->getBlock()->x, $e->getBlock()->y - 1, $e->getBlock()->z)); if($blockUnder->getId() === 121) { $e->getBlock()->getLevel()->setBlock(new Vector3($e->getBlock()->x, $e->getBlock()->y, $e->getBlock()->z), Block::get(Block::STONE)); $e->getPlayer()->sendMessage("Na dole jest kamien!"); } } } }
Cancel the event. PocketMine will change the block to air AFTER the event is called. So even if the plugin changed the block to stone, PocketMine will still change it to air afterwards. To prevent this behaviour, simply cancel the event.
I must use $e->setCancelled();? If yes it stop event and 0 drop cobblestone etc... And if I want add task later?
Yes, you can schedule a delayed task. But that's not the best solution. In this case, you can just foreach the result of getDrops and drop the items one by one.