mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
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:
parent
fe3a4baddb
commit
9ef5f9518c
38
src/pocketmine/world/generator/GeneratorChunkManager.php
Normal file
38
src/pocketmine/world/generator/GeneratorChunkManager.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,6 @@ namespace pocketmine\world\generator;
|
|||||||
use pocketmine\block\BlockFactory;
|
use pocketmine\block\BlockFactory;
|
||||||
use pocketmine\scheduler\AsyncTask;
|
use pocketmine\scheduler\AsyncTask;
|
||||||
use pocketmine\world\biome\Biome;
|
use pocketmine\world\biome\Biome;
|
||||||
use pocketmine\world\SimpleChunkManager;
|
|
||||||
use pocketmine\world\World;
|
use pocketmine\world\World;
|
||||||
use function serialize;
|
use function serialize;
|
||||||
use function unserialize;
|
use function unserialize;
|
||||||
@ -50,7 +49,7 @@ class GeneratorRegisterTask extends AsyncTask{
|
|||||||
public function onRun() : void{
|
public function onRun() : void{
|
||||||
BlockFactory::init();
|
BlockFactory::init();
|
||||||
Biome::init();
|
Biome::init();
|
||||||
$manager = new SimpleChunkManager($this->worldHeight);
|
$manager = new GeneratorChunkManager($this->worldHeight);
|
||||||
$this->worker->saveToThreadStore("generation.world{$this->worldId}.manager", $manager);
|
$this->worker->saveToThreadStore("generation.world{$this->worldId}.manager", $manager);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user