mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +00:00
Chunk: make all parameters of __construct() mandatory and non-nullable
having the constructor fill in defaults for these invariably causes bugs.
This commit is contained in:
parent
d53347454b
commit
baba25953f
@ -68,7 +68,7 @@ class Chunk{
|
|||||||
/**
|
/**
|
||||||
* @param SubChunk[] $subChunks
|
* @param SubChunk[] $subChunks
|
||||||
*/
|
*/
|
||||||
public function __construct(array $subChunks = [], ?BiomeArray $biomeIds = null, bool $terrainPopulated = false){
|
public function __construct(array $subChunks, BiomeArray $biomeIds, bool $terrainPopulated){
|
||||||
$this->subChunks = new \SplFixedArray(Chunk::MAX_SUBCHUNKS);
|
$this->subChunks = new \SplFixedArray(Chunk::MAX_SUBCHUNKS);
|
||||||
|
|
||||||
foreach($this->subChunks as $y => $null){
|
foreach($this->subChunks as $y => $null){
|
||||||
@ -77,7 +77,7 @@ class Chunk{
|
|||||||
|
|
||||||
$val = ($this->subChunks->getSize() * SubChunk::EDGE_LENGTH);
|
$val = ($this->subChunks->getSize() * SubChunk::EDGE_LENGTH);
|
||||||
$this->heightMap = HeightArray::fill($val); //TODO: what about lazily initializing this?
|
$this->heightMap = HeightArray::fill($val); //TODO: what about lazily initializing this?
|
||||||
$this->biomeIds = $biomeIds ?? BiomeArray::fill(BiomeIds::OCEAN);
|
$this->biomeIds = $biomeIds;
|
||||||
|
|
||||||
$this->terrainPopulated = $terrainPopulated;
|
$this->terrainPopulated = $terrainPopulated;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\world\format\io\leveldb;
|
|||||||
|
|
||||||
use pocketmine\block\Block;
|
use pocketmine\block\Block;
|
||||||
use pocketmine\block\BlockLegacyIds;
|
use pocketmine\block\BlockLegacyIds;
|
||||||
|
use pocketmine\data\bedrock\BiomeIds;
|
||||||
use pocketmine\data\bedrock\LegacyBlockIdToStringIdMap;
|
use pocketmine\data\bedrock\LegacyBlockIdToStringIdMap;
|
||||||
use pocketmine\nbt\LittleEndianNbtSerializer;
|
use pocketmine\nbt\LittleEndianNbtSerializer;
|
||||||
use pocketmine\nbt\NbtDataException;
|
use pocketmine\nbt\NbtDataException;
|
||||||
@ -416,7 +417,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
|
|||||||
|
|
||||||
$chunk = new Chunk(
|
$chunk = new Chunk(
|
||||||
$subChunks,
|
$subChunks,
|
||||||
$biomeArray,
|
$biomeArray ?? BiomeArray::fill(BiomeIds::OCEAN), //TODO: maybe missing biomes should be an error?
|
||||||
$terrainPopulated
|
$terrainPopulated
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\world\format\io\region;
|
namespace pocketmine\world\format\io\region;
|
||||||
|
|
||||||
|
use pocketmine\data\bedrock\BiomeIds;
|
||||||
use pocketmine\nbt\BigEndianNbtSerializer;
|
use pocketmine\nbt\BigEndianNbtSerializer;
|
||||||
use pocketmine\nbt\NbtDataException;
|
use pocketmine\nbt\NbtDataException;
|
||||||
use pocketmine\nbt\tag\ByteArrayTag;
|
use pocketmine\nbt\tag\ByteArrayTag;
|
||||||
@ -86,6 +87,8 @@ trait LegacyAnvilChunkTrait{
|
|||||||
$biomeArray = $makeBiomeArray(ChunkUtils::convertBiomeColors($biomeColorsTag->getValue())); //Convert back to original format
|
$biomeArray = $makeBiomeArray(ChunkUtils::convertBiomeColors($biomeColorsTag->getValue())); //Convert back to original format
|
||||||
}elseif(($biomesTag = $chunk->getTag("Biomes")) instanceof ByteArrayTag){
|
}elseif(($biomesTag = $chunk->getTag("Biomes")) instanceof ByteArrayTag){
|
||||||
$biomeArray = $makeBiomeArray($biomesTag->getValue());
|
$biomeArray = $makeBiomeArray($biomesTag->getValue());
|
||||||
|
}else{
|
||||||
|
$biomeArray = BiomeArray::fill(BiomeIds::OCEAN);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ChunkData(
|
return new ChunkData(
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\world\format\io\region;
|
|||||||
|
|
||||||
use pocketmine\block\Block;
|
use pocketmine\block\Block;
|
||||||
use pocketmine\block\BlockLegacyIds;
|
use pocketmine\block\BlockLegacyIds;
|
||||||
|
use pocketmine\data\bedrock\BiomeIds;
|
||||||
use pocketmine\nbt\BigEndianNbtSerializer;
|
use pocketmine\nbt\BigEndianNbtSerializer;
|
||||||
use pocketmine\nbt\NbtDataException;
|
use pocketmine\nbt\NbtDataException;
|
||||||
use pocketmine\nbt\tag\ByteArrayTag;
|
use pocketmine\nbt\tag\ByteArrayTag;
|
||||||
@ -80,6 +81,8 @@ class McRegion extends RegionWorldProvider{
|
|||||||
$biomeIds = $makeBiomeArray(ChunkUtils::convertBiomeColors($biomeColorsTag->getValue())); //Convert back to original format
|
$biomeIds = $makeBiomeArray(ChunkUtils::convertBiomeColors($biomeColorsTag->getValue())); //Convert back to original format
|
||||||
}elseif(($biomesTag = $chunk->getTag("Biomes")) instanceof ByteArrayTag){
|
}elseif(($biomesTag = $chunk->getTag("Biomes")) instanceof ByteArrayTag){
|
||||||
$biomeIds = $makeBiomeArray($biomesTag->getValue());
|
$biomeIds = $makeBiomeArray($biomesTag->getValue());
|
||||||
|
}else{
|
||||||
|
$biomeIds = BiomeArray::fill(BiomeIds::OCEAN);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ChunkData(
|
return new ChunkData(
|
||||||
|
@ -69,7 +69,7 @@ class Flat extends Generator{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function generateBaseChunk() : void{
|
protected function generateBaseChunk() : void{
|
||||||
$this->chunk = new Chunk([], BiomeArray::fill($this->options->getBiomeId()));
|
$this->chunk = new Chunk([], BiomeArray::fill($this->options->getBiomeId()), false);
|
||||||
|
|
||||||
$structure = $this->options->getStructure();
|
$structure = $this->options->getStructure();
|
||||||
$count = count($structure);
|
$count = count($structure);
|
||||||
|
@ -23,8 +23,10 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\world\generator;
|
namespace pocketmine\world\generator;
|
||||||
|
|
||||||
|
use pocketmine\data\bedrock\BiomeIds;
|
||||||
use pocketmine\scheduler\AsyncTask;
|
use pocketmine\scheduler\AsyncTask;
|
||||||
use pocketmine\utils\AssumptionFailedError;
|
use pocketmine\utils\AssumptionFailedError;
|
||||||
|
use pocketmine\world\format\BiomeArray;
|
||||||
use pocketmine\world\format\Chunk;
|
use pocketmine\world\format\Chunk;
|
||||||
use pocketmine\world\format\io\FastChunkSerializer;
|
use pocketmine\world\format\io\FastChunkSerializer;
|
||||||
use pocketmine\world\SimpleChunkManager;
|
use pocketmine\world\SimpleChunkManager;
|
||||||
@ -127,7 +129,7 @@ class PopulationTask extends AsyncTask{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static function setOrGenerateChunk(SimpleChunkManager $manager, Generator $generator, int $chunkX, int $chunkZ, ?Chunk $chunk) : Chunk{
|
private static function setOrGenerateChunk(SimpleChunkManager $manager, Generator $generator, int $chunkX, int $chunkZ, ?Chunk $chunk) : Chunk{
|
||||||
$manager->setChunk($chunkX, $chunkZ, $chunk ?? new Chunk());
|
$manager->setChunk($chunkX, $chunkZ, $chunk ?? new Chunk([], BiomeArray::fill(BiomeIds::OCEAN), false));
|
||||||
if($chunk === null){
|
if($chunk === null){
|
||||||
$generator->generateChunk($manager, $chunkX, $chunkZ);
|
$generator->generateChunk($manager, $chunkX, $chunkZ);
|
||||||
$chunk = $manager->getChunk($chunkX, $chunkZ);
|
$chunk = $manager->getChunk($chunkX, $chunkZ);
|
||||||
|
@ -24,11 +24,12 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\world\format;
|
namespace pocketmine\world\format;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use pocketmine\data\bedrock\BiomeIds;
|
||||||
|
|
||||||
class ChunkTest extends TestCase{
|
class ChunkTest extends TestCase{
|
||||||
|
|
||||||
public function testClone() : void{
|
public function testClone() : void{
|
||||||
$chunk = new Chunk();
|
$chunk = new Chunk([], BiomeArray::fill(BiomeIds::OCEAN), false);
|
||||||
$chunk->setFullBlock(0, 0, 0, 1);
|
$chunk->setFullBlock(0, 0, 0, 1);
|
||||||
$chunk->setBiomeId(0, 0, 1);
|
$chunk->setBiomeId(0, 0, 1);
|
||||||
$chunk->setHeightMap(0, 0, 1);
|
$chunk->setHeightMap(0, 0, 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user