mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-22 10:56:35 +00:00
Living: Do not rely on attribute map for moveSpeed attribute access
This commit is contained in:
parent
f77eea8c44
commit
1aa92bd6a8
@ -107,6 +107,8 @@ abstract class Living extends Entity{
|
|||||||
protected $absorptionAttr;
|
protected $absorptionAttr;
|
||||||
/** @var Attribute */
|
/** @var Attribute */
|
||||||
protected $knockbackResistanceAttr;
|
protected $knockbackResistanceAttr;
|
||||||
|
/** @var Attribute */
|
||||||
|
protected $moveSpeedAttr;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $sprinting = false;
|
protected $sprinting = false;
|
||||||
@ -168,7 +170,7 @@ abstract class Living extends Entity{
|
|||||||
$this->attributeMap->add($this->healthAttr = AttributeFactory::getInstance()->mustGet(Attribute::HEALTH));
|
$this->attributeMap->add($this->healthAttr = AttributeFactory::getInstance()->mustGet(Attribute::HEALTH));
|
||||||
$this->attributeMap->add(AttributeFactory::getInstance()->mustGet(Attribute::FOLLOW_RANGE));
|
$this->attributeMap->add(AttributeFactory::getInstance()->mustGet(Attribute::FOLLOW_RANGE));
|
||||||
$this->attributeMap->add($this->knockbackResistanceAttr = AttributeFactory::getInstance()->mustGet(Attribute::KNOCKBACK_RESISTANCE));
|
$this->attributeMap->add($this->knockbackResistanceAttr = AttributeFactory::getInstance()->mustGet(Attribute::KNOCKBACK_RESISTANCE));
|
||||||
$this->attributeMap->add(AttributeFactory::getInstance()->mustGet(Attribute::MOVEMENT_SPEED));
|
$this->attributeMap->add($this->moveSpeedAttr = AttributeFactory::getInstance()->mustGet(Attribute::MOVEMENT_SPEED));
|
||||||
$this->attributeMap->add(AttributeFactory::getInstance()->mustGet(Attribute::ATTACK_DAMAGE));
|
$this->attributeMap->add(AttributeFactory::getInstance()->mustGet(Attribute::ATTACK_DAMAGE));
|
||||||
$this->attributeMap->add($this->absorptionAttr = AttributeFactory::getInstance()->mustGet(Attribute::ABSORPTION));
|
$this->attributeMap->add($this->absorptionAttr = AttributeFactory::getInstance()->mustGet(Attribute::ABSORPTION));
|
||||||
}
|
}
|
||||||
@ -213,11 +215,20 @@ abstract class Living extends Entity{
|
|||||||
public function setSprinting(bool $value = true) : void{
|
public function setSprinting(bool $value = true) : void{
|
||||||
if($value !== $this->isSprinting()){
|
if($value !== $this->isSprinting()){
|
||||||
$this->sprinting = $value;
|
$this->sprinting = $value;
|
||||||
$attr = $this->attributeMap->get(Attribute::MOVEMENT_SPEED);
|
$moveSpeed = $this->getMovementSpeed();
|
||||||
$attr->setValue($value ? ($attr->getValue() * 1.3) : ($attr->getValue() / 1.3), false, true);
|
$this->setMovementSpeed($value ? ($moveSpeed * 1.3) : ($moveSpeed / 1.3));
|
||||||
|
$this->moveSpeedAttr->markSynchronized(false); //TODO: reevaluate this hack
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMovementSpeed() : float{
|
||||||
|
return $this->moveSpeedAttr->getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMovementSpeed(float $v, bool $fit = false) : void{
|
||||||
|
$this->moveSpeedAttr->setValue($v, $fit);
|
||||||
|
}
|
||||||
|
|
||||||
public function saveNBT() : CompoundTag{
|
public function saveNBT() : CompoundTag{
|
||||||
$nbt = parent::saveNBT();
|
$nbt = parent::saveNBT();
|
||||||
$nbt->setFloat("Health", $this->getHealth());
|
$nbt->setFloat("Health", $this->getHealth());
|
||||||
|
@ -23,18 +23,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\entity\effect;
|
namespace pocketmine\entity\effect;
|
||||||
|
|
||||||
use pocketmine\entity\Attribute;
|
|
||||||
use pocketmine\entity\Living;
|
use pocketmine\entity\Living;
|
||||||
|
|
||||||
class SlownessEffect extends Effect{
|
class SlownessEffect extends Effect{
|
||||||
|
|
||||||
public function add(Living $entity, EffectInstance $instance) : void{
|
public function add(Living $entity, EffectInstance $instance) : void{
|
||||||
$attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED);
|
$entity->setMovementSpeed($entity->getMovementSpeed() * (1 - 0.15 * $instance->getEffectLevel()), true);
|
||||||
$attr->setValue($attr->getValue() * (1 - 0.15 * $instance->getEffectLevel()), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remove(Living $entity, EffectInstance $instance) : void{
|
public function remove(Living $entity, EffectInstance $instance) : void{
|
||||||
$attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED);
|
$entity->setMovementSpeed($entity->getMovementSpeed() / (1 - 0.15 * $instance->getEffectLevel()));
|
||||||
$attr->setValue($attr->getValue() / (1 - 0.15 * $instance->getEffectLevel()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,18 +23,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\entity\effect;
|
namespace pocketmine\entity\effect;
|
||||||
|
|
||||||
use pocketmine\entity\Attribute;
|
|
||||||
use pocketmine\entity\Living;
|
use pocketmine\entity\Living;
|
||||||
|
|
||||||
class SpeedEffect extends Effect{
|
class SpeedEffect extends Effect{
|
||||||
|
|
||||||
public function add(Living $entity, EffectInstance $instance) : void{
|
public function add(Living $entity, EffectInstance $instance) : void{
|
||||||
$attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED);
|
$entity->setMovementSpeed($entity->getMovementSpeed() * (1 + 0.2 * $instance->getEffectLevel()));
|
||||||
$attr->setValue($attr->getValue() * (1 + 0.2 * $instance->getEffectLevel()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remove(Living $entity, EffectInstance $instance) : void{
|
public function remove(Living $entity, EffectInstance $instance) : void{
|
||||||
$attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED);
|
$entity->setMovementSpeed($entity->getMovementSpeed() / (1 + 0.2 * $instance->getEffectLevel()));
|
||||||
$attr->setValue($attr->getValue() / (1 + 0.2 * $instance->getEffectLevel()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,16 +185,6 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: ../../../src/entity/HungerManager.php
|
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\\.$#"
|
message: "#^Cannot call method getEffectLevel\\(\\) on pocketmine\\\\entity\\\\effect\\\\EffectInstance\\|null\\.$#"
|
||||||
count: 3
|
count: 3
|
||||||
@ -210,26 +200,6 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: ../../../src/entity/Living.php
|
path: ../../../src/entity/Living.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Cannot call method getValue\\(\\) on pocketmine\\\\entity\\\\Attribute\\|null\\.$#"
|
|
||||||
count: 2
|
|
||||||
path: ../../../src/entity/effect/SlownessEffect.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Cannot call method setValue\\(\\) on pocketmine\\\\entity\\\\Attribute\\|null\\.$#"
|
|
||||||
count: 2
|
|
||||||
path: ../../../src/entity/effect/SlownessEffect.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Cannot call method getValue\\(\\) on pocketmine\\\\entity\\\\Attribute\\|null\\.$#"
|
|
||||||
count: 2
|
|
||||||
path: ../../../src/entity/effect/SpeedEffect.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Cannot call method setValue\\(\\) on pocketmine\\\\entity\\\\Attribute\\|null\\.$#"
|
|
||||||
count: 2
|
|
||||||
path: ../../../src/entity/effect/SpeedEffect.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Method pocketmine\\\\entity\\\\object\\\\Painting\\:\\:getMotive\\(\\) should return pocketmine\\\\entity\\\\object\\\\PaintingMotive but returns pocketmine\\\\entity\\\\object\\\\PaintingMotive\\|null\\.$#"
|
message: "#^Method pocketmine\\\\entity\\\\object\\\\Painting\\:\\:getMotive\\(\\) should return pocketmine\\\\entity\\\\object\\\\PaintingMotive but returns pocketmine\\\\entity\\\\object\\\\PaintingMotive\\|null\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user