diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 4d4442c63..a020c56d6 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -40,6 +40,9 @@ use pocketmine\math\Facing; use pocketmine\math\Vector2; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; +use pocketmine\nbt\tag\DoubleTag; +use pocketmine\nbt\tag\FloatTag; +use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\StringTag; use pocketmine\network\mcpe\protocol\AddActorPacket; use pocketmine\network\mcpe\protocol\MoveActorAbsolutePacket; @@ -459,7 +462,21 @@ abstract class Entity{ } public function saveNBT() : CompoundTag{ - $nbt = EntityDataHelper::createBaseNBT($this->location, $this->motion, $this->location->yaw, $this->location->pitch); + $nbt = CompoundTag::create() + ->setTag("Pos", new ListTag([ + new DoubleTag($this->location->x), + new DoubleTag($this->location->y), + new DoubleTag($this->location->z) + ])) + ->setTag("Motion", new ListTag([ + new DoubleTag($this->motion->x), + new DoubleTag($this->motion->y), + new DoubleTag($this->motion->z) + ])) + ->setTag("Rotation", new ListTag([ + new FloatTag($this->location->yaw), + new FloatTag($this->location->pitch) + ])); if(!($this instanceof Player)){ EntityFactory::getInstance()->injectSaveId(get_class($this), $nbt); diff --git a/src/entity/EntityDataHelper.php b/src/entity/EntityDataHelper.php index e4632aa07..f58fef743 100644 --- a/src/entity/EntityDataHelper.php +++ b/src/entity/EntityDataHelper.php @@ -69,25 +69,4 @@ final class EntityDataHelper{ } return new Vector3($values[0]->getValue(), $values[1]->getValue(), $values[2]->getValue()); } - - /** - * Helper function which creates minimal NBT needed to spawn an entity. - */ - public static function createBaseNBT(Vector3 $pos, ?Vector3 $motion = null, float $yaw = 0.0, float $pitch = 0.0) : CompoundTag{ - return CompoundTag::create() - ->setTag("Pos", new ListTag([ - new DoubleTag($pos->x), - new DoubleTag($pos->y), - new DoubleTag($pos->z) - ])) - ->setTag("Motion", new ListTag([ - new DoubleTag($motion !== null ? $motion->x : 0.0), - new DoubleTag($motion !== null ? $motion->y : 0.0), - new DoubleTag($motion !== null ? $motion->z : 0.0) - ])) - ->setTag("Rotation", new ListTag([ - new FloatTag($yaw), - new FloatTag($pitch) - ])); - } }