Skip to content

Commit

Permalink
Add 1.20.80 version support
Browse files Browse the repository at this point in the history
  • Loading branch information
AkmalFairuz committed Apr 25, 2024
1 parent 6199056 commit 6183e9b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/ProtocolInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ private function __construct(){
*/

/** Actual Minecraft: PE protocol version */
public const CURRENT_PROTOCOL = 662;
public const CURRENT_PROTOCOL = 671;
/** Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. */
public const MINECRAFT_VERSION = 'v1.20.70';
public const MINECRAFT_VERSION = 'v1.20.80';
/** Version number sent to clients in ping responses. */
public const MINECRAFT_VERSION_NETWORK = '1.20.70';
public const MINECRAFT_VERSION_NETWORK = '1.20.80';

public const BASE_VERSION = '1.18.0';

public const PROTOCOL_671 = 671; // 1.20.80
public const PROTOCOL_662 = 662; // 1.20.70
public const PROTOCOL_649 = 649; // 1.20.60
public const PROTOCOL_630 = 630; // 1.20.50
Expand All @@ -63,6 +64,7 @@ private function __construct(){
public const PROTOCOL_475 = 475; // v1.18.0

public const COMPATIBLE_PROTOCOL = [
self::PROTOCOL_671,
self::PROTOCOL_662,
self::PROTOCOL_649,
self::PROTOCOL_630,
Expand Down
10 changes: 9 additions & 1 deletion src/ResourcePackStackPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@ class ResourcePackStackPacket extends DataPacket implements ClientboundPacket{
public bool $mustAccept = false;
public string $baseGameVersion = ProtocolInfo::MINECRAFT_VERSION_NETWORK;
public Experiments $experiments;
public bool $useVanillaEditorPacks = false;

/**
* @generate-create-func
* @param ResourcePackStackEntry[] $resourcePackStack
* @param ResourcePackStackEntry[] $behaviorPackStack
*/
public static function create(array $resourcePackStack, array $behaviorPackStack, bool $mustAccept, string $baseGameVersion, Experiments $experiments) : self{
public static function create(array $resourcePackStack, array $behaviorPackStack, bool $mustAccept, string $baseGameVersion, Experiments $experiments, bool $useVanillaEditorPacks = false) : self{
$result = new self;
$result->resourcePackStack = $resourcePackStack;
$result->behaviorPackStack = $behaviorPackStack;
$result->mustAccept = $mustAccept;
$result->baseGameVersion = $baseGameVersion;
$result->experiments = $experiments;
$result->useVanillaEditorPacks = $useVanillaEditorPacks;
return $result;
}

Expand All @@ -59,6 +61,9 @@ protected function decodePayload(PacketSerializer $in) : void{

$this->baseGameVersion = $in->getString();
$this->experiments = Experiments::read($in);
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_671){
$this->useVanillaEditorPacks = $in->getBool();
}
}

protected function encodePayload(PacketSerializer $out) : void{
Expand All @@ -76,6 +81,9 @@ protected function encodePayload(PacketSerializer $out) : void{

$out->putString($this->baseGameVersion);
$this->experiments->write($out);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_671){
$out->putBool($this->useVanillaEditorPacks);
}
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
12 changes: 11 additions & 1 deletion src/UpdatePlayerGameTypePacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,39 @@ class UpdatePlayerGameTypePacket extends DataPacket implements ClientboundPacket
/** @see GameMode */
private int $gameMode;
private int $playerActorUniqueId;
private int $tick = 0;

/**
* @generate-create-func
*/
public static function create(int $gameMode, int $playerActorUniqueId) : self{
public static function create(int $gameMode, int $playerActorUniqueId, int $tick = 0) : self{
$result = new self;
$result->gameMode = $gameMode;
$result->playerActorUniqueId = $playerActorUniqueId;
$result->tick = $tick;
return $result;
}

public function getGameMode() : int{ return $this->gameMode; }

public function getPlayerActorUniqueId() : int{ return $this->playerActorUniqueId; }

public function getTick(): int{ return $this->tick; }

protected function decodePayload(PacketSerializer $in) : void{
$this->gameMode = $in->getVarInt();
$this->playerActorUniqueId = $in->getActorUniqueId();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_671){
$this->tick = $in->getUnsignedVarInt();
}
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putVarInt($this->gameMode);
$out->putActorUniqueId($this->playerActorUniqueId);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_671){
$out->putUnsignedVarInt($this->tick);
}
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
7 changes: 7 additions & 0 deletions src/types/LevelSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class LevelSettings{
public SpawnSettings $spawnSettings;
public int $generator = GeneratorType::OVERWORLD;
public int $worldGamemode;
public bool $hardcore = false;
public int $difficulty;
public BlockPosition $spawnPosition;
public bool $hasAchievementsDisabled = true;
Expand Down Expand Up @@ -100,6 +101,9 @@ private function internalRead(PacketSerializer $in) : void{
$this->spawnSettings = SpawnSettings::read($in);
$this->generator = $in->getVarInt();
$this->worldGamemode = $in->getVarInt();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_671){
$this->hardcore = $in->getBool();
}
$this->difficulty = $in->getVarInt();
$this->spawnPosition = $in->getBlockPosition();
$this->hasAchievementsDisabled = $in->getBool();
Expand Down Expand Up @@ -168,6 +172,9 @@ public function write(PacketSerializer $out) : void{
$this->spawnSettings->write($out);
$out->putVarInt($this->generator);
$out->putVarInt($this->worldGamemode);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_671){
$out->putBool($this->hardcore);
}
$out->putVarInt($this->difficulty);
$out->putBlockPosition($this->spawnPosition);
$out->putBool($this->hasAchievementsDisabled);
Expand Down
10 changes: 8 additions & 2 deletions src/types/recipe/ShapedRecipe.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 All @@ -34,7 +35,8 @@ public function __construct(
private UuidInterface $uuid,
string $blockType, //TODO: rename this
private int $priority,
private int $recipeNetId
private int $recipeNetId,
private bool $symmetric = true,
){
parent::__construct($typeId);
$rows = count($input);
Expand Down Expand Up @@ -112,9 +114,10 @@ public static function decode(int $recipeType, PacketSerializer $in) : self{
$uuid = $in->getUUID();
$block = $in->getString();
$priority = $in->getVarInt();
$symmetric = !($in->getProtocol() >= ProtocolInfo::PROTOCOL_671) || $in->getBool();
$recipeNetId = $in->readGenericTypeNetworkId();

return new self($recipeType, $recipeId, $input, $output, $uuid, $block, $priority, $recipeNetId);
return new self($recipeType, $recipeId, $input, $output, $uuid, $block, $priority, $recipeNetId, $symmetric);
}

public function encode(PacketSerializer $out) : void{
Expand All @@ -135,6 +138,9 @@ public function encode(PacketSerializer $out) : void{
$out->putUUID($this->uuid);
$out->putString($this->blockName);
$out->putVarInt($this->priority);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_671){
$out->putBool($this->symmetric);
}
$out->writeGenericTypeNetworkId($this->recipeNetId);
}
}

0 comments on commit 6183e9b

Please sign in to comment.