From ea8a2ec84c4ced80766658d0594d81d1c5d38092 Mon Sep 17 00:00:00 2001 From: AkmalFairuz Date: Thu, 15 Aug 2024 12:58:02 +0700 Subject: [PATCH] Backward compatible --- src/InventoryContentPacket.php | 2 +- src/MobArmorEquipmentPacket.php | 11 ++++++++--- src/types/inventory/ContainerUIIds.php | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/InventoryContentPacket.php b/src/InventoryContentPacket.php index 7b6b5702..b9b6a7f6 100644 --- a/src/InventoryContentPacket.php +++ b/src/InventoryContentPacket.php @@ -30,7 +30,7 @@ class InventoryContentPacket extends DataPacket implements ClientboundPacket{ * @generate-create-func * @param ItemStackWrapper[] $items */ - public static function create(int $windowId, array $items, int $dynamicContainerId) : self{ + public static function create(int $windowId, array $items, int $dynamicContainerId = 0) : self{ $result = new self; $result->windowId = $windowId; $result->items = $items; diff --git a/src/MobArmorEquipmentPacket.php b/src/MobArmorEquipmentPacket.php index d5262cef..c7d37d6f 100644 --- a/src/MobArmorEquipmentPacket.php +++ b/src/MobArmorEquipmentPacket.php @@ -15,6 +15,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; +use pocketmine\network\mcpe\protocol\types\inventory\ItemStack; use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper; class MobArmorEquipmentPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ @@ -27,12 +28,12 @@ class MobArmorEquipmentPacket extends DataPacket implements ClientboundPacket, S public ItemStackWrapper $chest; public ItemStackWrapper $legs; public ItemStackWrapper $feet; - public ItemStackWrapper $body; + public ?ItemStackWrapper $body; /** * @generate-create-func */ - public static function create(int $actorRuntimeId, ItemStackWrapper $head, ItemStackWrapper $chest, ItemStackWrapper $legs, ItemStackWrapper $feet, ItemStackWrapper $body) : self{ + public static function create(int $actorRuntimeId, ItemStackWrapper $head, ItemStackWrapper $chest, ItemStackWrapper $legs, ItemStackWrapper $feet, ?ItemStackWrapper $body = null) : self{ $result = new self; $result->actorRuntimeId = $actorRuntimeId; $result->head = $head; @@ -61,7 +62,11 @@ protected function encodePayload(PacketSerializer $out) : void{ $this->legs->write($out); $this->feet->write($out); if($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){ - $this->body->write($out); + if($this->body === null){ + (new ItemStackWrapper(0, ItemStack::null()))->write($out); + }else{ + $this->body->write($out); + } } } diff --git a/src/types/inventory/ContainerUIIds.php b/src/types/inventory/ContainerUIIds.php index b36005e7..863dd310 100644 --- a/src/types/inventory/ContainerUIIds.php +++ b/src/types/inventory/ContainerUIIds.php @@ -104,7 +104,7 @@ public static function write(PacketSerializer $out, int $containerId, bool $lega $out->putByte($containerId); } - public static function read(PacketSerializer $in, bool $legacy = false) : ?int{ + public static function read(PacketSerializer $in, bool $legacy = false) : int{ if($in->getProtocol() >= ProtocolInfo::PROTOCOL_712 && !$legacy){ return FullContainerName::read($in)->getContainerId(); }