Howdy! I've been trying to place blocks through an async task and have had no success, I've always had it crash with "setBlockIdAt" on null. Code for placing blocks: PHP: $store = $this->getFromThreadStore("generator.level{$this->levelId}.manager");for($minX = -$this->border; $minX <= $this->border; $minX++){ for($y = 50; $y <= 100; $y++){ $store->setBlockIdAt($minX, $y, $this->border, Block::BEDROCK); }} Code for calling the task: PHP: $level = $this->plugin->getServer()->getDefaultLevel();$this->plugin->getServer()->getAsyncPool()->submitTask(new PlaceBlockTask($border, $level->getId()));
you can serialize the chunks you want to change, then deserialize it in the task, then you can loop the chunks to your suit PHP: /** @var Chunk $chunk */$serializedChunk = $chunk->fastSerialize();/** of course you can make this an array and loop it in the task to change more chunks$this->plugin->getServer()->getAsyncPool()->submitTask(new PlaceBlockTask($border, $serializedChunk)); then in the task you can do PHP: $chunk = Chunk::fastDeserialize($this->serializedChunk);/** There are only 16x16x256 blocks in a chunk */for($xx = 0; $xx < 16; $xx++){ for($zz = 0; $zz < 16; $zz++){ for($yy = 50; $y <= 100; $yy++){ //$chunk->setBlock(); blah blah.. } }}
You need to serialize the chunk again after you are done setting the blocks in onRun, then $this->setResult($serializedChunk); Then onCompletion you unserialize the chunk(getResult) and setChunk on your level