diff --git a/src/CodeBuilderSourcePacket.php b/src/CodeBuilderSourcePacket.php index 3d408b26..f213235f 100644 --- a/src/CodeBuilderSourcePacket.php +++ b/src/CodeBuilderSourcePacket.php @@ -21,15 +21,17 @@ class CodeBuilderSourcePacket extends DataPacket implements ServerboundPacket{ private int $operation; private int $category; + private string $value; private int $codeStatus; /** * @generate-create-func */ - public static function create(int $operation, int $category, int $codeStatus) : self{ + public static function create(int $operation, int $category, string $value, int $codeStatus) : self{ $result = new self; $result->operation = $operation; $result->category = $category; + $result->value = $value; $result->codeStatus = $codeStatus; return $result; } @@ -38,18 +40,28 @@ public function getOperation() : int{ return $this->operation; } public function getCategory() : int{ return $this->category; } + public function getValue() : string{ return $this->value; } + public function getCodeStatus() : int{ return $this->codeStatus; } protected function decodePayload(PacketSerializer $in) : void{ $this->operation = $in->getByte(); $this->category = $in->getByte(); - $this->codeStatus = $in->getByte(); + if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_0){ + $this->codeStatus = $in->getByte(); + }else{ + $this->value = $in->getString(); + } } protected function encodePayload(PacketSerializer $out) : void{ $out->putByte($this->operation); $out->putByte($this->category); - $out->putByte($this->codeStatus); + if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_0){ + $out->putByte($this->codeStatus); + }else{ + $out->putString($this->value); + } } public function handle(PacketHandlerInterface $handler) : bool{ diff --git a/src/ContainerClosePacket.php b/src/ContainerClosePacket.php index 36fdd1a5..ff5a7ccb 100644 --- a/src/ContainerClosePacket.php +++ b/src/ContainerClosePacket.php @@ -36,13 +36,17 @@ public static function create(int $windowId, int $windowType, bool $server) : se protected function decodePayload(PacketSerializer $in) : void{ $this->windowId = $in->getByte(); - $this->windowType = $in->getByte(); + if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_0){ + $this->windowType = $in->getByte(); + } $this->server = $in->getBool(); } protected function encodePayload(PacketSerializer $out) : void{ $out->putByte($this->windowId); - $out->putByte($this->windowType); + if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_0){ + $out->putByte($this->windowType); + } $out->putBool($this->server); } diff --git a/src/TextPacket.php b/src/TextPacket.php index ceae96ca..8f831974 100644 --- a/src/TextPacket.php +++ b/src/TextPacket.php @@ -126,7 +126,9 @@ protected function decodePayload(PacketSerializer $in) : void{ $this->xboxUserId = $in->getString(); $this->platformChatId = $in->getString(); - $this->filteredMessage = $in->getString(); + if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_0){ + $this->filteredMessage = $in->getString(); + } } protected function encodePayload(PacketSerializer $out) : void{ @@ -160,7 +162,9 @@ protected function encodePayload(PacketSerializer $out) : void{ $out->putString($this->xboxUserId); $out->putString($this->platformChatId); - $out->putString($this->filteredMessage); + if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_0){ + $out->putString($this->filteredMessage); + } } public function handle(PacketHandlerInterface $handler) : bool{ diff --git a/src/types/LevelSettings.php b/src/types/LevelSettings.php index 4afd72ba..d3e5f67c 100644 --- a/src/types/LevelSettings.php +++ b/src/types/LevelSettings.php @@ -147,9 +147,11 @@ private function internalRead(PacketSerializer $in) : void{ $this->experimentalGameplayOverride = $in->readOptional($in->getBool(...)); $this->chatRestrictionLevel = $in->getByte(); $this->disablePlayerInteractions = $in->getBool(); - $this->serverIdentifier = $in->getString(); - $this->worldIdentifier = $in->getString(); - $this->scenarioIdentifier = $in->getString(); + if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_0){ + $this->serverIdentifier = $in->getString(); + $this->worldIdentifier = $in->getString(); + $this->scenarioIdentifier = $in->getString(); + } } public function write(PacketSerializer $out) : void{ @@ -207,8 +209,10 @@ public function write(PacketSerializer $out) : void{ $out->writeOptional($this->experimentalGameplayOverride, $out->putBool(...)); $out->putByte($this->chatRestrictionLevel); $out->putBool($this->disablePlayerInteractions); - $out->putString($this->serverIdentifier); - $out->putString($this->worldIdentifier); - $out->putString($this->scenarioIdentifier); + if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_0){ + $out->putString($this->serverIdentifier); + $out->putString($this->worldIdentifier); + $out->putString($this->scenarioIdentifier); + } } } diff --git a/src/types/recipe/ShapelessRecipe.php b/src/types/recipe/ShapelessRecipe.php index 92ec411f..ddb50138 100644 --- a/src/types/recipe/ShapelessRecipe.php +++ b/src/types/recipe/ShapelessRecipe.php @@ -14,6 +14,7 @@ namespace pocketmine\network\mcpe\protocol\types\recipe; +use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; use pocketmine\network\mcpe\protocol\types\inventory\ItemStack; use Ramsey\Uuid\UuidInterface; @@ -87,11 +88,13 @@ public static function decode(int $recipeType, PacketSerializer $in) : self{ $uuid = $in->getUUID(); $block = $in->getString(); $priority = $in->getVarInt(); - $unlockingRequirement = RecipeUnlockingRequirement::read($in); + if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_0){ + $unlockingRequirement = RecipeUnlockingRequirement::read($in); + } $recipeNetId = $in->readRecipeNetId(); - return new self($recipeType, $recipeId, $input, $output, $uuid, $block, $priority, $unlockingRequirement, $recipeNetId); + return new self($recipeType, $recipeId, $input, $output, $uuid, $block, $priority, $unlockingRequirement ?? new RecipeUnlockingRequirement(null), $recipeNetId); } public function encode(PacketSerializer $out) : void{ @@ -109,7 +112,9 @@ public function encode(PacketSerializer $out) : void{ $out->putUUID($this->uuid); $out->putString($this->blockName); $out->putVarInt($this->priority); - $this->unlockingRequirement->write($out); + if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_0){ + $this->unlockingRequirement->write($out); + } $out->writeRecipeNetId($this->recipeNetId); }