Living: Do not rely on attribute map for moveSpeed attribute access

This commit is contained in:
Dylan K. Taylor
2020-05-21 20:13:24 +01:00
parent f77eea8c44
commit 1aa92bd6a8
4 changed files with 18 additions and 43 deletions

View File

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

View File

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