From deba0448b9152883393c85c75e55f6adf421ecbc Mon Sep 17 00:00:00 2001 From: AkmalFairuz Date: Thu, 19 Sep 2024 16:41:00 +0700 Subject: [PATCH] Add 1.20.30 support --- src/EmotePacket.php | 14 +++++++++++++- src/InventoryContentPacket.php | 24 +++++++++++++++++++----- src/InventorySlotPacket.php | 23 ++++++++++++++++++----- src/ProtocolInfo.php | 4 +++- src/ResourcePacksInfoPacket.php | 24 ++++++++++++++++-------- src/TransferPacket.php | 10 +++++++++- src/serializer/PacketSerializer.php | 5 +++++ 7 files changed, 83 insertions(+), 21 deletions(-) diff --git a/src/EmotePacket.php b/src/EmotePacket.php index e176da38..6d71b406 100644 --- a/src/EmotePacket.php +++ b/src/EmotePacket.php @@ -24,6 +24,7 @@ class EmotePacket extends DataPacket implements ClientboundPacket, ServerboundPa private int $actorRuntimeId; private string $emoteId; + private int $emoteLengthTicks = 0; private string $xboxUserId; private string $platformChatId; private int $flags; @@ -31,10 +32,11 @@ class EmotePacket extends DataPacket implements ClientboundPacket, ServerboundPa /** * @generate-create-func */ - public static function create(int $actorRuntimeId, string $emoteId, string $xboxUserId, string $platformChatId, int $flags) : self{ + public static function create(int $actorRuntimeId, string $emoteId, string $xboxUserId, string $platformChatId, int $flags, int $emoteLengthTicks = 0) : self{ $result = new self; $result->actorRuntimeId = $actorRuntimeId; $result->emoteId = $emoteId; + $result->emoteLengthTicks = $emoteLengthTicks; $result->xboxUserId = $xboxUserId; $result->platformChatId = $platformChatId; $result->flags = $flags; @@ -49,6 +51,10 @@ public function getEmoteId() : string{ return $this->emoteId; } + public function getEmoteLengthTicks(): int { + return $this->emoteLengthTicks; + } + public function getXboxUserId() : string{ return $this->xboxUserId; } public function getPlatformChatId() : string{ return $this->platformChatId; } @@ -60,6 +66,9 @@ public function getFlags() : int{ protected function decodePayload(PacketSerializer $in) : void{ $this->actorRuntimeId = $in->getActorRuntimeId(); $this->emoteId = $in->getString(); + if($in->getProtocol() >= ProtocolInfo::PROTOCOL_729){ + $this->emoteLengthTicks = $in->getInt(); + } if($in->getProtocol() >= ProtocolInfo::PROTOCOL_589){ $this->xboxUserId = $in->getString(); $this->platformChatId = $in->getString(); @@ -73,6 +82,9 @@ protected function decodePayload(PacketSerializer $in) : void{ protected function encodePayload(PacketSerializer $out) : void{ $out->putActorRuntimeId($this->actorRuntimeId); $out->putString($this->emoteId); + if($out->getProtocol() >= ProtocolInfo::PROTOCOL_729){ + $out->putInt($this->emoteLengthTicks); + } if($out->getProtocol() >= ProtocolInfo::PROTOCOL_589){ $out->putString($this->xboxUserId); $out->putString($this->platformChatId); diff --git a/src/InventoryContentPacket.php b/src/InventoryContentPacket.php index b9b6a7f6..0cb2323a 100644 --- a/src/InventoryContentPacket.php +++ b/src/InventoryContentPacket.php @@ -15,6 +15,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; +use pocketmine\network\mcpe\protocol\types\inventory\FullContainerName; use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper; use function count; @@ -24,17 +25,19 @@ class InventoryContentPacket extends DataPacket implements ClientboundPacket{ public int $windowId; /** @var ItemStackWrapper[] */ public array $items = []; - public int $dynamicContainerId; + public FullContainerName $containerName; + public int $dynamicContainerSize = 0; /** * @generate-create-func * @param ItemStackWrapper[] $items */ - public static function create(int $windowId, array $items, int $dynamicContainerId = 0) : self{ + public static function create(int $windowId, array $items, FullContainerName $containerName, int $dynamicContainerSize = 0) : self{ $result = new self; $result->windowId = $windowId; $result->items = $items; - $result->dynamicContainerId = $dynamicContainerId; + $result->containerName = $containerName; + $result->dynamicContainerSize = $dynamicContainerSize; return $result; } @@ -45,7 +48,13 @@ protected function decodePayload(PacketSerializer $in) : void{ $this->items[] = ItemStackWrapper::read($in); } if($in->getProtocol() >= ProtocolInfo::PROTOCOL_712){ - $this->dynamicContainerId = $in->getUnsignedVarInt(); + if($in->getProtocol() >= ProtocolInfo::PROTOCOL_729){ + $this->containerName = FullContainerName::read($in); + $this->dynamicContainerSize = $in->getUnsignedVarInt(); + }else { + $dynamicContainerId = $in->getUnsignedVarInt(); + $this->containerName = new FullContainerName(0, $dynamicContainerId); + } } } @@ -56,7 +65,12 @@ protected function encodePayload(PacketSerializer $out) : void{ $item->write($out); } if($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){ - $out->putUnsignedVarInt($this->dynamicContainerId); + if($out->getProtocol() >= ProtocolInfo::PROTOCOL_729){ + $this->containerName->write($out); + $out->putUnsignedVarInt($this->dynamicContainerSize); + }else { + $out->putUnsignedVarInt($this->containerName->getDynamicId()); + } } } diff --git a/src/InventorySlotPacket.php b/src/InventorySlotPacket.php index 49742435..ab927249 100644 --- a/src/InventorySlotPacket.php +++ b/src/InventorySlotPacket.php @@ -15,6 +15,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; +use pocketmine\network\mcpe\protocol\types\inventory\FullContainerName; use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper; class InventorySlotPacket extends DataPacket implements ClientboundPacket{ @@ -22,17 +23,19 @@ class InventorySlotPacket extends DataPacket implements ClientboundPacket{ public int $windowId; public int $inventorySlot; + public FullContainerName $containerName; + public int $dynamicContainerSize; public ItemStackWrapper $item; - public int $dynamicContainerId; /** * @generate-create-func */ - public static function create(int $windowId, int $inventorySlot, ItemStackWrapper $item, int $dynamicContainerId = 0) : self{ + public static function create(int $windowId, int $inventorySlot, ItemStackWrapper $item, FullContainerName $containerName, int $dynamicContainerSize) : self{ $result = new self; $result->windowId = $windowId; $result->inventorySlot = $inventorySlot; - $result->dynamicContainerId = $dynamicContainerId; + $result->containerName = $containerName; + $result->dynamicContainerSize = $dynamicContainerSize; $result->item = $item; return $result; } @@ -41,7 +44,12 @@ protected function decodePayload(PacketSerializer $in) : void{ $this->windowId = $in->getUnsignedVarInt(); $this->inventorySlot = $in->getUnsignedVarInt(); if($in->getProtocol() >= ProtocolInfo::PROTOCOL_712){ - $this->dynamicContainerId = $in->getUnsignedVarInt(); + if($in->getProtocol() >= ProtocolInfo::PROTOCOL_729){ + $this->containerName = FullContainerName::read($in); + $this->dynamicContainerSize = $in->getUnsignedVarInt(); + }else{ + $this->containerName = new FullContainerName(0, $in->getUnsignedVarInt()); + } } $this->item = ItemStackWrapper::read($in); } @@ -50,7 +58,12 @@ protected function encodePayload(PacketSerializer $out) : void{ $out->putUnsignedVarInt($this->windowId); $out->putUnsignedVarInt($this->inventorySlot); if($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){ - $out->putUnsignedVarInt($this->dynamicContainerId); + if($out->getProtocol() >= ProtocolInfo::PROTOCOL_729){ + $this->containerName->write($out); + $out->putUnsignedVarInt($this->dynamicContainerSize); + }else{ + $out->putUnsignedVarInt($this->containerName->getDynamicId()); + } } $this->item->write($out); } diff --git a/src/ProtocolInfo.php b/src/ProtocolInfo.php index 300c5858..f0361daa 100644 --- a/src/ProtocolInfo.php +++ b/src/ProtocolInfo.php @@ -32,7 +32,7 @@ private function __construct(){ */ /** Actual Minecraft: PE protocol version */ - public const CURRENT_PROTOCOL = 712; + public const CURRENT_PROTOCOL = 729; /** Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. */ public const MINECRAFT_VERSION = 'v1.21.20'; /** Version number sent to clients in ping responses. */ @@ -40,6 +40,7 @@ private function __construct(){ public const BASE_VERSION = '1.18.0'; + public const PROTOCOL_729 = 729; // 1.21.30 public const PROTOCOL_712 = 712; // 1.21.20 public const PROTOCOL_686 = 686; // 1.21.2 public const PROTOCOL_685 = 685; // 1.21.0 @@ -67,6 +68,7 @@ private function __construct(){ public const PROTOCOL_475 = 475; // v1.18.0 public const COMPATIBLE_PROTOCOL = [ + self::PROTOCOL_729, self::PROTOCOL_712, // self::PROTOCOL_686, self::PROTOCOL_685, diff --git a/src/ResourcePacksInfoPacket.php b/src/ResourcePacksInfoPacket.php index ce6ecb67..08d2cc13 100644 --- a/src/ResourcePacksInfoPacket.php +++ b/src/ResourcePacksInfoPacket.php @@ -61,10 +61,14 @@ protected function decodePayload(PacketSerializer $in) : void{ $this->hasAddons = $in->getBool(); } $this->hasScripts = $in->getBool(); - $this->forceServerPacks = $in->getBool(); - $behaviorPackCount = $in->getLShort(); - while($behaviorPackCount-- > 0){ - $this->behaviorPackEntries[] = BehaviorPackInfoEntry::read($in); + if($in->getProtocol() < ProtocolInfo::PROTOCOL_729) { + $this->forceServerPacks = $in->getBool(); + } + if($in->getProtocol() < ProtocolInfo::PROTOCOL_729) { + $behaviorPackCount = $in->getLShort(); + while($behaviorPackCount-- > 0) { + $this->behaviorPackEntries[] = BehaviorPackInfoEntry::read($in); + } } $resourcePackCount = $in->getLShort(); @@ -88,10 +92,14 @@ protected function encodePayload(PacketSerializer $out) : void{ $out->putBool($this->hasAddons); } $out->putBool($this->hasScripts); - $out->putBool($this->forceServerPacks); - $out->putLShort(count($this->behaviorPackEntries)); - foreach($this->behaviorPackEntries as $entry){ - $entry->write($out); + if($out->getProtocol() < ProtocolInfo::PROTOCOL_729) { + $out->putBool($this->forceServerPacks); + } + if($out->getProtocol() < ProtocolInfo::PROTOCOL_729) { + $out->putLShort(count($this->behaviorPackEntries)); + foreach($this->behaviorPackEntries as $entry) { + $entry->write($out); + } } $out->putLShort(count($this->resourcePackEntries)); foreach($this->resourcePackEntries as $entry){ diff --git a/src/TransferPacket.php b/src/TransferPacket.php index f9d2013e..c516b335 100644 --- a/src/TransferPacket.php +++ b/src/TransferPacket.php @@ -21,25 +21,33 @@ class TransferPacket extends DataPacket implements ClientboundPacket{ public string $address; public int $port = 19132; + public bool $reloadWorld = true; /** * @generate-create-func */ - public static function create(string $address, int $port) : self{ + public static function create(string $address, int $port, bool $reloadWorld = true) : self{ $result = new self; $result->address = $address; $result->port = $port; + $result->reloadWorld = $reloadWorld; return $result; } protected function decodePayload(PacketSerializer $in) : void{ $this->address = $in->getString(); $this->port = $in->getLShort(); + if($in->getProtocol() >= ProtocolInfo::PROTOCOL_729){ + $this->reloadWorld = $in->getBool(); + } } protected function encodePayload(PacketSerializer $out) : void{ $out->putString($this->address); $out->putLShort($this->port); + if($out->getProtocol() >= ProtocolInfo::PROTOCOL_729){ + $this->reloadWorld = $out->getBool(); + } } public function handle(PacketHandlerInterface $handler) : bool{ diff --git a/src/serializer/PacketSerializer.php b/src/serializer/PacketSerializer.php index a5ae4181..fef32bc1 100644 --- a/src/serializer/PacketSerializer.php +++ b/src/serializer/PacketSerializer.php @@ -518,6 +518,11 @@ public function putAttributeList(Attribute ...$attributes) : void{ $this->putLFloat($attribute->getMin()); $this->putLFloat($attribute->getMax()); $this->putLFloat($attribute->getCurrent()); + if($this->getProtocol() >= ProtocolInfo::PROTOCOL_729) { + // TODO: implement default min & max + $this->putLFloat($attribute->getMin()); // default min + $this->putLFloat($attribute->getMax()); // default max + } $this->putLFloat($attribute->getDefault()); $this->putString($attribute->getId());