moving sneak & sprint properties to Living

This commit is contained in:
Dylan K. Taylor 2020-05-21 19:55:58 +01:00
parent 74e1f6320a
commit ec8ee29291
4 changed files with 38 additions and 36 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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{

View File

@ -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