generator: prevent access to chunks that don't exist on this thread

the generator shouldn't be creating chunks that it wasn't given.
This commit is contained in:
Dylan K. Taylor 2019-07-08 18:29:19 +01:00
parent fe3a4baddb
commit 9ef5f9518c
2 changed files with 39 additions and 2 deletions

View File

@ -0,0 +1,38 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\world\generator;
use pocketmine\world\format\Chunk;
use pocketmine\world\SimpleChunkManager;
use pocketmine\world\World;
class GeneratorChunkManager extends SimpleChunkManager{
public function getChunk(int $chunkX, int $chunkZ, bool $create = false) : ?Chunk{
if(!isset($this->chunks[World::chunkHash($chunkX, $chunkZ)])){
throw new \InvalidArgumentException("Chunk does not exist");
}
return parent::getChunk($chunkX, $chunkZ, $create);
}
}

View File

@ -26,7 +26,6 @@ namespace pocketmine\world\generator;
use pocketmine\block\BlockFactory;
use pocketmine\scheduler\AsyncTask;
use pocketmine\world\biome\Biome;
use pocketmine\world\SimpleChunkManager;
use pocketmine\world\World;
use function serialize;
use function unserialize;
@ -50,7 +49,7 @@ class GeneratorRegisterTask extends AsyncTask{
public function onRun() : void{
BlockFactory::init();
Biome::init();
$manager = new SimpleChunkManager($this->worldHeight);
$manager = new GeneratorChunkManager($this->worldHeight);
$this->worker->saveToThreadStore("generation.world{$this->worldId}.manager", $manager);
/**