mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Kill entity runtime NBT (#2361)
This commit is contained in:
@ -74,8 +74,8 @@ abstract class Living extends Entity implements Damageable{
|
||||
|
||||
abstract public function getName() : string;
|
||||
|
||||
protected function initEntity() : void{
|
||||
parent::initEntity();
|
||||
protected function initEntity(CompoundTag $nbt) : void{
|
||||
parent::initEntity($nbt);
|
||||
|
||||
$this->armorInventory = new ArmorInventory($this);
|
||||
//TODO: load/save armor inventory contents
|
||||
@ -83,21 +83,17 @@ abstract class Living extends Entity implements Damageable{
|
||||
|
||||
$health = $this->getMaxHealth();
|
||||
|
||||
if($this->namedtag->hasTag("HealF", FloatTag::class)){
|
||||
$health = $this->namedtag->getFloat("HealF");
|
||||
$this->namedtag->removeTag("HealF");
|
||||
}elseif($this->namedtag->hasTag("Health")){
|
||||
$healthTag = $this->namedtag->getTag("Health");
|
||||
if($nbt->hasTag("HealF", FloatTag::class)){
|
||||
$health = $nbt->getFloat("HealF");
|
||||
}elseif($nbt->hasTag("Health")){
|
||||
$healthTag = $nbt->getTag("Health");
|
||||
$health = (float) $healthTag->getValue(); //Older versions of PocketMine-MP incorrectly saved this as a short instead of a float
|
||||
if(!($healthTag instanceof FloatTag)){
|
||||
$this->namedtag->removeTag("Health");
|
||||
}
|
||||
}
|
||||
|
||||
$this->setHealth($health);
|
||||
|
||||
/** @var CompoundTag[]|ListTag $activeEffectsTag */
|
||||
$activeEffectsTag = $this->namedtag->getListTag("ActiveEffects");
|
||||
$activeEffectsTag = $nbt->getListTag("ActiveEffects");
|
||||
if($activeEffectsTag !== null){
|
||||
foreach($activeEffectsTag as $e){
|
||||
$effect = Effect::getEffect($e->getByte("Id"));
|
||||
@ -150,9 +146,9 @@ abstract class Living extends Entity implements Damageable{
|
||||
$this->attributeMap->getAttribute(Attribute::ABSORPTION)->setValue($absorption);
|
||||
}
|
||||
|
||||
public function saveNBT() : void{
|
||||
parent::saveNBT();
|
||||
$this->namedtag->setFloat("Health", $this->getHealth(), true);
|
||||
public function saveNBT() : CompoundTag{
|
||||
$nbt = parent::saveNBT();
|
||||
$nbt->setFloat("Health", $this->getHealth(), true);
|
||||
|
||||
if(count($this->effects) > 0){
|
||||
$effects = [];
|
||||
@ -166,10 +162,10 @@ abstract class Living extends Entity implements Damageable{
|
||||
]);
|
||||
}
|
||||
|
||||
$this->namedtag->setTag(new ListTag("ActiveEffects", $effects));
|
||||
}else{
|
||||
$this->namedtag->removeTag("ActiveEffects");
|
||||
$nbt->setTag(new ListTag("ActiveEffects", $effects));
|
||||
}
|
||||
|
||||
return $nbt;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user