use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; use pocketmine\network\mcpe\protocol\types\entity\Attribute; use pocketmine\network\mcpe\protocol\types\entity\EntityLink; use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty; use function count; class AddActorPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::ADD_ACTOR_PACKET; /** @var int|null */ public $entityUniqueId = null; //TODO /** @var int */ public $entityRuntimeId; /** @var string */ public $type; /** @var Vector3 */ public $position; /** @var Vector3|null */ public $motion; /** @var float */ public $pitch = 0.0; /** @var float */ public $yaw = 0.0; /** @var float */ public $headYaw = 0.0; /** @var Attribute[] */ public $attributes = []; /** * @var MetadataProperty[] * @phpstan-var array */ public $metadata = []; /** @var EntityLink[] */ public $links = []; protected function decodePayload(PacketSerializer $in) : void{ $this->entityUniqueId = $in->getEntityUniqueId(); $this->entityRuntimeId = $in->getEntityRuntimeId(); $this->type = $in->getString(); $this->position = $in->getVector3(); $this->motion = $in->getVector3(); $this->pitch = $in->getLFloat(); $this->yaw = $in->getLFloat(); $this->headYaw = $in->getLFloat(); $attrCount = $in->getUnsignedVarInt(); for($i = 0; $i < $attrCount; ++$i){ $id = $in->getString(); $min = $in->getLFloat(); $current = $in->getLFloat(); $max = $in->getLFloat(); $this->attributes[] = new Attribute($id, $min, $max, $current, $current); } $this->metadata = $in->getEntityMetadata(); $linkCount = $in->getUnsignedVarInt(); for($i = 0; $i < $linkCount; ++$i){ $this->links[] = $in->getEntityLink(); } } protected function encodePayload(PacketSerializer $out) : void{ $out->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); $out->putEntityRuntimeId($this->entityRuntimeId); $out->putString($this->type); $out->putVector3($this->position); $out->putVector3Nullable($this->motion); $out->putLFloat($this->pitch); $out->putLFloat($this->yaw); $out->putLFloat($this->headYaw); $out->putUnsignedVarInt(count($this->attributes)); foreach($this->attributes as $attribute){ $out->putString($attribute->getId()); $out->putLFloat($attribute->getMin()); $out->putLFloat($attribute->getCurrent()); $out->putLFloat($attribute->getMax()); } $out->putEntityMetadata($this->metadata); $out->putUnsignedVarInt(count($this->links)); foreach($this->links as $link){ $out->putEntityLink($link); } } public function handle(PacketHandlerInterface $handler) : bool{ return $handler->handleAddActor($this); } }