PocketMine-MP 5.23.3 git-fbaa125d0ce21ffef98fc1630881a92bedfbaa73
Loading...
Searching...
No Matches
AddActorPacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
23use function count;
24
26 public const NETWORK_ID = ProtocolInfo::ADD_ACTOR_PACKET;
27
28 public int $actorUniqueId;
29 public int $actorRuntimeId;
30 public string $type;
31 public Vector3 $position;
32 public ?Vector3 $motion = null;
33 public float $pitch = 0.0;
34 public float $yaw = 0.0;
35 public float $headYaw = 0.0;
36 public float $bodyYaw = 0.0; //???
37
39 public array $attributes = [];
44 public array $metadata = [];
45 public PropertySyncData $syncedProperties;
47 public array $links = [];
48
56 public static function create(
57 int $actorUniqueId,
58 int $actorRuntimeId,
59 string $type,
60 Vector3 $position,
61 ?Vector3 $motion,
62 float $pitch,
63 float $yaw,
64 float $headYaw,
65 float $bodyYaw,
66 array $attributes,
67 array $metadata,
68 PropertySyncData $syncedProperties,
69 array $links,
70 ) : self{
71 $result = new self;
72 $result->actorUniqueId = $actorUniqueId;
73 $result->actorRuntimeId = $actorRuntimeId;
74 $result->type = $type;
75 $result->position = $position;
76 $result->motion = $motion;
77 $result->pitch = $pitch;
78 $result->yaw = $yaw;
79 $result->headYaw = $headYaw;
80 $result->bodyYaw = $bodyYaw;
81 $result->attributes = $attributes;
82 $result->metadata = $metadata;
83 $result->syncedProperties = $syncedProperties;
84 $result->links = $links;
85 return $result;
86 }
87
88 protected function decodePayload(PacketSerializer $in) : void{
89 $this->actorUniqueId = $in->getActorUniqueId();
90 $this->actorRuntimeId = $in->getActorRuntimeId();
91 $this->type = $in->getString();
92 $this->position = $in->getVector3();
93 $this->motion = $in->getVector3();
94 $this->pitch = $in->getLFloat();
95 $this->yaw = $in->getLFloat();
96 $this->headYaw = $in->getLFloat();
97 $this->bodyYaw = $in->getLFloat();
98
99 $attrCount = $in->getUnsignedVarInt();
100 for($i = 0; $i < $attrCount; ++$i){
101 $id = $in->getString();
102 $min = $in->getLFloat();
103 $current = $in->getLFloat();
104 $max = $in->getLFloat();
105 $this->attributes[] = new Attribute($id, $min, $max, $current, $current, []);
106 }
107
108 $this->metadata = $in->getEntityMetadata();
109 $this->syncedProperties = PropertySyncData::read($in);
110
111 $linkCount = $in->getUnsignedVarInt();
112 for($i = 0; $i < $linkCount; ++$i){
113 $this->links[] = $in->getEntityLink();
114 }
115 }
116
117 protected function encodePayload(PacketSerializer $out) : void{
118 $out->putActorUniqueId($this->actorUniqueId);
119 $out->putActorRuntimeId($this->actorRuntimeId);
120 $out->putString($this->type);
121 $out->putVector3($this->position);
122 $out->putVector3Nullable($this->motion);
123 $out->putLFloat($this->pitch);
124 $out->putLFloat($this->yaw);
125 $out->putLFloat($this->headYaw);
126 $out->putLFloat($this->bodyYaw);
127
128 $out->putUnsignedVarInt(count($this->attributes));
129 foreach($this->attributes as $attribute){
130 $out->putString($attribute->getId());
131 $out->putLFloat($attribute->getMin());
132 $out->putLFloat($attribute->getCurrent());
133 $out->putLFloat($attribute->getMax());
134 }
135
136 $out->putEntityMetadata($this->metadata);
137 $this->syncedProperties->write($out);
138
139 $out->putUnsignedVarInt(count($this->links));
140 foreach($this->links as $link){
141 $out->putEntityLink($link);
142 }
143 }
144
145 public function handle(PacketHandlerInterface $handler) : bool{
146 return $handler->handleAddActor($this);
147 }
148}
static create(int $actorUniqueId, int $actorRuntimeId, string $type, Vector3 $position, ?Vector3 $motion, float $pitch, float $yaw, float $headYaw, float $bodyYaw, array $attributes, array $metadata, PropertySyncData $syncedProperties, array $links,)