Type-hinted NBT tag constructors, made getValue() and setValue() more strict, fix dozens of assorted related bugs

This commit is contained in:
Dylan K. Taylor
2017-06-08 19:17:41 +01:00
parent 595e1ab52f
commit 890f72dbf2
24 changed files with 348 additions and 65 deletions

View File

@ -59,7 +59,7 @@ abstract class BaseLevelProvider implements LevelProvider{
}
if(!isset($this->levelData->generatorName)){
$this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("DEFAULT"));
$this->levelData->generatorName = new StringTag("generatorName", (string) Generator::getGenerator("DEFAULT"));
}
if(!isset($this->levelData->generatorOptions)){

View File

@ -95,7 +95,7 @@ class LevelDB extends BaseLevelProvider{
if(isset($this->levelData->Generator)){
switch((int) $this->levelData->Generator->getValue()){ //Detect correct generator from MCPE data
case self::GENERATOR_FLAT:
$this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("FLAT"));
$this->levelData->generatorName = new StringTag("generatorName", (string) Generator::getGenerator("FLAT"));
if(($layers = $this->db->get(self::ENTRY_FLAT_WORLD_LAYERS)) !== false){ //Detect existing custom flat layers
$layers = trim($layers, "[]");
}else{
@ -105,7 +105,7 @@ class LevelDB extends BaseLevelProvider{
break;
case self::GENERATOR_INFINITE:
//TODO: add a null generator which does not generate missing chunks (to allow importing back to MCPE and generating more normal terrain without PocketMine messing things up)
$this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("DEFAULT"));
$this->levelData->generatorName = new StringTag("generatorName", (string) Generator::getGenerator("DEFAULT"));
$this->levelData->generatorOptions = new StringTag("generatorOptions", "");
break;
case self::GENERATOR_LIMITED:
@ -114,7 +114,7 @@ class LevelDB extends BaseLevelProvider{
throw new LevelException("Unknown LevelDB world format type, this level cannot be loaded");
}
}else{
$this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("DEFAULT"));
$this->levelData->generatorName = new StringTag("generatorName", (string) Generator::getGenerator("DEFAULT"));
}
}

View File

@ -56,7 +56,7 @@ class Anvil extends McRegion{
if($subChunk->isEmpty()){
continue;
}
$nbt->Sections[++$subChunks] = new CompoundTag(null, [
$nbt->Sections[++$subChunks] = new CompoundTag("", [
"Y" => new ByteTag("Y", $y),
"Blocks" => new ByteArrayTag("Blocks", ChunkUtils::reorderByteArray($subChunk->getBlockIdArray())), //Generic in-memory chunks are currently always XZY
"Data" => new ByteArrayTag("Data", ChunkUtils::reorderNibbleArray($subChunk->getBlockDataArray())),

View File

@ -59,7 +59,7 @@ class PMAnvil extends Anvil{
if($subChunk->isEmpty()){
continue;
}
$nbt->Sections[++$subChunks] = new CompoundTag(null, [
$nbt->Sections[++$subChunks] = new CompoundTag("", [
"Y" => new ByteTag("Y", $y),
"Blocks" => new ByteArrayTag("Blocks", $subChunk->getBlockIdArray()),
"Data" => new ByteArrayTag("Data", $subChunk->getBlockDataArray()),