Skip to content

Commit

Permalink
Add v1.20.80 BC support
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Jun 13, 2024
1 parent 6c648b7 commit c7a8233
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
18 changes: 15 additions & 3 deletions src/CodeBuilderSourcePacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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{
Expand Down
8 changes: 6 additions & 2 deletions src/ContainerClosePacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 6 additions & 2 deletions src/TextPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
16 changes: 10 additions & 6 deletions src/types/LevelSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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);
}
}
}
11 changes: 8 additions & 3 deletions src/types/recipe/ShapelessRecipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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{
Expand All @@ -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);
}
Expand Down

0 comments on commit c7a8233

Please sign in to comment.