diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 77de5256f..e2e228c8f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1641,7 +1641,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->achievements = []; - /** @var Byte $achievement */ + /** @var ByteTag $achievement */ foreach($nbt->Achievements as $achievement){ $this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false; } diff --git a/src/pocketmine/entity/Attribute.php b/src/pocketmine/entity/Attribute.php index 62b9b6916..f6fb4b238 100644 --- a/src/pocketmine/entity/Attribute.php +++ b/src/pocketmine/entity/Attribute.php @@ -56,9 +56,9 @@ class Attribute{ self::addAttribute(self::KNOCKBACK_RESISTANCE, "generic.knockbackResistance", 0.00, 1.00, 0.00); self::addAttribute(self::HEALTH, "generic.health", 0.00, 20.00, 20.00); self::addAttribute(self::MOVEMENT_SPEED, "generic.movementSpeed", 0.00, 340282346638528859811704183484516925440.00, 0.10); - self::addAttribute(self::FOLLOW_RANGE, "generic.followRange", 0.00, 2048.00, 16.00); + self::addAttribute(self::FOLLOW_RANGE, "generic.followRange", 0.00, 2048.00, 16.00, false); self::addAttribute(self::HUNGER, "player.hunger", 0.00, 20.00, 20.00); - self::addAttribute(self::ATTACK_DAMAGE, "generic.attackDamage", 0.00, 340282346638528859811704183484516925440.00, 1.00); + self::addAttribute(self::ATTACK_DAMAGE, "generic.attackDamage", 0.00, 340282346638528859811704183484516925440.00, 1.00, false); self::addAttribute(self::EXPERIENCE_LEVEL, "player.level", 0.00, 24791.00, 0.00); self::addAttribute(self::EXPERIENCE, "player.experience", 0.00, 1.00, 0.00); } @@ -199,7 +199,7 @@ class Attribute{ return $this->shouldSend and $this->desynchronized; } - public function markSynchronized(){ - $this->desynchronized = false; + public function markSynchronized(bool $synced = true){ + $this->desynchronized = !$synced; } } diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 56f4ff660..c6f2e17d3 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -250,7 +250,7 @@ class Effect{ $this->color = (($r & 0xff) << 16) + (($g & 0xff) << 8) + ($b & 0xff); } - public function add(Entity $entity, $modify = false){ + public function add(Entity $entity, $modify = false, Effect $oldEffect = null){ if($entity instanceof Player){ $pk = new MobEffectPacket(); $pk->eid = 0; @@ -270,6 +270,24 @@ class Effect{ if($this->id === Effect::INVISIBILITY){ $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, true); $entity->setDataProperty(Entity::DATA_SHOW_NAMETAG, Entity::DATA_TYPE_BYTE, 0); + }elseif($this->id === Effect::SPEED){ + $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + if($modify and $oldEffect !== null){ + $speed = $attr->getValue() / (1 + 0.2 * $oldEffect->getAmplifier()); + }else{ + $speed = $attr->getValue(); + } + $speed *= (1 + 0.2 * $this->amplifier); + $attr->setValue($speed); + }elseif($this->id === Effect::SLOWNESS){ + $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + if($modify and $oldEffect !== null){ + $speed = $attr->getValue() / (1 - 0.15 * $oldEffect->getAmplifier()); + }else{ + $speed = $attr->getValue(); + } + $speed *= (1 - 0.15 * $this->amplifier); + $attr->setValue($speed); } } @@ -286,6 +304,12 @@ class Effect{ if($this->id === Effect::INVISIBILITY){ $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, false); $entity->setDataProperty(Entity::DATA_SHOW_NAMETAG, Entity::DATA_TYPE_BYTE, 1); + }elseif($this->id === Effect::SPEED){ + $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr->setValue($attr->getValue() / (1 + 0.2 * $this->amplifier)); + }elseif($this->id === Effect::SLOWNESS){ + $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr->setValue($attr->getValue() / (1 - 0.15 * $this->amplifier)); } } } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index eab6b1e49..e386379e6 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -319,7 +319,11 @@ abstract class Entity extends Location implements Metadatable{ } public function setSprinting($value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING, (bool) $value); + if($value !== $this->isSprinting()){ + $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING, (bool) $value); + $attr = $this->attributeMap->getAttribute(Attribute::MOVEMENT_SPEED); + $attr->setValue($value ? ($attr->getValue() * 1.3) : ($attr->getValue() / 1.3)); + } } /** @@ -363,7 +367,7 @@ abstract class Entity extends Location implements Metadatable{ ){ return; } - $effect->add($this, true); + $effect->add($this, true, $oldEffect); }else{ $effect->add($this, false); } @@ -408,10 +412,10 @@ abstract class Entity extends Location implements Metadatable{ } /** - * @param int|string $type - * @param FullChunk $chunk - * @param CompoundTag $nbt - * @param $args + * @param int|string $type + * @param FullChunk $chunk + * @param CompoundTag $nbt + * @param $args * * @return Entity */ @@ -506,6 +510,17 @@ abstract class Entity extends Location implements Metadatable{ protected function initEntity(){ assert($this->namedtag instanceof CompoundTag); + if(isset($this->namedtag->CustomName)){ + $this->setNameTag($this->namedtag["CustomName"]); + if(isset($this->namedtag->CustomNameVisible)){ + $this->setNameTagVisible($this->namedtag["CustomNameVisible"] > 0); + } + } + + $this->scheduleUpdate(); + + $this->addAttributes(); + if(isset($this->namedtag->ActiveEffects)){ foreach($this->namedtag->ActiveEffects->getValue() as $e){ $effect = Effect::getEffect($e["Id"]); @@ -518,18 +533,6 @@ abstract class Entity extends Location implements Metadatable{ $this->addEffect($effect); } } - - - if(isset($this->namedtag->CustomName)){ - $this->setNameTag($this->namedtag["CustomName"]); - if(isset($this->namedtag->CustomNameVisible)){ - $this->setNameTagVisible($this->namedtag["CustomNameVisible"] > 0); - } - } - - $this->scheduleUpdate(); - - $this->addAttributes(); } protected function addAttributes(){ @@ -1559,6 +1562,7 @@ abstract class Entity extends Location implements Metadatable{ * @param int $propertyId * @param int $id * @param bool $value + * @param int $type */ public function setDataFlag($propertyId, $id, $value = true, $type = self::DATA_TYPE_BYTE){ if($this->getDataFlag($propertyId, $id) !== $value){