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

@ -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);