Why can't I use setblock without setCancelled ? Source code : PHP: <?phpnamespace MinePlugin;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\block\Block;use pocketmine\event\block\BlockBreakEvent; class MinePlugin extends PluginBase implements Listener { public function onEnable(){ $this->getLogger()->info("MinePlugin has been loaded."); $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onBreak(BlockBreakEvent $e) { $block = $e->getBlock(); $e->setCancelled(true); $block->getLevel()->setBlock($block, Block::get(Block::STONE)); } }?> Please Tell me how to use setblock without setCancelled.
Please use code and php tags in order to make code more readable, you can do this by pressing the "+" button of the post field and then pressing "Code". You can also write it like this: [php]php code here[/php] or [code]config files here [/code]
The reason for you issue is because the block gets updated after your plugin handles the event. When the event is called, all registered handlers can handle the event. If the event is not cancelled after all the hadnlers have handled it, then it will set the block to air, so if you set that block to something else, it will immediately be replaced with air if the event is not cancelled
Okay, I understand. Then how can I use setblock without setcanclled? Some people recommend using "task" to me so I searched how to use task, but i couldn't understand. This is the code. Code: public function onEnable(){ $this->getScheduler()->scheduleDelayedTask(new class extends \pocketmine\scheduler\Task{ public function onRun(int $currentTick) : void{ } }, 20); //delay I could understand some of it, though i don't know how to use setblock at the code.
yes you can use a delayed task to set your block, but why? why don't you want to cancel the event when it's the needed action to do? do you have a specific reason? http://xyproblem.info