mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
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:
@ -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);
|
||||
|
Reference in New Issue
Block a user