Hey everyone, So, I did a AsyncTask because there are many blocks to set on what I'm doing. When the task is executed, everything is okay, no error, but, nothing happens. I did some var_dump & echo and the code got executed correctly. I don't know if it need an onCompletation() or anything else, but if it's that, I want to know how to do/use it. PHP: class ResetTask extends AsyncTask{ //$placed contains Vector3(x, y, z), same for $breaked public function __construct(Level $levelId, bool $place, array $placed, bool $break, array $breaked){ $this->levelId = $levelId->getId(); $this->place = $place; $this->placed = $placed; $this->break = $break; $this->breaked = $breaked; } public function onRun(){ if($this->place == true){ foreach($this->placed as $p){ $this->getFromThreadStore("generation.level{$this->levelId}.manager")->setBlockIdAt($p->x, $p->y, $p->z, Block::SANDSTONE); $this->getFromThreadStore("generation.level{$this->levelId}.manager")->setBlockDataAt($p->x, $p->y, $p->z, 2); } } if($this->break == true){ foreach($this->breaked as $b){ $this->getFromThreadStore("generation.level{$this->levelId}.manager")->setBlockIdAt($b->x, $b->y, $b->z, Block::AIR); } } }} Thanks !
1. There are multiple async workers on a server. Did you execute this on all workers? https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/level/Level.php#L390 2. The data in the thread store generator do not get automatically exported to the level reference in the main thread. Eventually, someone has to copy the changes to the main thread. As far as I understand, you're trying to change blocks in an AsyncTask in the hope that it reduces lag. However, this is most likely not going to work. I am not sure where the lag of changing a lot of blocks comes from, but it should either be from editing the block data and block cache data or from creating packets to send to players, both of which are executed in the main thread, so setting blocks from other threads is not going to work anyway. On the other hand, you have to serialize blocks to pass to the worker thread, and someone has to unserialize the changes from the worker thread or otherwise import your changes somewhere, both of which will further increase the load.
I already told you. Nothing will happen if you don't fetch the results. Using my restaurant analogy again. The customer asks the waiter for a cup of water, but instead of taking it directly (this may take some time and stop the waiter from serving indeed), the waiter calls his son to come to the restaurant to hand him the cup of water. Yes, eventually the cup of water will come to the customer, but he has to make the phone call and take the cup of water from his son. Do you think this will be faster than directly fetching the cup of water? The problem you're having right now is that the water is ignoring the cup of water his son handed to him. But even if he does not ignore it, the service won't be any better, would it?