diff --git a/src/entity/Entity.php b/src/entity/Entity.php index f44ba784c..f529db489 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -41,7 +41,6 @@ use pocketmine\math\Facing; use pocketmine\math\Vector2; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\StringTag; use pocketmine\network\mcpe\protocol\AddActorPacket; use pocketmine\network\mcpe\protocol\MoveActorAbsolutePacket; @@ -240,11 +239,10 @@ abstract class Entity{ throw new \InvalidStateException("Cannot create entities in unloaded chunks"); } - $this->motion = new Vector3(0, 0, 0); - if($nbt !== null and $nbt->hasTag("Motion", ListTag::class)){ - /** @var float[] $motion */ - $motion = $nbt->getListTag("Motion")->getAllValues(); - $this->setMotion($this->temporalVector->setComponents(...$motion)); + if($nbt !== null){ + $this->motion = EntityFactory::parseVec3($nbt, "Motion", true); + }else{ + $this->motion = new Vector3(0, 0, 0); } $this->resetLastMovements(); diff --git a/src/entity/EntityFactory.php b/src/entity/EntityFactory.php index d74b206ac..ef0bbcb2b 100644 --- a/src/entity/EntityFactory.php +++ b/src/entity/EntityFactory.php @@ -290,7 +290,7 @@ final class EntityFactory{ return Location::fromObject($pos, $world, $values[0]->getValue(), $values[1]->getValue()); } - private static function parseVec3(CompoundTag $nbt, string $tagName, bool $optional) : Vector3{ + public static function parseVec3(CompoundTag $nbt, string $tagName, bool $optional) : Vector3{ $pos = $nbt->getTag($tagName); if($pos === null and $optional){ return new Vector3(0, 0, 0);