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 14, 2024
1 parent 6c648b7 commit bb5a3ae
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 17 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
2 changes: 2 additions & 0 deletions src/PacketHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public function handleUpdateBlock(UpdateBlockPacket $packet) : bool;

public function handleAddPainting(AddPaintingPacket $packet) : bool;

public function handleTickSync(TickSyncPacket $packet) : bool;

public function handleLevelSoundEventPacketV1(LevelSoundEventPacketV1 $packet) : bool;

public function handleLevelEvent(LevelEventPacket $packet) : bool;
Expand Down
1 change: 1 addition & 0 deletions src/PacketPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function __construct(){
$this->registerPacket(new PassengerJumpPacket());
$this->registerPacket(new UpdateBlockPacket());
$this->registerPacket(new AddPaintingPacket());
$this->registerPacket(new TickSyncPacket());
$this->registerPacket(new LevelSoundEventPacketV1());
$this->registerPacket(new LevelEventPacket());
$this->registerPacket(new BlockEventPacket());
Expand Down
2 changes: 1 addition & 1 deletion src/ProtocolInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function __construct(){
public const PASSENGER_JUMP_PACKET = 0x14;
public const UPDATE_BLOCK_PACKET = 0x15;
public const ADD_PAINTING_PACKET = 0x16;

public const TICK_SYNC_PACKET = 0x17;
public const LEVEL_SOUND_EVENT_PACKET_V1 = 0x18;
public const LEVEL_EVENT_PACKET = 0x19;
public const BLOCK_EVENT_PACKET = 0x1a;
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
64 changes: 64 additions & 0 deletions src/TickSyncPacket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/*
* This file is part of BedrockProtocol.
* Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
*
* BedrockProtocol is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

declare(strict_types=1);

namespace pocketmine\network\mcpe\protocol;

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;

class TickSyncPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{
public const NETWORK_ID = ProtocolInfo::TICK_SYNC_PACKET;

private int $clientSendTime;
private int $serverReceiveTime;

/**
* @generate-create-func
*/
private static function create(int $clientSendTime, int $serverReceiveTime) : self{
$result = new self;
$result->clientSendTime = $clientSendTime;
$result->serverReceiveTime = $serverReceiveTime;
return $result;
}

public static function request(int $clientTime) : self{
return self::create($clientTime, 0 /* useless, but always written anyway */);
}

public static function response(int $clientSendTime, int $serverReceiveTime) : self{
return self::create($clientSendTime, $serverReceiveTime);
}

public function getClientSendTime() : int{
return $this->clientSendTime;
}

public function getServerReceiveTime() : int{
return $this->serverReceiveTime;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->clientSendTime = $in->getLLong();
$this->serverReceiveTime = $in->getLLong();
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putLLong($this->clientSendTime);
$out->putLLong($this->serverReceiveTime);
}

public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleTickSync($this);
}
}
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 bb5a3ae

Please sign in to comment.