mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-11 00:09:39 +00:00
Entity: use EntityFactory helper function to deserialize Motion
This commit is contained in:
parent
4b528aa637
commit
60a6b4b10d
@ -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();
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user