Remove all usages of CompoundTag->hasTag()

in pretty much every case, these usages really wanted to read the tag's contents anyway, which can be combined with a getTag() and instanceof call for more concise and static analysis friendly code.
In the few cases where the tag contents wasn't needed, it still wanted to check the type, which, again, can be done in a more static analysis friendly way by just using getTag() and instanceof.
This commit is contained in:
Dylan K. Taylor 2020-07-10 21:01:43 +01:00
parent 91b028c208
commit 279abb871d
27 changed files with 94 additions and 92 deletions

View File

@ -61,8 +61,8 @@ class Banner extends Spawnable{
public function readSaveData(CompoundTag $nbt) : void{
$colorIdMap = DyeColorIdMap::getInstance();
if($nbt->hasTag(self::TAG_BASE, IntTag::class)){
$this->baseColor = $colorIdMap->fromInvertedId($nbt->getInt(self::TAG_BASE));
if(($baseColorTag = $nbt->getTag(self::TAG_BASE)) instanceof IntTag){
$this->baseColor = $colorIdMap->fromInvertedId($baseColorTag->getValue());
}
$patterns = $nbt->getListTag(self::TAG_PATTERNS);

View File

@ -49,8 +49,8 @@ class Bed extends Spawnable{
}
public function readSaveData(CompoundTag $nbt) : void{
if($nbt->hasTag(self::TAG_COLOR, ByteTag::class)){
$this->color = DyeColorIdMap::getInstance()->fromId($nbt->getByte(self::TAG_COLOR));
if(($colorTag = $nbt->getTag(self::TAG_COLOR)) instanceof ByteTag){
$this->color = DyeColorIdMap::getInstance()->fromId($colorTag->getValue());
}
}

View File

@ -59,9 +59,9 @@ class Chest extends Spawnable implements Container, Nameable{
}
public function readSaveData(CompoundTag $nbt) : void{
if($nbt->hasTag(self::TAG_PAIRX, IntTag::class) and $nbt->hasTag(self::TAG_PAIRZ, IntTag::class)){
$pairX = $nbt->getInt(self::TAG_PAIRX);
$pairZ = $nbt->getInt(self::TAG_PAIRZ);
if(($pairXTag = $nbt->getTag(self::TAG_PAIRX)) instanceof IntTag and ($pairZTag = $nbt->getTag(self::TAG_PAIRZ)) instanceof IntTag){
$pairX = $pairXTag->getValue();
$pairZ = $pairZTag->getValue();
if(
($this->pos->x === $pairX and abs($this->pos->z - $pairZ) === 1) or
($this->pos->z === $pairZ and abs($this->pos->x - $pairX) === 1)

View File

@ -56,8 +56,8 @@ trait ContainerTrait{
$inventory->getListeners()->add(...$listeners);
}
if($tag->hasTag(Container::TAG_LOCK, StringTag::class)){
$this->lock = $tag->getString(Container::TAG_LOCK);
if(($lockTag = $tag->getTag(Container::TAG_LOCK)) instanceof StringTag){
$this->lock = $lockTag->getValue();
}
}

View File

@ -42,9 +42,9 @@ class FlowerPot extends Spawnable{
private $plant = null;
public function readSaveData(CompoundTag $nbt) : void{
if($nbt->hasTag(self::TAG_ITEM, ShortTag::class) and $nbt->hasTag(self::TAG_ITEM_DATA, IntTag::class)){
if(($itemIdTag = $nbt->getTag(self::TAG_ITEM)) instanceof ShortTag and ($itemMetaTag = $nbt->getTag(self::TAG_ITEM_DATA)) instanceof IntTag){
try{
$this->setPlant(BlockFactory::getInstance()->get($nbt->getShort(self::TAG_ITEM), $nbt->getInt(self::TAG_ITEM_DATA)));
$this->setPlant(BlockFactory::getInstance()->get($itemIdTag->getValue(), $itemMetaTag->getValue()));
}catch(\InvalidArgumentException $e){
//noop
}

View File

@ -95,11 +95,11 @@ class MonsterSpawner extends Spawnable{
private $requiredPlayerRange = self::DEFAULT_REQUIRED_PLAYER_RANGE;
public function readSaveData(CompoundTag $nbt) : void{
if($nbt->hasTag(self::TAG_LEGACY_ENTITY_TYPE_ID, IntTag::class)){
if(($legacyIdTag = $nbt->getTag(self::TAG_LEGACY_ENTITY_TYPE_ID)) instanceof IntTag){
//TODO: this will cause unexpected results when there's no mapping for the entity
$this->entityTypeId = LegacyEntityIdToStringIdMap::getInstance()->legacyToString($nbt->getInt(self::TAG_LEGACY_ENTITY_TYPE_ID)) ?? ":";
}elseif($nbt->hasTag(self::TAG_ENTITY_TYPE_ID, StringTag::class)){
$this->entityTypeId = $nbt->getString(self::TAG_ENTITY_TYPE_ID);
$this->entityTypeId = LegacyEntityIdToStringIdMap::getInstance()->legacyToString($legacyIdTag->getValue()) ?? ":";
}elseif(($idTag = $nbt->getTag(self::TAG_ENTITY_TYPE_ID)) instanceof StringTag){
$this->entityTypeId = $idTag->getValue();
}else{
$this->entityTypeId = ":"; //default - TODO: replace this with a constant
}

View File

@ -59,8 +59,8 @@ trait NameableTrait{
}
protected function loadName(CompoundTag $tag) : void{
if($tag->hasTag(Nameable::TAG_CUSTOM_NAME, StringTag::class)){
$this->customName = $tag->getString(Nameable::TAG_CUSTOM_NAME);
if(($customNameTag = $tag->getTag(Nameable::TAG_CUSTOM_NAME)) instanceof StringTag){
$this->customName = $customNameTag->getValue();
}
}

View File

@ -59,14 +59,14 @@ class Sign extends Spawnable{
}
public function readSaveData(CompoundTag $nbt) : void{
if($nbt->hasTag(self::TAG_TEXT_BLOB, StringTag::class)){ //MCPE 1.2 save format
$this->text = SignText::fromBlob(mb_scrub($nbt->getString(self::TAG_TEXT_BLOB), 'UTF-8'));
if(($textBlobTag = $nbt->getTag(self::TAG_TEXT_BLOB)) instanceof StringTag){ //MCPE 1.2 save format
$this->text = SignText::fromBlob(mb_scrub($textBlobTag->getValue(), 'UTF-8'));
}else{
$text = [];
for($i = 0; $i < SignText::LINE_COUNT; ++$i){
$textKey = sprintf(self::TAG_TEXT_LINE, $i + 1);
if($nbt->hasTag($textKey, StringTag::class)){
$text[$i] = mb_scrub($nbt->getString($textKey), 'UTF-8');
if(($lineTag = $nbt->getTag($textKey)) instanceof StringTag){
$text[$i] = mb_scrub($lineTag->getValue(), 'UTF-8');
}
}
$this->text = new SignText($text);

View File

@ -51,9 +51,9 @@ class Skull extends Spawnable{
}
public function readSaveData(CompoundTag $nbt) : void{
if($nbt->hasTag(self::TAG_SKULL_TYPE, ByteTag::class)){
if(($skullTypeTag = $nbt->getTag(self::TAG_SKULL_TYPE)) instanceof ByteTag){
try{
$this->skullType = SkullType::fromMagicNumber($nbt->getByte(self::TAG_SKULL_TYPE));
$this->skullType = SkullType::fromMagicNumber($skullTypeTag->getValue());
}catch(\InvalidArgumentException $e){
//bad data, drop it
}

View File

@ -481,12 +481,12 @@ abstract class Entity{
$this->fallDistance = $nbt->getFloat("FallDistance", 0.0);
if($nbt->hasTag("CustomName", StringTag::class)){
$this->setNameTag($nbt->getString("CustomName"));
if(($customNameTag = $nbt->getTag("CustomName")) instanceof StringTag){
$this->setNameTag($customNameTag->getValue());
if($nbt->hasTag("CustomNameVisible", StringTag::class)){
if(($customNameVisibleTag = $nbt->getTag("CustomNameVisible")) instanceof StringTag){
//Older versions incorrectly saved this as a string (see 890f72dbf23a77f294169b79590770470041adc4)
$this->setNameTagVisible($nbt->getString("CustomNameVisible") !== "");
$this->setNameTagVisible($customNameVisibleTag->getValue() !== "");
}else{
$this->setNameTagVisible($nbt->getByte("CustomNameVisible", 1) !== 0);
}

View File

@ -118,10 +118,10 @@ final class EntityFactory{
throw new \UnexpectedValueException("Unknown painting motive");
}
$blockIn = new Vector3($nbt->getInt("TileX"), $nbt->getInt("TileY"), $nbt->getInt("TileZ"));
if($nbt->hasTag("Direction", ByteTag::class)){
$facing = Painting::DATA_TO_FACING[$nbt->getByte("Direction")] ?? Facing::NORTH;
}elseif($nbt->hasTag("Facing", ByteTag::class)){
$facing = Painting::DATA_TO_FACING[$nbt->getByte("Facing")] ?? Facing::NORTH;
if(($directionTag = $nbt->getTag("Direction")) instanceof ByteTag){
$facing = Painting::DATA_TO_FACING[$directionTag->getValue()] ?? Facing::NORTH;
}elseif(($facingTag = $nbt->getTag("Facing")) instanceof ByteTag){
$facing = Painting::DATA_TO_FACING[$facingTag->getValue()] ?? Facing::NORTH;
}else{
throw new \UnexpectedValueException("Missing facing info");
}

View File

@ -105,7 +105,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
}
return new Skin( //this throws if the skin is invalid
$skinTag->getString("Name"),
$skinTag->hasTag("Data", StringTag::class) ? $skinTag->getString("Data") : $skinTag->getByteArray("Data"), //old data (this used to be saved as a StringTag in older versions of PM)
($skinDataTag = $skinTag->getTag("Data")) instanceof StringTag ? $skinDataTag->getValue() : $skinTag->getByteArray("Data"), //old data (this used to be saved as a StringTag in older versions of PM)
$skinTag->getByteArray("CapeData", ""),
$skinTag->getString("GeometryName", ""),
$skinTag->getByteArray("GeometryData", "")
@ -194,8 +194,8 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
* For Human entities which are not players, sets their properties such as nametag, skin and UUID from NBT.
*/
protected function initHumanData(CompoundTag $nbt) : void{
if($nbt->hasTag("NameTag", StringTag::class)){
$this->setNameTag($nbt->getString("NameTag"));
if(($nameTagTag = $nbt->getTag("NameTag")) instanceof StringTag){
$this->setNameTag($nameTagTag->getValue());
}
$this->uuid = UUID::fromData((string) $this->getId(), $this->skin->getSkinData(), $this->getNameTag());
@ -251,8 +251,8 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
$nbt->getFloat("XpP", 0.0));
$this->xpManager->setLifetimeTotalXp($nbt->getInt("XpTotal", 0));
if($nbt->hasTag("XpSeed", IntTag::class)){
$this->xpSeed = $nbt->getInt("XpSeed");
if(($xpSeedTag = $nbt->getTag("XpSeed")) instanceof IntTag){
$this->xpSeed = $xpSeedTag->getValue();
}else{
$this->xpSeed = random_int(Limits::INT32_MIN, Limits::INT32_MAX);
}

View File

@ -134,12 +134,12 @@ abstract class Living extends Entity{
$health = $this->getMaxHealth();
if($nbt->hasTag("HealF", FloatTag::class)){
$health = $nbt->getFloat("HealF");
}elseif($nbt->hasTag("Health", ShortTag::class)){
$health = $nbt->getShort("Health"); //Older versions of PocketMine-MP incorrectly saved this as a short instead of a float
}elseif($nbt->hasTag("Health", FloatTag::class)){
$health = $nbt->getFloat("Health");
if(($healFTag = $nbt->getTag("HealF")) instanceof FloatTag){
$health = $healFTag->getValue();
}elseif(($healthTag = $nbt->getTag("Health")) instanceof ShortTag){
$health = $healthTag->getValue(); //Older versions of PocketMine-MP incorrectly saved this as a short instead of a float
}elseif(($healthTag = $nbt->getTag("Health")) instanceof FloatTag){
$health = $healthTag->getValue();
}
$this->setHealth($health);

View File

@ -108,10 +108,10 @@ class ExperienceOrb extends Entity{
$this->age = $nbt->getShort("Age", 0);
$value = 1;
if($nbt->hasTag(self::TAG_VALUE_PC, ShortTag::class)){ //PC
$value = $nbt->getShort(self::TAG_VALUE_PC);
}elseif($nbt->hasTag(self::TAG_VALUE_PE, IntTag::class)){ //PE save format
$value = $nbt->getInt(self::TAG_VALUE_PE);
if(($valuePcTag = $nbt->getTag(self::TAG_VALUE_PC)) instanceof ShortTag){ //PC
$value = $valuePcTag->getValue();
}elseif(($valuePeTag = $nbt->getTag(self::TAG_VALUE_PE)) instanceof IntTag){ //PE save format
$value = $valuePeTag->getValue();
}
$this->setXpValue($value);

View File

@ -64,10 +64,10 @@ class FallingBlock extends Entity{
$blockId = 0;
//TODO: 1.8+ save format
if($nbt->hasTag("TileID", IntTag::class)){
$blockId = $nbt->getInt("TileID");
}elseif($nbt->hasTag("Tile", ByteTag::class)){
$blockId = $nbt->getByte("Tile");
if(($tileIdTag = $nbt->getTag("TileID")) instanceof IntTag){
$blockId = $tileIdTag->getValue();
}elseif(($tileTag = $nbt->getTag("Tile")) instanceof ByteTag){
$blockId = $tileTag->getValue();
}
if($blockId === 0){

View File

@ -82,20 +82,20 @@ abstract class Projectile extends Entity{
$blockId = null;
$blockData = null;
if($nbt->hasTag("tileX", IntTag::class) and $nbt->hasTag("tileY", IntTag::class) and $nbt->hasTag("tileZ", IntTag::class)){
$blockPos = new Vector3($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ"));
if(($tileXTag = $nbt->getTag("tileX")) instanceof IntTag and ($tileYTag = $nbt->getTag("tileY")) instanceof IntTag and ($tileZTag = $nbt->getTag("tileZ")) instanceof IntTag){
$blockPos = new Vector3($tileXTag->getValue(), $tileYTag->getValue(), $tileZTag->getValue());
}else{
break;
}
if($nbt->hasTag("blockId", IntTag::class)){
$blockId = $nbt->getInt("blockId");
if(($blockIdTag = $nbt->getTag("blockId")) instanceof IntTag){
$blockId = $blockIdTag->getValue();
}else{
break;
}
if($nbt->hasTag("blockData", ByteTag::class)){
$blockData = $nbt->getByte("blockData");
if(($blockDataTag = $nbt->getTag("blockData")) instanceof ByteTag){
$blockData = $blockDataTag->getValue();
}else{
break;
}

View File

@ -133,8 +133,8 @@ class Armor extends Durable{
protected function deserializeCompoundTag(CompoundTag $tag) : void{
parent::deserializeCompoundTag($tag);
if($tag->hasTag(self::TAG_CUSTOM_COLOR, IntTag::class)){
$this->customColor = Color::fromARGB(Binary::unsignInt($tag->getInt(self::TAG_CUSTOM_COLOR)));
if(($colorTag = $tag->getTag(self::TAG_CUSTOM_COLOR)) instanceof IntTag){
$this->customColor = Color::fromARGB(Binary::unsignInt($colorTag->getValue()));
}else{
$this->customColor = null;
}

View File

@ -647,7 +647,7 @@ class Item implements \JsonSerializable{
* Deserializes an Item from an NBT CompoundTag
*/
public static function nbtDeserialize(CompoundTag $tag) : Item{
if(!$tag->hasTag("id") or !$tag->hasTag("Count")){
if($tag->getTag("id") === null or $tag->getTag("Count") === null){
return ItemFactory::getInstance()->get(0);
}

View File

@ -137,8 +137,8 @@ class TypeConverter{
if($compound !== null){
$compound = clone $compound;
if($compound->hasTag(self::DAMAGE_TAG, IntTag::class)){
$meta = $compound->getInt(self::DAMAGE_TAG);
if(($damageTag = $compound->getTag(self::DAMAGE_TAG)) instanceof IntTag){
$meta = $damageTag->getValue();
$compound->removeTag(self::DAMAGE_TAG);
if($compound->count() === 0){
$compound = null;

View File

@ -598,9 +598,9 @@ class InGamePacketHandler extends PacketHandler{
if(!($nbt instanceof CompoundTag)) throw new AssumptionFailedError("PHPStan should ensure this is a CompoundTag"); //for phpstorm's benefit
if($block instanceof Sign){
if($nbt->hasTag("Text", StringTag::class)){
if(($textBlobTag = $nbt->getTag("Text")) instanceof StringTag){
try{
$text = SignText::fromBlob($nbt->getString("Text"));
$text = SignText::fromBlob($textBlobTag->getValue());
}catch(\InvalidArgumentException $e){
throw BadPacketException::wrap($e, "Invalid sign text update");
}

View File

@ -99,11 +99,11 @@ class OfflinePlayer implements IPlayer{
}
public function getFirstPlayed() : ?int{
return ($this->namedtag !== null and $this->namedtag->hasTag("firstPlayed", LongTag::class)) ? $this->namedtag->getLong("firstPlayed") : null;
return ($this->namedtag !== null and ($firstPlayedTag = $this->namedtag->getTag("firstPlayed")) instanceof LongTag) ? $firstPlayedTag->getValue() : null;
}
public function getLastPlayed() : ?int{
return ($this->namedtag !== null and $this->namedtag->hasTag("lastPlayed", LongTag::class)) ? $this->namedtag->getLong("lastPlayed") : null;
return ($this->namedtag !== null and ($lastPlayedTag = $this->namedtag->getTag("lastPlayed")) instanceof LongTag) ? $lastPlayedTag->getValue() : null;
}
public function hasPlayedBefore() : bool{

View File

@ -334,10 +334,10 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$this->firstPlayed = $nbt->getLong("firstPlayed", $now = (int) (microtime(true) * 1000));
$this->lastPlayed = $nbt->getLong("lastPlayed", $now);
if($this->server->getForceGamemode() or !$nbt->hasTag("playerGameType", IntTag::class)){
$this->internalSetGameMode($this->server->getGamemode());
if(!$this->server->getForceGamemode() and ($gameModeTag = $nbt->getTag("playerGameType")) instanceof IntTag){
$this->internalSetGameMode(GameMode::fromMagicNumber($gameModeTag->getValue() & 0x03)); //TODO: bad hack here to avoid crashes on corrupted data
}else{
$this->internalSetGameMode(GameMode::fromMagicNumber($nbt->getInt("playerGameType") & 0x03)); //TODO: bad hack here to avoid crashes on corrupted data
$this->internalSetGameMode($this->server->getGamemode());
}
$this->keepMovement = true;

View File

@ -125,8 +125,8 @@ abstract class BaseNbtWorldData implements WorldData{
}
public function getTime() : int{
if($this->compoundTag->hasTag("Time", IntTag::class)){ //some older PM worlds had this in the wrong format
return $this->compoundTag->getInt("Time");
if(($timeTag = $this->compoundTag->getTag("Time")) instanceof IntTag){ //some older PM worlds had this in the wrong format
return $timeTag->getValue();
}
return $this->compoundTag->getLong("Time", 0);
}

View File

@ -134,9 +134,10 @@ class BedrockWorldData extends BaseNbtWorldData{
}
protected function fix() : void{
if(!$this->compoundTag->hasTag("generatorName", StringTag::class)){
if($this->compoundTag->hasTag("Generator", IntTag::class)){
switch($this->compoundTag->getInt("Generator")){ //Detect correct generator from MCPE data
$generatorNameTag = $this->compoundTag->getTag("generatorName");
if(!($generatorNameTag instanceof StringTag)){
if(($mcpeGeneratorTypeTag = $this->compoundTag->getTag("Generator")) instanceof IntTag){
switch($mcpeGeneratorTypeTag->getValue()){ //Detect correct generator from MCPE data
case self::GENERATOR_FLAT:
$this->compoundTag->setString("generatorName", "flat");
$this->compoundTag->setString("generatorOptions", "2;7,3,3,2;1");
@ -154,11 +155,11 @@ class BedrockWorldData extends BaseNbtWorldData{
}else{
$this->compoundTag->setString("generatorName", "default");
}
}elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($this->compoundTag->getString("generatorName"))) !== null){
}elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($generatorNameTag->getValue())) !== null){
$this->compoundTag->setString("generatorName", $generatorName);
}
if(!$this->compoundTag->hasTag("generatorOptions", StringTag::class)){
if(!($this->compoundTag->getTag("generatorOptions")) instanceof StringTag){
$this->compoundTag->setString("generatorOptions", "");
}
}

View File

@ -101,13 +101,14 @@ class JavaWorldData extends BaseNbtWorldData{
}
protected function fix() : void{
if(!$this->compoundTag->hasTag("generatorName", StringTag::class)){
$generatorNameTag = $this->compoundTag->getTag("generatorName");
if(!($generatorNameTag instanceof StringTag)){
$this->compoundTag->setString("generatorName", "default");
}elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($this->compoundTag->getString("generatorName"))) !== null){
}elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($generatorNameTag->getValue())) !== null){
$this->compoundTag->setString("generatorName", $generatorName);
}
if(!$this->compoundTag->hasTag("generatorOptions", StringTag::class)){
if(!($this->compoundTag->getTag("generatorOptions") instanceof StringTag)){
$this->compoundTag->setString("generatorOptions", "");
}
}
@ -135,8 +136,8 @@ class JavaWorldData extends BaseNbtWorldData{
}
public function getRainLevel() : float{
if($this->compoundTag->hasTag("rainLevel", FloatTag::class)){ //PocketMine/MCPE
return $this->compoundTag->getFloat("rainLevel");
if(($rainLevelTag = $this->compoundTag->getTag("rainLevel")) instanceof FloatTag){ //PocketMine/MCPE
return $rainLevelTag->getValue();
}
return (float) $this->compoundTag->getByte("raining", 0); //PC vanilla
@ -156,8 +157,8 @@ class JavaWorldData extends BaseNbtWorldData{
}
public function getLightningLevel() : float{
if($this->compoundTag->hasTag("lightningLevel", FloatTag::class)){ //PocketMine/MCPE
return $this->compoundTag->getFloat("lightningLevel");
if(($lightningLevelTag = $this->compoundTag->getTag("lightningLevel")) instanceof FloatTag){ //PocketMine/MCPE
return $lightningLevelTag->getValue();
}
return (float) $this->compoundTag->getByte("thundering", 0); //PC vanilla

View File

@ -86,10 +86,10 @@ trait LegacyAnvilChunkTrait{
}
};
$biomeArray = null;
if($chunk->hasTag("BiomeColors", IntArrayTag::class)){
$biomeArray = $makeBiomeArray(ChunkUtils::convertBiomeColors($chunk->getIntArray("BiomeColors"))); //Convert back to original format
}elseif($chunk->hasTag("Biomes", ByteArrayTag::class)){
$biomeArray = $makeBiomeArray($chunk->getByteArray("Biomes"));
if(($biomeColorsTag = $chunk->getTag("BiomeColors")) instanceof IntArrayTag){
$biomeArray = $makeBiomeArray(ChunkUtils::convertBiomeColors($biomeColorsTag->getValue())); //Convert back to original format
}elseif(($biomesTag = $chunk->getTag("Biomes")) instanceof ByteArrayTag){
$biomeArray = $makeBiomeArray($biomesTag->getValue());
}
$result = new Chunk(

View File

@ -68,8 +68,8 @@ class McRegion extends RegionWorldProvider{
}
$subChunks = [];
$fullIds = $chunk->hasTag("Blocks", ByteArrayTag::class) ? $chunk->getByteArray("Blocks") : str_repeat("\x00", 32768);
$fullData = $chunk->hasTag("Data", ByteArrayTag::class) ? $chunk->getByteArray("Data") : str_repeat("\x00", 16384);
$fullIds = ($fullIdsTag = $chunk->getTag("Blocks")) instanceof ByteArrayTag ? $fullIdsTag->getValue() : str_repeat("\x00", 32768);
$fullData = ($fullDataTag = $chunk->getTag("Data")) instanceof ByteArrayTag ? $fullDataTag->getValue() : str_repeat("\x00", 16384);
for($y = 0; $y < 8; ++$y){
$subChunks[$y] = new SubChunk(BlockLegacyIds::AIR << 4, [SubChunkConverter::convertSubChunkFromLegacyColumn($fullIds, $fullData, $y)]);
@ -83,10 +83,10 @@ class McRegion extends RegionWorldProvider{
}
};
$biomeIds = null;
if($chunk->hasTag("BiomeColors", IntArrayTag::class)){
$biomeIds = $makeBiomeArray(ChunkUtils::convertBiomeColors($chunk->getIntArray("BiomeColors"))); //Convert back to original format
}elseif($chunk->hasTag("Biomes", ByteArrayTag::class)){
$biomeIds = $makeBiomeArray($chunk->getByteArray("Biomes"));
if(($biomeColorsTag = $chunk->getTag("BiomeColors")) instanceof IntArrayTag){
$biomeIds = $makeBiomeArray(ChunkUtils::convertBiomeColors($biomeColorsTag->getValue())); //Convert back to original format
}elseif(($biomesTag = $chunk->getTag("Biomes")) instanceof ByteArrayTag){
$biomeIds = $makeBiomeArray($biomesTag->getValue());
}
$result = new Chunk(