Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
ini-values: xdebug.max_nesting_level=3000
extensions: encoding-pmmp/[email protected]

- name: Load Composer package cache
uses: actions/cache@v4
Expand Down Expand Up @@ -49,6 +50,7 @@ jobs:
php-version: 8.2
ini-values: xdebug.max_nesting_level=3000
tools: php-cs-fixer:3
extensions: encoding-pmmp/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "library",
"require": {
"php": "^8.1",
"ext-encoding": "~1.0.0",
"ext-json": "*",
"pocketmine/binaryutils": "^0.2.0",
"pocketmine/color": "^0.2.0 || ^0.3.0",
Expand Down
22 changes: 13 additions & 9 deletions src/ActorEventPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

namespace pocketmine\network\mcpe\protocol;

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pmmp\encoding\Byte;
use pmmp\encoding\ByteBufferReader;
use pmmp\encoding\ByteBufferWriter;
use pmmp\encoding\VarInt;
use pocketmine\network\mcpe\protocol\serializer\CommonTypes;
use pocketmine\network\mcpe\protocol\types\ActorEvent;

class ActorEventPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{
Expand All @@ -36,16 +40,16 @@ public static function create(int $actorRuntimeId, int $eventId, int $eventData)
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->actorRuntimeId = $in->getActorRuntimeId();
$this->eventId = $in->getByte();
$this->eventData = $in->getVarInt();
protected function decodePayload(ByteBufferReader $in) : void{
$this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
$this->eventId = Byte::readUnsigned($in);
$this->eventData = VarInt::readSignedInt($in);
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putActorRuntimeId($this->actorRuntimeId);
$out->putByte($this->eventId);
$out->putVarInt($this->eventData);
protected function encodePayload(ByteBufferWriter $out) : void{
CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
Byte::writeUnsigned($out, $this->eventId);
VarInt::writeSignedInt($out, $this->eventData);
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
22 changes: 13 additions & 9 deletions src/ActorPickRequestPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

namespace pocketmine\network\mcpe\protocol;

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pmmp\encoding\Byte;
use pmmp\encoding\ByteBufferReader;
use pmmp\encoding\ByteBufferWriter;
use pmmp\encoding\LE;
use pocketmine\network\mcpe\protocol\serializer\CommonTypes;

class ActorPickRequestPacket extends DataPacket implements ServerboundPacket{
public const NETWORK_ID = ProtocolInfo::ACTOR_PICK_REQUEST_PACKET;
Expand All @@ -34,16 +38,16 @@ public static function create(int $actorUniqueId, int $hotbarSlot, bool $addUser
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->actorUniqueId = $in->getLLong();
$this->hotbarSlot = $in->getByte();
$this->addUserData = $in->getBool();
protected function decodePayload(ByteBufferReader $in) : void{
$this->actorUniqueId = LE::readSignedLong($in);
$this->hotbarSlot = Byte::readUnsigned($in);
$this->addUserData = CommonTypes::getBool($in);
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putLLong($this->actorUniqueId);
$out->putByte($this->hotbarSlot);
$out->putBool($this->addUserData);
protected function encodePayload(ByteBufferWriter $out) : void{
LE::writeSignedLong($out, $this->actorUniqueId);
Byte::writeUnsigned($out, $this->hotbarSlot);
CommonTypes::putBool($out, $this->addUserData);
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
82 changes: 43 additions & 39 deletions src/AddActorPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@

namespace pocketmine\network\mcpe\protocol;

use pmmp\encoding\ByteBufferReader;
use pmmp\encoding\ByteBufferWriter;
use pmmp\encoding\LE;
use pmmp\encoding\VarInt;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\serializer\CommonTypes;
use pocketmine\network\mcpe\protocol\types\entity\Attribute;
use pocketmine\network\mcpe\protocol\types\entity\EntityLink;
use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty;
Expand Down Expand Up @@ -85,60 +89,60 @@ public static function create(
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->actorUniqueId = $in->getActorUniqueId();
$this->actorRuntimeId = $in->getActorRuntimeId();
$this->type = $in->getString();
$this->position = $in->getVector3();
$this->motion = $in->getVector3();
$this->pitch = $in->getLFloat();
$this->yaw = $in->getLFloat();
$this->headYaw = $in->getLFloat();
$this->bodyYaw = $in->getLFloat();

$attrCount = $in->getUnsignedVarInt();
protected function decodePayload(ByteBufferReader $in) : void{
$this->actorUniqueId = CommonTypes::getActorUniqueId($in);
$this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
$this->type = CommonTypes::getString($in);
$this->position = CommonTypes::getVector3($in);
$this->motion = CommonTypes::getVector3($in);
$this->pitch = LE::readFloat($in);
$this->yaw = LE::readFloat($in);
$this->headYaw = LE::readFloat($in);
$this->bodyYaw = LE::readFloat($in);

$attrCount = VarInt::readUnsignedInt($in);
for($i = 0; $i < $attrCount; ++$i){
$id = $in->getString();
$min = $in->getLFloat();
$current = $in->getLFloat();
$max = $in->getLFloat();
$id = CommonTypes::getString($in);
$min = LE::readFloat($in);
$current = LE::readFloat($in);
$max = LE::readFloat($in);
$this->attributes[] = new Attribute($id, $min, $max, $current, $current, []);
}

$this->metadata = $in->getEntityMetadata();
$this->metadata = CommonTypes::getEntityMetadata($in);
$this->syncedProperties = PropertySyncData::read($in);

$linkCount = $in->getUnsignedVarInt();
$linkCount = VarInt::readUnsignedInt($in);
for($i = 0; $i < $linkCount; ++$i){
$this->links[] = $in->getEntityLink();
$this->links[] = CommonTypes::getEntityLink($in);
}
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putActorUniqueId($this->actorUniqueId);
$out->putActorRuntimeId($this->actorRuntimeId);
$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->putLFloat($this->bodyYaw);

$out->putUnsignedVarInt(count($this->attributes));
protected function encodePayload(ByteBufferWriter $out) : void{
CommonTypes::putActorUniqueId($out, $this->actorUniqueId);
CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
CommonTypes::putString($out, $this->type);
CommonTypes::putVector3($out, $this->position);
CommonTypes::putVector3Nullable($out, $this->motion);
LE::writeFloat($out, $this->pitch);
LE::writeFloat($out, $this->yaw);
LE::writeFloat($out, $this->headYaw);
LE::writeFloat($out, $this->bodyYaw);

VarInt::writeUnsignedInt($out, count($this->attributes));
foreach($this->attributes as $attribute){
$out->putString($attribute->getId());
$out->putLFloat($attribute->getMin());
$out->putLFloat($attribute->getCurrent());
$out->putLFloat($attribute->getMax());
CommonTypes::putString($out, $attribute->getId());
LE::writeFloat($out, $attribute->getMin());
LE::writeFloat($out, $attribute->getCurrent());
LE::writeFloat($out, $attribute->getMax());
}

$out->putEntityMetadata($this->metadata);
CommonTypes::putEntityMetadata($out, $this->metadata);
$this->syncedProperties->write($out);

$out->putUnsignedVarInt(count($this->links));
VarInt::writeUnsignedInt($out, count($this->links));
foreach($this->links as $link){
$out->putEntityLink($link);
CommonTypes::putEntityLink($out, $link);
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/AddBehaviorTreePacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

namespace pocketmine\network\mcpe\protocol;

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pmmp\encoding\ByteBufferReader;
use pmmp\encoding\ByteBufferWriter;
use pocketmine\network\mcpe\protocol\serializer\CommonTypes;

class AddBehaviorTreePacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::ADD_BEHAVIOR_TREE_PACKET;
Expand All @@ -30,12 +32,12 @@ public static function create(string $behaviorTreeJson) : self{
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->behaviorTreeJson = $in->getString();
protected function decodePayload(ByteBufferReader $in) : void{
$this->behaviorTreeJson = CommonTypes::getString($in);
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putString($this->behaviorTreeJson);
protected function encodePayload(ByteBufferWriter $out) : void{
CommonTypes::putString($out, $this->behaviorTreeJson);
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
36 changes: 19 additions & 17 deletions src/AddItemActorPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

namespace pocketmine\network\mcpe\protocol;

use pmmp\encoding\ByteBufferReader;
use pmmp\encoding\ByteBufferWriter;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\serializer\CommonTypes;
use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;

Expand Down Expand Up @@ -59,24 +61,24 @@ public static function create(
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->actorUniqueId = $in->getActorUniqueId();
$this->actorRuntimeId = $in->getActorRuntimeId();
$this->item = $in->getItemStackWrapper();
$this->position = $in->getVector3();
$this->motion = $in->getVector3();
$this->metadata = $in->getEntityMetadata();
$this->isFromFishing = $in->getBool();
protected function decodePayload(ByteBufferReader $in) : void{
$this->actorUniqueId = CommonTypes::getActorUniqueId($in);
$this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
$this->item = CommonTypes::getItemStackWrapper($in);
$this->position = CommonTypes::getVector3($in);
$this->motion = CommonTypes::getVector3($in);
$this->metadata = CommonTypes::getEntityMetadata($in);
$this->isFromFishing = CommonTypes::getBool($in);
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putActorUniqueId($this->actorUniqueId);
$out->putActorRuntimeId($this->actorRuntimeId);
$out->putItemStackWrapper($this->item);
$out->putVector3($this->position);
$out->putVector3Nullable($this->motion);
$out->putEntityMetadata($this->metadata);
$out->putBool($this->isFromFishing);
protected function encodePayload(ByteBufferWriter $out) : void{
CommonTypes::putActorUniqueId($out, $this->actorUniqueId);
CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
CommonTypes::putItemStackWrapper($out, $this->item);
CommonTypes::putVector3($out, $this->position);
CommonTypes::putVector3Nullable($out, $this->motion);
CommonTypes::putEntityMetadata($out, $this->metadata);
CommonTypes::putBool($out, $this->isFromFishing);
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
29 changes: 16 additions & 13 deletions src/AddPaintingPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

namespace pocketmine\network\mcpe\protocol;

use pmmp\encoding\ByteBufferReader;
use pmmp\encoding\ByteBufferWriter;
use pmmp\encoding\VarInt;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\serializer\CommonTypes;

class AddPaintingPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::ADD_PAINTING_PACKET;
Expand All @@ -39,20 +42,20 @@ public static function create(int $actorUniqueId, int $actorRuntimeId, Vector3 $
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->actorUniqueId = $in->getActorUniqueId();
$this->actorRuntimeId = $in->getActorRuntimeId();
$this->position = $in->getVector3();
$this->direction = $in->getVarInt();
$this->title = $in->getString();
protected function decodePayload(ByteBufferReader $in) : void{
$this->actorUniqueId = CommonTypes::getActorUniqueId($in);
$this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
$this->position = CommonTypes::getVector3($in);
$this->direction = VarInt::readSignedInt($in);
$this->title = CommonTypes::getString($in);
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putActorUniqueId($this->actorUniqueId);
$out->putActorRuntimeId($this->actorRuntimeId);
$out->putVector3($this->position);
$out->putVarInt($this->direction);
$out->putString($this->title);
protected function encodePayload(ByteBufferWriter $out) : void{
CommonTypes::putActorUniqueId($out, $this->actorUniqueId);
CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
CommonTypes::putVector3($out, $this->position);
VarInt::writeSignedInt($out, $this->direction);
CommonTypes::putString($out, $this->title);
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
Loading