Skip to content

Commit

Permalink
1.21.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
AkmalFairuz committed Jun 14, 2024
1 parent 6183e9b commit 4a0a0aa
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/ContainerClosePacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,33 @@ class ContainerClosePacket extends DataPacket implements ClientboundPacket, Serv
public const NETWORK_ID = ProtocolInfo::CONTAINER_CLOSE_PACKET;

public int $windowId;
public int $windowType;
public bool $server = false;

/**
* @generate-create-func
*/
public static function create(int $windowId, bool $server) : self{
public static function create(int $windowId, int $windowType, bool $server): self{
$result = new self;
$result->windowId = $windowId;
$result->windowType = $windowType;
$result->server = $server;
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->windowId = $in->getByte();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_685){
$this->windowType = $in->getByte();
}
$this->server = $in->getBool();
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putByte($this->windowId);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_685){
$out->putByte($this->windowType);
}
$out->putBool($this->server);
}

Expand Down
2 changes: 2 additions & 0 deletions src/ProtocolInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private function __construct(){

public const BASE_VERSION = '1.18.0';

public const PROTOCOL_685 = 685; // 1.21.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
Expand All @@ -64,6 +65,7 @@ private function __construct(){
public const PROTOCOL_475 = 475; // v1.18.0

public const COMPATIBLE_PROTOCOL = [
self::PROTOCOL_685,
self::PROTOCOL_671,
self::PROTOCOL_662,
self::PROTOCOL_649,
Expand Down
7 changes: 7 additions & 0 deletions src/TextPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TextPacket extends DataPacket implements ClientboundPacket, ServerboundPac
public array $parameters = [];
public string $xboxUserId = "";
public string $platformChatId = "";
public string $filteredMessage = "";

private static function messageOnly(int $type, string $message) : self{
$result = new self;
Expand Down Expand Up @@ -125,6 +126,9 @@ protected function decodePayload(PacketSerializer $in) : void{

$this->xboxUserId = $in->getString();
$this->platformChatId = $in->getString();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_685){
$this->filteredMessage = $in->getString();
}
}

protected function encodePayload(PacketSerializer $out) : void{
Expand Down Expand Up @@ -158,6 +162,9 @@ protected function encodePayload(PacketSerializer $out) : void{

$out->putString($this->xboxUserId);
$out->putString($this->platformChatId);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_685){
$out->putString($this->filteredMessage);
}
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
13 changes: 13 additions & 0 deletions src/types/LevelSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ final class LevelSettings{
public ?bool $experimentalGameplayOverride = null;
public int $chatRestrictionLevel = ChatRestrictionLevel::NONE;
public bool $disablePlayerInteractions = false;
public string $serverIdentifier = "";
public string $worldIdentifier = "";
public string $scenarioIdentifier = "";

/**
* @throws BinaryDataException
Expand Down Expand Up @@ -161,6 +164,11 @@ private function internalRead(PacketSerializer $in) : void{
$this->chatRestrictionLevel = $in->getByte();
$this->disablePlayerInteractions = $in->getBool();
}
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_685){
$this->serverIdentifier = $in->getString();
$this->worldIdentifier = $in->getString();
$this->scenarioIdentifier = $in->getString();
}
}

public function write(PacketSerializer $out) : void{
Expand Down Expand Up @@ -232,5 +240,10 @@ public function write(PacketSerializer $out) : void{
$out->putByte($this->chatRestrictionLevel);
$out->putBool($this->disablePlayerInteractions);
}
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_685){
$out->putString($this->serverIdentifier);
$out->putString($this->worldIdentifier);
$out->putString($this->scenarioIdentifier);
}
}
}
58 changes: 58 additions & 0 deletions src/types/recipe/RecipeUnlockingRequirement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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\types\recipe;

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

final class RecipeUnlockingRequirement{

/**
* @param RecipeIngredient[]|null $unlockingIngredients
*/
public function __construct(
private ?array $unlockingIngredients
){}

/**
* @return RecipeIngredient[]|null
*/
public function getUnlockingIngredients() : ?array{ return $this->unlockingIngredients; }

public static function read(PacketSerializer $in) : self{
//I don't know what the point of this structure is. It could easily have been a list<RecipeIngredient> instead.
//It's basically just an optional list, which could have been done by an empty list wherever it's not needed.
$unlockingContext = $in->getBool();
$unlockingIngredients = null;
if(!$unlockingContext){
$unlockingIngredients = [];
for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; $i++){
$unlockingIngredients[] = $in->getRecipeIngredient();
}
}

return new self($unlockingIngredients);
}

public function write(PacketSerializer $out) : void{
$out->putBool($this->unlockingIngredients === null);
if($this->unlockingIngredients !== null){
$out->putUnsignedVarInt(count($this->unlockingIngredients));
foreach($this->unlockingIngredients as $ingredient){
$out->putRecipeIngredient($ingredient);
}
}
}
}
14 changes: 13 additions & 1 deletion src/types/recipe/ShapedRecipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function __construct(
string $blockType, //TODO: rename this
private int $priority,
private int $recipeNetId,
private RecipeUnlockingRequirement $unlockingRequirement,
private bool $symmetric = true,
){
parent::__construct($typeId);
Expand Down Expand Up @@ -96,6 +97,13 @@ public function getRecipeNetId() : int{
return $this->recipeNetId;
}

/**
* @return RecipeUnlockingRequirement
*/
public function getUnlockingRequirement(): RecipeUnlockingRequirement{
return $this->unlockingRequirement;
}

public static function decode(int $recipeType, PacketSerializer $in) : self{
$recipeId = $in->getString();
$width = $in->getVarInt();
Expand All @@ -115,9 +123,10 @@ public static function decode(int $recipeType, PacketSerializer $in) : self{
$block = $in->getString();
$priority = $in->getVarInt();
$symmetric = !($in->getProtocol() >= ProtocolInfo::PROTOCOL_671) || $in->getBool();
$unlockingRequirement = $in->getProtocol() >= ProtocolInfo::PROTOCOL_685 ? RecipeUnlockingRequirement::read($in) : new RecipeUnlockingRequirement(null);
$recipeNetId = $in->readGenericTypeNetworkId();

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

public function encode(PacketSerializer $out) : void{
Expand All @@ -141,6 +150,9 @@ public function encode(PacketSerializer $out) : void{
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_671){
$out->putBool($this->symmetric);
}
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_685){
$this->unlockingRequirement->write($out);
}
$out->writeGenericTypeNetworkId($this->recipeNetId);
}
}
15 changes: 14 additions & 1 deletion 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 All @@ -32,6 +33,7 @@ public function __construct(
private UuidInterface $uuid,
private string $blockName,
private int $priority,
private RecipeUnlockingRequirement $unlockingRequirement,
private int $recipeNetId
){
parent::__construct($typeId);
Expand Down Expand Up @@ -71,6 +73,13 @@ public function getRecipeNetId() : int{
return $this->recipeNetId;
}

/**
* @return RecipeUnlockingRequirement
*/
public function getUnlockingRequirement(): RecipeUnlockingRequirement{
return $this->unlockingRequirement;
}

public static function decode(int $recipeType, PacketSerializer $in) : self{
$recipeId = $in->getString();
$input = [];
Expand All @@ -84,9 +93,10 @@ public static function decode(int $recipeType, PacketSerializer $in) : self{
$uuid = $in->getUUID();
$block = $in->getString();
$priority = $in->getVarInt();
$unlockingRequirement = $in->getProtocol() >= ProtocolInfo::PROTOCOL_685 ? RecipeUnlockingRequirement::read($in) : new RecipeUnlockingRequirement(null);
$recipeNetId = $in->readGenericTypeNetworkId();

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

public function encode(PacketSerializer $out) : void{
Expand All @@ -104,6 +114,9 @@ public function encode(PacketSerializer $out) : void{
$out->putUUID($this->uuid);
$out->putString($this->blockName);
$out->putVarInt($this->priority);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_685){
$this->unlockingRequirement->write($out);
}
$out->writeGenericTypeNetworkId($this->recipeNetId);
}
}

0 comments on commit 4a0a0aa

Please sign in to comment.