Skip to content

Commit

Permalink
Backward compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
AkmalFairuz committed Aug 15, 2024
1 parent 9687bbb commit ea8a2ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/InventoryContentPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions src/MobArmorEquipmentPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/inventory/ContainerUIIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit ea8a2ec

Please sign in to comment.