I want to remove a set of blocks in a cuboidal region. And at the same time, instead of spawning ItemEntity, I want to move them directly to the player's inventory. Here's my code: PHP: //$ev = BlockBreakEvent //$lev = Level //$player = $ev->getPlayer(); $radius = 2; $xo = $block->x - $radius; $xp = $block->x + $radius; $yo = $block->y - $radius; $yp = $block->y + $radius; $zo = $block->z - $radius; $zp = $block->z + $radius; $drops = []; for ($x = $xo; $x <= $xp; $x++) { for ($y = $yo; $y <= $yp; $y++) { for ($z = $zo; $z <= $zp; $z++) { if ($lev->getBlockIdAt($x, $y, $z) !== 7) { if (($b = $lev->getBlock(new Vector3($x, $y, $z)))->isSolid()) { $lev->setBlock($b, new Air()); $drops[] = $b->getDrops($item); } } } } } if (!empty($drops)) { foreach ($drops as $drop) { foreach ($drop as $ite) { $player->getInventory()->addItem(Item::get($ite[0], $ite[1], $ite[2])); } } } $ev->setDrops([]); Average Time:0.0053859272003174 Is there an easier way to do this? Performance on priority.
This is already the best method if you want to do it through the "normal" and "stable" way. You can of course also refer to MineReset by @falk, which unloads the chunks, processes and writes them asynchronously and loads them back in main thread and resend to clients. This is quite complicated, and I don't recommend it for anyone not completely familiar with PocketMine chunk loading and sending mechanism. You may also want to edit a limited amount of blocks per tick. You can refer to WorldEditArt for how it can be done. It is also possible to edit it like how it is done in the world generator, using setBlockId() etc., and then use sendBlocks(), but I don't think it is effective in updating client reference and may not really have great performance boost. After all, the main lag comes from sending the data to clients, not from editing the blocks server-side.
Adding to what @SOFe said. I wrote a blog post about what I did with MineReset and different ways to set block areas. It basically goes through exactly what @SOFe said, but also has some code. http://blog.falkirks.com/setting-huge-areas-of-blocks/
You are here too, OMG! GG on the MineReset Asynchronous task. I am still trying to understand that and I hope the blog makes it easier