mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-21 18:36:40 +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;
|
||||
/** @var Attribute */
|
||||
protected $knockbackResistanceAttr;
|
||||
/** @var Attribute */
|
||||
protected $moveSpeedAttr;
|
||||
|
||||
/** @var bool */
|
||||
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(AttributeFactory::getInstance()->mustGet(Attribute::FOLLOW_RANGE));
|
||||
$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($this->absorptionAttr = AttributeFactory::getInstance()->mustGet(Attribute::ABSORPTION));
|
||||
}
|
||||
@ -213,11 +215,20 @@ abstract class Living extends Entity{
|
||||
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);
|
||||
$moveSpeed = $this->getMovementSpeed();
|
||||
$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{
|
||||
$nbt = parent::saveNBT();
|
||||
$nbt->setFloat("Health", $this->getHealth());
|
||||
|
@ -23,18 +23,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\entity\effect;
|
||||
|
||||
use pocketmine\entity\Attribute;
|
||||
use pocketmine\entity\Living;
|
||||
|
||||
class SlownessEffect extends Effect{
|
||||
|
||||
public function add(Living $entity, EffectInstance $instance) : void{
|
||||
$attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED);
|
||||
$attr->setValue($attr->getValue() * (1 - 0.15 * $instance->getEffectLevel()), true);
|
||||
$entity->setMovementSpeed($entity->getMovementSpeed() * (1 - 0.15 * $instance->getEffectLevel()), true);
|
||||
}
|
||||
|
||||
public function remove(Living $entity, EffectInstance $instance) : void{
|
||||
$attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED);
|
||||
$attr->setValue($attr->getValue() / (1 - 0.15 * $instance->getEffectLevel()));
|
||||
$entity->setMovementSpeed($entity->getMovementSpeed() / (1 - 0.15 * $instance->getEffectLevel()));
|
||||
}
|
||||
}
|
||||
|
@ -23,18 +23,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\entity\effect;
|
||||
|
||||
use pocketmine\entity\Attribute;
|
||||
use pocketmine\entity\Living;
|
||||
|
||||
class SpeedEffect extends Effect{
|
||||
|
||||
public function add(Living $entity, EffectInstance $instance) : void{
|
||||
$attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED);
|
||||
$attr->setValue($attr->getValue() * (1 + 0.2 * $instance->getEffectLevel()));
|
||||
$entity->setMovementSpeed($entity->getMovementSpeed() * (1 + 0.2 * $instance->getEffectLevel()));
|
||||
}
|
||||
|
||||
public function remove(Living $entity, EffectInstance $instance) : void{
|
||||
$attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED);
|
||||
$attr->setValue($attr->getValue() / (1 + 0.2 * $instance->getEffectLevel()));
|
||||
$entity->setMovementSpeed($entity->getMovementSpeed() / (1 + 0.2 * $instance->getEffectLevel()));
|
||||
}
|
||||
}
|
||||
|
@ -185,16 +185,6 @@ 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
|
||||
@ -210,26 +200,6 @@ parameters:
|
||||
count: 1
|
||||
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\\.$#"
|
||||
count: 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user