diff --git a/src/block/Magma.php b/src/block/Magma.php index fd3437bc4..d16ae056b 100644 --- a/src/block/Magma.php +++ b/src/block/Magma.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\entity\Entity; +use pocketmine\entity\Living; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\item\ToolTier; @@ -43,7 +44,7 @@ class Magma extends Opaque{ } public function onEntityInside(Entity $entity) : void{ - if(!$entity->isSneaking()){ + if($entity instanceof Living and !$entity->isSneaking()){ $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); $entity->attack($ev); } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 01b01c2da..e428b1391 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -209,10 +209,6 @@ abstract class Entity{ protected $immobile = false; /** @var bool */ protected $invisible = false; - /** @var bool */ - protected $sneaking = false; - /** @var bool */ - protected $sprinting = false; /** @var int|null */ protected $ownerId = null; @@ -345,26 +341,6 @@ abstract class Entity{ ); } - public function isSneaking() : bool{ - return $this->sneaking; - } - - public function setSneaking(bool $value = true) : void{ - $this->sneaking = $value; - } - - public function isSprinting() : bool{ - return $this->sprinting; - } - - public function setSprinting(bool $value = true) : void{ - if($value !== $this->isSprinting()){ - $this->sprinting = $value; - $attr = $this->attributeMap->get(Attribute::MOVEMENT_SPEED); - $attr->setValue($value ? ($attr->getValue() * 1.3) : ($attr->getValue() / 1.3), false, true); - } - } - public function isImmobile() : bool{ return $this->immobile; } @@ -1697,7 +1673,6 @@ abstract class Entity{ $this->networkProperties->setGenericFlag(EntityMetadataFlags::IMMOBILE, $this->immobile); $this->networkProperties->setGenericFlag(EntityMetadataFlags::INVISIBLE, $this->invisible); $this->networkProperties->setGenericFlag(EntityMetadataFlags::ONFIRE, $this->isOnFire()); - $this->networkProperties->setGenericFlag(EntityMetadataFlags::SNEAKING, $this->sneaking); $this->networkProperties->setGenericFlag(EntityMetadataFlags::WALLCLIMBING, $this->canClimbWalls); } diff --git a/src/entity/Living.php b/src/entity/Living.php index 524f17dda..089e84ed4 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -108,6 +108,11 @@ abstract class Living extends Entity{ /** @var Attribute */ protected $knockbackResistanceAttr; + /** @var bool */ + protected $sprinting = false; + /** @var bool */ + protected $sneaking = false; + abstract public function getName() : string; protected function initEntity(CompoundTag $nbt) : void{ @@ -193,6 +198,26 @@ abstract class Living extends Entity{ $this->absorptionAttr->setValue($absorption); } + public function isSneaking() : bool{ + return $this->sneaking; + } + + public function setSneaking(bool $value = true) : void{ + $this->sneaking = $value; + } + + public function isSprinting() : bool{ + return $this->sprinting; + } + + public function setSprinting(bool $value = true) : void{ + if($value !== $this->isSprinting()){ + $this->sprinting = $value; + $attr = $this->attributeMap->get(Attribute::MOVEMENT_SPEED); + $attr->setValue($value ? ($attr->getValue() * 1.3) : ($attr->getValue() / 1.3), false, true); + } + } + public function saveNBT() : CompoundTag{ $nbt = parent::saveNBT(); $nbt->setFloat("Health", $this->getHealth()); @@ -739,6 +764,7 @@ abstract class Living extends Entity{ $this->networkProperties->setShort(EntityMetadataProperties::MAX_AIR, $this->maxBreathTicks); $this->networkProperties->setGenericFlag(EntityMetadataFlags::BREATHING, $this->breathing); + $this->networkProperties->setGenericFlag(EntityMetadataFlags::SNEAKING, $this->sneaking); } protected function onDispose() : void{ diff --git a/tests/phpstan/configs/l8-baseline.neon b/tests/phpstan/configs/l8-baseline.neon index 28ca59cff..860fc02c1 100644 --- a/tests/phpstan/configs/l8-baseline.neon +++ b/tests/phpstan/configs/l8-baseline.neon @@ -170,16 +170,6 @@ parameters: count: 1 path: ../../../src/entity/Entity.php - - - message: "#^Cannot call method getValue\\(\\) on pocketmine\\\\entity\\\\Attribute\\|null\\.$#" - count: 2 - path: ../../../src/entity/Entity.php - - - - message: "#^Cannot call method setValue\\(\\) on pocketmine\\\\entity\\\\Attribute\\|null\\.$#" - count: 1 - path: ../../../src/entity/Entity.php - - message: "#^Property pocketmine\\\\network\\\\mcpe\\\\protocol\\\\AddActorPacket\\:\\:\\$type \\(string\\) does not accept string\\|null\\.$#" count: 1 @@ -195,6 +185,16 @@ parameters: count: 1 path: ../../../src/entity/HungerManager.php + - + message: "#^Cannot call method getValue\\(\\) on pocketmine\\\\entity\\\\Attribute\\|null\\.$#" + count: 2 + path: ../../../src/entity/Living.php + + - + message: "#^Cannot call method setValue\\(\\) on pocketmine\\\\entity\\\\Attribute\\|null\\.$#" + count: 1 + path: ../../../src/entity/Living.php + - message: "#^Cannot call method getEffectLevel\\(\\) on pocketmine\\\\entity\\\\effect\\\\EffectInstance\\|null\\.$#" count: 3