Entity: use EntityFactory helper function to deserialize Motion

This commit is contained in:
Dylan K. Taylor 2020-06-19 10:18:31 +01:00
parent 4b528aa637
commit 60a6b4b10d
2 changed files with 5 additions and 7 deletions

View File

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

View File

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