mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 00:39:45 +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\Vector2;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\ListTag;
|
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
use pocketmine\network\mcpe\protocol\AddActorPacket;
|
use pocketmine\network\mcpe\protocol\AddActorPacket;
|
||||||
use pocketmine\network\mcpe\protocol\MoveActorAbsolutePacket;
|
use pocketmine\network\mcpe\protocol\MoveActorAbsolutePacket;
|
||||||
@ -240,11 +239,10 @@ abstract class Entity{
|
|||||||
throw new \InvalidStateException("Cannot create entities in unloaded chunks");
|
throw new \InvalidStateException("Cannot create entities in unloaded chunks");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->motion = new Vector3(0, 0, 0);
|
if($nbt !== null){
|
||||||
if($nbt !== null and $nbt->hasTag("Motion", ListTag::class)){
|
$this->motion = EntityFactory::parseVec3($nbt, "Motion", true);
|
||||||
/** @var float[] $motion */
|
}else{
|
||||||
$motion = $nbt->getListTag("Motion")->getAllValues();
|
$this->motion = new Vector3(0, 0, 0);
|
||||||
$this->setMotion($this->temporalVector->setComponents(...$motion));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->resetLastMovements();
|
$this->resetLastMovements();
|
||||||
|
@ -290,7 +290,7 @@ final class EntityFactory{
|
|||||||
return Location::fromObject($pos, $world, $values[0]->getValue(), $values[1]->getValue());
|
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);
|
$pos = $nbt->getTag($tagName);
|
||||||
if($pos === null and $optional){
|
if($pos === null and $optional){
|
||||||
return new Vector3(0, 0, 0);
|
return new Vector3(0, 0, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user