|
14 | 14 |
|
15 | 15 | namespace pocketmine\network\mcpe\protocol;
|
16 | 16 |
|
| 17 | +use pmmp\encoding\ByteBufferReader; |
| 18 | +use pmmp\encoding\ByteBufferWriter; |
| 19 | +use pmmp\encoding\LE; |
| 20 | +use pmmp\encoding\VarInt; |
17 | 21 | use pocketmine\math\Vector3;
|
18 |
| -use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; |
| 22 | +use pocketmine\network\mcpe\protocol\serializer\CommonTypes; |
19 | 23 | use pocketmine\network\mcpe\protocol\types\entity\Attribute;
|
20 | 24 | use pocketmine\network\mcpe\protocol\types\entity\EntityLink;
|
21 | 25 | use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty;
|
@@ -85,60 +89,60 @@ public static function create(
|
85 | 89 | return $result;
|
86 | 90 | }
|
87 | 91 |
|
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(); |
| 92 | + protected function decodePayload(ByteBufferReader $in) : void{ |
| 93 | + $this->actorUniqueId = CommonTypes::getActorUniqueId($in); |
| 94 | + $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in); |
| 95 | + $this->type = CommonTypes::getString($in); |
| 96 | + $this->position = CommonTypes::getVector3($in); |
| 97 | + $this->motion = CommonTypes::getVector3($in); |
| 98 | + $this->pitch = LE::readFloat($in); |
| 99 | + $this->yaw = LE::readFloat($in); |
| 100 | + $this->headYaw = LE::readFloat($in); |
| 101 | + $this->bodyYaw = LE::readFloat($in); |
| 102 | + |
| 103 | + $attrCount = VarInt::readUnsignedInt($in); |
100 | 104 | for($i = 0; $i < $attrCount; ++$i){
|
101 |
| - $id = $in->getString(); |
102 |
| - $min = $in->getLFloat(); |
103 |
| - $current = $in->getLFloat(); |
104 |
| - $max = $in->getLFloat(); |
| 105 | + $id = CommonTypes::getString($in); |
| 106 | + $min = LE::readFloat($in); |
| 107 | + $current = LE::readFloat($in); |
| 108 | + $max = LE::readFloat($in); |
105 | 109 | $this->attributes[] = new Attribute($id, $min, $max, $current, $current, []);
|
106 | 110 | }
|
107 | 111 |
|
108 |
| - $this->metadata = $in->getEntityMetadata(); |
| 112 | + $this->metadata = CommonTypes::getEntityMetadata($in); |
109 | 113 | $this->syncedProperties = PropertySyncData::read($in);
|
110 | 114 |
|
111 |
| - $linkCount = $in->getUnsignedVarInt(); |
| 115 | + $linkCount = VarInt::readUnsignedInt($in); |
112 | 116 | for($i = 0; $i < $linkCount; ++$i){
|
113 |
| - $this->links[] = $in->getEntityLink(); |
| 117 | + $this->links[] = CommonTypes::getEntityLink($in); |
114 | 118 | }
|
115 | 119 | }
|
116 | 120 |
|
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)); |
| 121 | + protected function encodePayload(ByteBufferWriter $out) : void{ |
| 122 | + CommonTypes::putActorUniqueId($out, $this->actorUniqueId); |
| 123 | + CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId); |
| 124 | + CommonTypes::putString($out, $this->type); |
| 125 | + CommonTypes::putVector3($out, $this->position); |
| 126 | + CommonTypes::putVector3Nullable($out, $this->motion); |
| 127 | + LE::writeFloat($out, $this->pitch); |
| 128 | + LE::writeFloat($out, $this->yaw); |
| 129 | + LE::writeFloat($out, $this->headYaw); |
| 130 | + LE::writeFloat($out, $this->bodyYaw); |
| 131 | + |
| 132 | + VarInt::writeUnsignedInt($out, count($this->attributes)); |
129 | 133 | 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 | + CommonTypes::putString($out, $attribute->getId()); |
| 135 | + LE::writeFloat($out, $attribute->getMin()); |
| 136 | + LE::writeFloat($out, $attribute->getCurrent()); |
| 137 | + LE::writeFloat($out, $attribute->getMax()); |
134 | 138 | }
|
135 | 139 |
|
136 |
| - $out->putEntityMetadata($this->metadata); |
| 140 | + CommonTypes::putEntityMetadata($out, $this->metadata); |
137 | 141 | $this->syncedProperties->write($out);
|
138 | 142 |
|
139 |
| - $out->putUnsignedVarInt(count($this->links)); |
| 143 | + VarInt::writeUnsignedInt($out, count($this->links)); |
140 | 144 | foreach($this->links as $link){
|
141 |
| - $out->putEntityLink($link); |
| 145 | + CommonTypes::putEntityLink($out, $link); |
142 | 146 | }
|
143 | 147 | }
|
144 | 148 |
|
|
0 commit comments