mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 17:36:12 +00:00
Merge branch 'next-minor' into next-major
This commit is contained in:
@ -77,6 +77,16 @@ use const M_PI;
|
||||
abstract class Living extends Entity{
|
||||
protected const DEFAULT_BREATH_TICKS = 300;
|
||||
|
||||
private const TAG_LEGACY_HEALTH = "HealF"; //TAG_Float
|
||||
private const TAG_HEALTH = "Health"; //TAG_Float
|
||||
private const TAG_BREATH_TICKS = "Air"; //TAG_Short
|
||||
private const TAG_ACTIVE_EFFECTS = "ActiveEffects"; //TAG_List<TAG_Compound>
|
||||
private const TAG_EFFECT_ID = "Id"; //TAG_Byte
|
||||
private const TAG_EFFECT_DURATION = "Duration"; //TAG_Int
|
||||
private const TAG_EFFECT_AMPLIFIER = "Amplifier"; //TAG_Byte
|
||||
private const TAG_EFFECT_SHOW_PARTICLES = "ShowParticles"; //TAG_Byte
|
||||
private const TAG_EFFECT_AMBIENT = "Ambient"; //TAG_Byte
|
||||
|
||||
protected int $attackTime = 0;
|
||||
|
||||
public int $deadTicks = 0;
|
||||
@ -127,9 +137,9 @@ abstract class Living extends Entity{
|
||||
|
||||
$health = $this->getMaxHealth();
|
||||
|
||||
if(($healFTag = $nbt->getTag("HealF")) instanceof FloatTag){
|
||||
if(($healFTag = $nbt->getTag(self::TAG_LEGACY_HEALTH)) instanceof FloatTag){
|
||||
$health = $healFTag->getValue();
|
||||
}elseif(($healthTag = $nbt->getTag("Health")) instanceof ShortTag){
|
||||
}elseif(($healthTag = $nbt->getTag(self::TAG_HEALTH)) instanceof ShortTag){
|
||||
$health = $healthTag->getValue(); //Older versions of PocketMine-MP incorrectly saved this as a short instead of a float
|
||||
}elseif($healthTag instanceof FloatTag){
|
||||
$health = $healthTag->getValue();
|
||||
@ -137,23 +147,23 @@ abstract class Living extends Entity{
|
||||
|
||||
$this->setHealth($health);
|
||||
|
||||
$this->setAirSupplyTicks($nbt->getShort("Air", self::DEFAULT_BREATH_TICKS));
|
||||
$this->setAirSupplyTicks($nbt->getShort(self::TAG_BREATH_TICKS, self::DEFAULT_BREATH_TICKS));
|
||||
|
||||
/** @var CompoundTag[]|ListTag|null $activeEffectsTag */
|
||||
$activeEffectsTag = $nbt->getListTag("ActiveEffects");
|
||||
$activeEffectsTag = $nbt->getListTag(self::TAG_ACTIVE_EFFECTS);
|
||||
if($activeEffectsTag !== null){
|
||||
foreach($activeEffectsTag as $e){
|
||||
$effect = EffectIdMap::getInstance()->fromId($e->getByte("Id"));
|
||||
$effect = EffectIdMap::getInstance()->fromId($e->getByte(self::TAG_EFFECT_ID));
|
||||
if($effect === null){
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->effectManager->add(new EffectInstance(
|
||||
$effect,
|
||||
$e->getInt("Duration"),
|
||||
Binary::unsignByte($e->getByte("Amplifier")),
|
||||
$e->getByte("ShowParticles", 1) !== 0,
|
||||
$e->getByte("Ambient", 0) !== 0
|
||||
$e->getInt(self::TAG_EFFECT_DURATION),
|
||||
Binary::unsignByte($e->getByte(self::TAG_EFFECT_AMPLIFIER)),
|
||||
$e->getByte(self::TAG_EFFECT_SHOW_PARTICLES, 1) !== 0,
|
||||
$e->getByte(self::TAG_EFFECT_AMBIENT, 0) !== 0
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -263,22 +273,22 @@ abstract class Living extends Entity{
|
||||
|
||||
public function saveNBT() : CompoundTag{
|
||||
$nbt = parent::saveNBT();
|
||||
$nbt->setFloat("Health", $this->getHealth());
|
||||
$nbt->setFloat(self::TAG_HEALTH, $this->getHealth());
|
||||
|
||||
$nbt->setShort("Air", $this->getAirSupplyTicks());
|
||||
$nbt->setShort(self::TAG_BREATH_TICKS, $this->getAirSupplyTicks());
|
||||
|
||||
if(count($this->effectManager->all()) > 0){
|
||||
$effects = [];
|
||||
foreach($this->effectManager->all() as $effect){
|
||||
$effects[] = CompoundTag::create()
|
||||
->setByte("Id", EffectIdMap::getInstance()->toId($effect->getType()))
|
||||
->setByte("Amplifier", Binary::signByte($effect->getAmplifier()))
|
||||
->setInt("Duration", $effect->getDuration())
|
||||
->setByte("Ambient", $effect->isAmbient() ? 1 : 0)
|
||||
->setByte("ShowParticles", $effect->isVisible() ? 1 : 0);
|
||||
->setByte(self::TAG_EFFECT_ID, EffectIdMap::getInstance()->toId($effect->getType()))
|
||||
->setByte(self::TAG_EFFECT_AMPLIFIER, Binary::signByte($effect->getAmplifier()))
|
||||
->setInt(self::TAG_EFFECT_DURATION, $effect->getDuration())
|
||||
->setByte(self::TAG_EFFECT_AMBIENT, $effect->isAmbient() ? 1 : 0)
|
||||
->setByte(self::TAG_EFFECT_SHOW_PARTICLES, $effect->isVisible() ? 1 : 0);
|
||||
}
|
||||
|
||||
$nbt->setTag("ActiveEffects", new ListTag($effects));
|
||||
$nbt->setTag(self::TAG_ACTIVE_EFFECTS, new ListTag($effects));
|
||||
}
|
||||
|
||||
return $nbt;
|
||||
|
Reference in New Issue
Block a user