diff --git a/src/entity/Attribute.php b/src/entity/Attribute.php index e65c1fed5..7ce9af10b 100644 --- a/src/entity/Attribute.php +++ b/src/entity/Attribute.php @@ -60,22 +60,22 @@ class Attribute{ protected static $attributes = []; public static function init() : void{ - self::addAttribute(self::ABSORPTION, 0.00, 340282346638528859811704183484516925440.00, 0.00); - self::addAttribute(self::SATURATION, 0.00, 20.00, 20.00); - self::addAttribute(self::EXHAUSTION, 0.00, 5.00, 0.0, false); - self::addAttribute(self::KNOCKBACK_RESISTANCE, 0.00, 1.00, 0.00); - self::addAttribute(self::HEALTH, 0.00, 20.00, 20.00); - self::addAttribute(self::MOVEMENT_SPEED, 0.00, 340282346638528859811704183484516925440.00, 0.10); - self::addAttribute(self::FOLLOW_RANGE, 0.00, 2048.00, 16.00, false); - self::addAttribute(self::HUNGER, 0.00, 20.00, 20.00); - self::addAttribute(self::ATTACK_DAMAGE, 0.00, 340282346638528859811704183484516925440.00, 1.00, false); - self::addAttribute(self::EXPERIENCE_LEVEL, 0.00, 24791.00, 0.00); - self::addAttribute(self::EXPERIENCE, 0.00, 1.00, 0.00); - self::addAttribute(self::UNDERWATER_MOVEMENT, 0.0, 340282346638528859811704183484516925440.0, 0.02); - self::addAttribute(self::LUCK, -1024.0, 1024.0, 0.0); - self::addAttribute(self::FALL_DAMAGE, 0.0, 340282346638528859811704183484516925440.0, 1.0); - self::addAttribute(self::HORSE_JUMP_STRENGTH, 0.0, 2.0, 0.7); - self::addAttribute(self::ZOMBIE_SPAWN_REINFORCEMENTS, 0.0, 1.0, 0.0); + self::register(self::ABSORPTION, 0.00, 340282346638528859811704183484516925440.00, 0.00); + self::register(self::SATURATION, 0.00, 20.00, 20.00); + self::register(self::EXHAUSTION, 0.00, 5.00, 0.0, false); + self::register(self::KNOCKBACK_RESISTANCE, 0.00, 1.00, 0.00); + self::register(self::HEALTH, 0.00, 20.00, 20.00); + self::register(self::MOVEMENT_SPEED, 0.00, 340282346638528859811704183484516925440.00, 0.10); + self::register(self::FOLLOW_RANGE, 0.00, 2048.00, 16.00, false); + self::register(self::HUNGER, 0.00, 20.00, 20.00); + self::register(self::ATTACK_DAMAGE, 0.00, 340282346638528859811704183484516925440.00, 1.00, false); + self::register(self::EXPERIENCE_LEVEL, 0.00, 24791.00, 0.00); + self::register(self::EXPERIENCE, 0.00, 1.00, 0.00); + self::register(self::UNDERWATER_MOVEMENT, 0.0, 340282346638528859811704183484516925440.0, 0.02); + self::register(self::LUCK, -1024.0, 1024.0, 0.0); + self::register(self::FALL_DAMAGE, 0.0, 340282346638528859811704183484516925440.0, 1.0); + self::register(self::HORSE_JUMP_STRENGTH, 0.0, 2.0, 0.7); + self::register(self::ZOMBIE_SPAWN_REINFORCEMENTS, 0.0, 1.0, 0.0); } /** @@ -89,7 +89,7 @@ class Attribute{ * * @throws \InvalidArgumentException */ - public static function addAttribute(string $id, float $minValue, float $maxValue, float $defaultValue, bool $shouldSend = true) : Attribute{ + public static function register(string $id, float $minValue, float $maxValue, float $defaultValue, bool $shouldSend = true) : Attribute{ if($minValue > $maxValue or $defaultValue > $maxValue or $defaultValue < $minValue){ throw new \InvalidArgumentException("Invalid ranges: min value: $minValue, max value: $maxValue, $defaultValue: $defaultValue"); } @@ -102,7 +102,7 @@ class Attribute{ * * @return Attribute|null */ - public static function getAttribute(string $id) : ?Attribute{ + public static function get(string $id) : ?Attribute{ return isset(self::$attributes[$id]) ? clone self::$attributes[$id] : null; } diff --git a/src/entity/AttributeMap.php b/src/entity/AttributeMap.php index 725db5069..c04223938 100644 --- a/src/entity/AttributeMap.php +++ b/src/entity/AttributeMap.php @@ -29,7 +29,7 @@ class AttributeMap implements \ArrayAccess{ /** @var Attribute[] */ private $attributes = []; - public function addAttribute(Attribute $attribute) : void{ + public function add(Attribute $attribute) : void{ $this->attributes[$attribute->getId()] = $attribute; } @@ -38,7 +38,7 @@ class AttributeMap implements \ArrayAccess{ * * @return Attribute|null */ - public function getAttribute(string $id) : ?Attribute{ + public function get(string $id) : ?Attribute{ return $this->attributes[$id] ?? null; } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index c046d6433..38f12a692 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -390,7 +390,7 @@ abstract class Entity extends Location{ public function setSprinting(bool $value = true) : void{ if($value !== $this->isSprinting()){ $this->sprinting = $value; - $attr = $this->attributeMap->getAttribute(Attribute::MOVEMENT_SPEED); + $attr = $this->attributeMap->get(Attribute::MOVEMENT_SPEED); $attr->setValue($value ? ($attr->getValue() * 1.3) : ($attr->getValue() / 1.3), false, true); } } diff --git a/src/entity/ExperienceManager.php b/src/entity/ExperienceManager.php index 969972047..1c963c43c 100644 --- a/src/entity/ExperienceManager.php +++ b/src/entity/ExperienceManager.php @@ -58,8 +58,8 @@ class ExperienceManager{ } private static function fetchAttribute(Entity $entity, string $attributeId) : Attribute{ - $entity->getAttributeMap()->addAttribute(Attribute::getAttribute($attributeId)); - return $entity->getAttributeMap()->getAttribute($attributeId); + $entity->getAttributeMap()->add(Attribute::get($attributeId)); + return $entity->getAttributeMap()->get($attributeId); } /** diff --git a/src/entity/HungerManager.php b/src/entity/HungerManager.php index f13e55afc..77e162c9b 100644 --- a/src/entity/HungerManager.php +++ b/src/entity/HungerManager.php @@ -57,8 +57,8 @@ class HungerManager{ } private static function fetchAttribute(Entity $entity, string $attributeId) : Attribute{ - $entity->getAttributeMap()->addAttribute(Attribute::getAttribute($attributeId)); - return $entity->getAttributeMap()->getAttribute($attributeId); + $entity->getAttributeMap()->add(Attribute::get($attributeId)); + return $entity->getAttributeMap()->get($attributeId); } public function getFood() : float{ diff --git a/src/entity/Living.php b/src/entity/Living.php index d7be4444e..df4836699 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -145,37 +145,37 @@ abstract class Living extends Entity{ } protected function addAttributes() : void{ - $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::HEALTH)); - $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::FOLLOW_RANGE)); - $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::KNOCKBACK_RESISTANCE)); - $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::MOVEMENT_SPEED)); - $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::ATTACK_DAMAGE)); - $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::ABSORPTION)); + $this->attributeMap->add(Attribute::get(Attribute::HEALTH)); + $this->attributeMap->add(Attribute::get(Attribute::FOLLOW_RANGE)); + $this->attributeMap->add(Attribute::get(Attribute::KNOCKBACK_RESISTANCE)); + $this->attributeMap->add(Attribute::get(Attribute::MOVEMENT_SPEED)); + $this->attributeMap->add(Attribute::get(Attribute::ATTACK_DAMAGE)); + $this->attributeMap->add(Attribute::get(Attribute::ABSORPTION)); } public function setHealth(float $amount) : void{ $wasAlive = $this->isAlive(); parent::setHealth($amount); - $this->attributeMap->getAttribute(Attribute::HEALTH)->setValue(ceil($this->getHealth()), true); + $this->attributeMap->get(Attribute::HEALTH)->setValue(ceil($this->getHealth()), true); if($this->isAlive() and !$wasAlive){ $this->broadcastEntityEvent(ActorEventPacket::RESPAWN); } } public function getMaxHealth() : int{ - return (int) $this->attributeMap->getAttribute(Attribute::HEALTH)->getMaxValue(); + return (int) $this->attributeMap->get(Attribute::HEALTH)->getMaxValue(); } public function setMaxHealth(int $amount) : void{ - $this->attributeMap->getAttribute(Attribute::HEALTH)->setMaxValue($amount)->setDefaultValue($amount); + $this->attributeMap->get(Attribute::HEALTH)->setMaxValue($amount)->setDefaultValue($amount); } public function getAbsorption() : float{ - return $this->attributeMap->getAttribute(Attribute::ABSORPTION)->getValue(); + return $this->attributeMap->get(Attribute::ABSORPTION)->getValue(); } public function setAbsorption(float $absorption) : void{ - $this->attributeMap->getAttribute(Attribute::ABSORPTION)->setValue($absorption); + $this->attributeMap->get(Attribute::ABSORPTION)->setValue($absorption); } public function saveNBT() : CompoundTag{ @@ -476,7 +476,7 @@ abstract class Living extends Entity{ if($f <= 0){ return; } - if(mt_rand() / mt_getrandmax() > $this->getAttributeMap()->getAttribute(Attribute::KNOCKBACK_RESISTANCE)->getValue()){ + if(mt_rand() / mt_getrandmax() > $this->getAttributeMap()->get(Attribute::KNOCKBACK_RESISTANCE)->getValue()){ $f = 1 / $f; $motion = clone $this->motion; diff --git a/src/entity/effect/SlownessEffect.php b/src/entity/effect/SlownessEffect.php index 8fbbc9912..a2604a1ba 100644 --- a/src/entity/effect/SlownessEffect.php +++ b/src/entity/effect/SlownessEffect.php @@ -29,12 +29,12 @@ use pocketmine\entity\Living; class SlownessEffect extends Effect{ public function add(Living $entity, EffectInstance $instance) : void{ - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED); $attr->setValue($attr->getValue() * (1 - 0.15 * $instance->getEffectLevel()), true); } public function remove(Living $entity, EffectInstance $instance) : void{ - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED); $attr->setValue($attr->getValue() / (1 - 0.15 * $instance->getEffectLevel())); } } diff --git a/src/entity/effect/SpeedEffect.php b/src/entity/effect/SpeedEffect.php index 5f0cc29f5..caafe0b74 100644 --- a/src/entity/effect/SpeedEffect.php +++ b/src/entity/effect/SpeedEffect.php @@ -29,12 +29,12 @@ use pocketmine\entity\Living; class SpeedEffect extends Effect{ public function add(Living $entity, EffectInstance $instance) : void{ - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED); $attr->setValue($attr->getValue() * (1 + 0.2 * $instance->getEffectLevel())); } public function remove(Living $entity, EffectInstance $instance) : void{ - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED); $attr->setValue($attr->getValue() / (1 + 0.2 * $instance->getEffectLevel())); } } diff --git a/src/network/mcpe/protocol/AddActorPacket.php b/src/network/mcpe/protocol/AddActorPacket.php index cea94a301..ecc4f09c0 100644 --- a/src/network/mcpe/protocol/AddActorPacket.php +++ b/src/network/mcpe/protocol/AddActorPacket.php @@ -189,7 +189,7 @@ class AddActorPacket extends DataPacket implements ClientboundPacket{ $min = $this->getLFloat(); $current = $this->getLFloat(); $max = $this->getLFloat(); - $attr = Attribute::getAttribute($id); + $attr = Attribute::get($id); if($attr !== null){ try{ diff --git a/src/network/mcpe/serializer/NetworkBinaryStream.php b/src/network/mcpe/serializer/NetworkBinaryStream.php index 42919c621..2aa9e12de 100644 --- a/src/network/mcpe/serializer/NetworkBinaryStream.php +++ b/src/network/mcpe/serializer/NetworkBinaryStream.php @@ -299,7 +299,7 @@ class NetworkBinaryStream extends BinaryStream{ $default = $this->getLFloat(); $id = $this->getString(); - $attr = Attribute::getAttribute($id); + $attr = Attribute::get($id); if($attr !== null){ $attr->setMinValue($min); $attr->setMaxValue($max);