Hello, I am trying to fix my plugin but this error "RuntimeException: "Recursive event call detected (reached max depth of 50 calls)" (EXCEPTION) in "src/pocketmine/event/Event" at line 87" keep popping mind helping me fix it. I think it means there are too many blocks i dont know lol, also mind telling me what is $step in https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/level/Level.php#L1692 Here is my try. PHP: public function onBreak(BlockBreakEvent $e): void{ $player = $e->getPlayer(); $block = $e->getBlock(); $inv = $player->getInventory()->getItemInHand(); if($this->check($player)){ $en = $this->getEnchant($player); $s = $block->getSide(Facing::SOUTH); $player->getLevel()->useBreakOn($s, $inv, $player); } } I am trying to break block like this xox xox xxx O is the broken blocks, I know I am suppose to use getDirection which comes later after I am done with this testing lol or Facing::ALL or smth I forgot.
Level->useBreakOn() calls BlockBreakEvent so your function keeps looping forever, you might want to set a threshold or find another way
I am trying to make a plugin, which mines 4 by 4 but I keep getting this error + I knew it was looping bc I checked with var dump but idk how to stop it
Well since Code: useBreakOn() calls block break event you will have to use different event for example on command or on placing a specific block
You can use a task to do that, also you should check if the block is breakable, and set a limit if not it will go on forever PHP: public function onBreak(BlockBreakEvent $e): void{ $player = $e->getPlayer(); $block = $e->getBlock(); $inv = $player->getInventory()->getItemInHand(); if($this->check($player)){ $en = $this->getEnchant($player); $s = $block->getSide(Facing::SOUTH); if($s->isBreakable($inv))//optionally you can set a limit $this->delayedBlockBreak($s, $inv, $player); } }function delayedBlockBreak(Vector3 $block,Item $item = null,Player $player = null){$this->getScheduler()->scheduleDelayedTask(new class($block,$item,$player) extends Task{private $block,$item,$player;function __construct(Vector3 $block,Item $item = null,Player $player = null){$this->block = $block;$this->item = $item;$this->player = $player;}function onRun(int $currentTick){if(!$this->block->getLevel()->isClosed() && (!$this->player || $this->player->isOnline())$this->block->getLevel()->useBreakOn($this->block,$this->item,$this->player);}},1);}
Protip: use ClosureTask to improve conciseness and reduce boilerplate code. It was added in API 3.4.0