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

@ -32,6 +32,7 @@ use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\event\Timings;
use pocketmine\item\Item as ItemItem;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\utils\BlockIterator;
@ -51,10 +52,12 @@ abstract class Living extends Entity implements Damageable{
parent::initEntity();
if(isset($this->namedtag->HealF)){
$this->namedtag->Health = new ShortTag("Health", (int) $this->namedtag["HealF"]);
$this->namedtag->Health = new FloatTag("Health", (float) $this->namedtag["HealF"]);
unset($this->namedtag->HealF);
}elseif(!isset($this->namedtag->Health) or !($this->namedtag->Health instanceof ShortTag)){
$this->namedtag->Health = new ShortTag("Health", $this->getMaxHealth());
}elseif(isset($this->namedtag->Health) and !($this->namedtag->Health instanceof FloatTag)){
$this->namedtag->Health = new FloatTag("Health", (float) $this->namedtag->Health->getValue());
}else{
$this->namedtag->Health = new FloatTag("Health", (float) $this->getMaxHealth());
}
$this->setHealth($this->namedtag["Health"]);