Merge branch 'stable'

This commit is contained in:
Dylan K. Taylor
2021-06-08 20:00:08 +01:00
19 changed files with 277 additions and 42 deletions

View File

@ -0,0 +1,65 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program 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.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\TreeRoot;
use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
class AddVolumeEntityPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::ADD_VOLUME_ENTITY_PACKET;
/** @var int */
private $entityNetId;
/** @var CompoundTag */
private $data;
public static function create(int $entityNetId, CompoundTag $data) : self{
$result = new self;
$result->entityNetId = $entityNetId;
$result->data = $data;
return $result;
}
public function getEntityNetId() : int{ return $this->entityNetId; }
public function getData() : CompoundTag{ return $this->data; }
protected function decodePayload(PacketSerializer $in) : void{
$this->entityNetId = $in->getUnsignedVarInt();
$this->data = $in->getNbtCompoundRoot();
}
protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt($this->entityNetId);
$out->put((new NetworkNbtSerializer())->write(new TreeRoot($this->data)));
}
public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleAddVolumeEntity($this);
}
}

View File

@ -344,4 +344,10 @@ interface PacketHandlerInterface{
public function handleFilterText(FilterTextPacket $packet) : bool;
public function handleClientboundDebugRenderer(ClientboundDebugRendererPacket $packet) : bool;
public function handleSyncActorProperty(SyncActorPropertyPacket $packet) : bool;
public function handleAddVolumeEntity(AddVolumeEntityPacket $packet) : bool;
public function handleRemoveVolumeEntity(RemoveVolumeEntityPacket $packet) : bool;
}

View File

@ -202,6 +202,9 @@ class PacketPool{
$this->registerPacket(new ItemComponentPacket());
$this->registerPacket(new FilterTextPacket());
$this->registerPacket(new ClientboundDebugRendererPacket());
$this->registerPacket(new SyncActorPropertyPacket());
$this->registerPacket(new AddVolumeEntityPacket());
$this->registerPacket(new RemoveVolumeEntityPacket());
}
public function registerPacket(Packet $packet) : void{

View File

@ -41,11 +41,11 @@ final class ProtocolInfo{
*/
/** Actual Minecraft: PE protocol version */
public const CURRENT_PROTOCOL = 431;
public const CURRENT_PROTOCOL = 440;
/** Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. */
public const MINECRAFT_VERSION = 'v1.16.220';
public const MINECRAFT_VERSION = 'v1.17.0';
/** Version number sent to clients in ping responses. */
public const MINECRAFT_VERSION_NETWORK = '1.16.220';
public const MINECRAFT_VERSION_NETWORK = '1.17.0';
public const LOGIN_PACKET = 0x01;
public const PLAY_STATUS_PACKET = 0x02;
@ -211,5 +211,8 @@ final class ProtocolInfo{
public const ITEM_COMPONENT_PACKET = 0xa2;
public const FILTER_TEXT_PACKET = 0xa3;
public const CLIENTBOUND_DEBUG_RENDERER_PACKET = 0xa4;
public const SYNC_ACTOR_PROPERTY_PACKET = 0xa5;
public const ADD_VOLUME_ENTITY_PACKET = 0xa6;
public const REMOVE_VOLUME_ENTITY_PACKET = 0xa7;
}

View File

@ -0,0 +1,55 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program 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.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
class RemoveVolumeEntityPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::REMOVE_VOLUME_ENTITY_PACKET;
/** @var int */
private $entityNetId;
public static function create(int $entityNetId) : self{
$result = new self;
$result->entityNetId = $entityNetId;
return $result;
}
public function getEntityNetId() : int{ return $this->entityNetId; }
protected function decodePayload(PacketSerializer $in) : void{
$this->entityNetId = $in->getUnsignedVarInt();
}
protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt($this->entityNetId);
}
public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleRemoveVolumeEntity($this);
}
}

View File

@ -163,6 +163,8 @@ class StartGamePacket extends DataPacket implements ClientboundPacket{
public $multiplayerCorrelationId = ""; //TODO: this should be filled with a UUID of some sort
/** @var bool */
public $enableNewInventorySystem = false; //TODO
/** @var string */
public $serverSoftwareVersion;
/**
* @var BlockPaletteEntry[]
@ -256,6 +258,7 @@ class StartGamePacket extends DataPacket implements ClientboundPacket{
$this->multiplayerCorrelationId = $in->getString();
$this->enableNewInventorySystem = $in->getBool();
$this->serverSoftwareVersion = $in->getString();
}
protected function encodePayload(PacketSerializer $out) : void{
@ -336,6 +339,7 @@ class StartGamePacket extends DataPacket implements ClientboundPacket{
$out->putString($this->multiplayerCorrelationId);
$out->putBool($this->enableNewInventorySystem);
$out->putString($this->serverSoftwareVersion);
}
public function handle(PacketHandlerInterface $handler) : bool{

View File

@ -0,0 +1,58 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program 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.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\TreeRoot;
use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
class SyncActorPropertyPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::SYNC_ACTOR_PROPERTY_PACKET;
/** @var CompoundTag */
private $data;
public static function create(CompoundTag $data) : self{
$result = new self;
$result->data = $data;
return $result;
}
public function getData() : CompoundTag{ return $this->data; }
protected function decodePayload(PacketSerializer $in) : void{
$this->data = $in->getNbtCompoundRoot();
}
protected function encodePayload(PacketSerializer $out) : void{
$out->put((new NetworkNbtSerializer())->write(new TreeRoot($this->data)));
}
public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleSyncActorProperty($this);
}
}

View File

@ -597,11 +597,11 @@ class PacketSerializer extends BinaryStream{
$this->putByte((int) ($rotation / (360 / 256)));
}
private function readGameRule(int $type) : GameRule{
private function readGameRule(int $type, bool $isPlayerModifiable) : GameRule{
switch($type){
case GameRuleType::BOOL: return BoolGameRule::decode($this);
case GameRuleType::INT: return IntGameRule::decode($this);
case GameRuleType::FLOAT: return FloatGameRule::decode($this);
case GameRuleType::BOOL: return BoolGameRule::decode($this, $isPlayerModifiable);
case GameRuleType::INT: return IntGameRule::decode($this, $isPlayerModifiable);
case GameRuleType::FLOAT: return FloatGameRule::decode($this, $isPlayerModifiable);
default:
throw new PacketDecodeException("Unknown gamerule type $type");
}
@ -621,8 +621,9 @@ class PacketSerializer extends BinaryStream{
$rules = [];
for($i = 0; $i < $count; ++$i){
$name = $this->getString();
$isPlayerModifiable = $this->getBool();
$type = $this->getUnsignedVarInt();
$rules[$name] = $this->readGameRule($type);
$rules[$name] = $this->readGameRule($type, $isPlayerModifiable);
}
return $rules;
@ -638,6 +639,7 @@ class PacketSerializer extends BinaryStream{
$this->putUnsignedVarInt(count($rules));
foreach($rules as $name => $rule){
$this->putString($name);
$this->putBool($rule->isPlayerModifiable());
$this->putUnsignedVarInt($rule->getType());
$rule->encode($this);
}

View File

@ -30,7 +30,8 @@ final class BoolGameRule extends GameRule{
/** @var bool */
private $value;
public function __construct(bool $value){
public function __construct(bool $value, bool $isPlayerModifiable){
parent::__construct($isPlayerModifiable);
$this->value = $value;
}
@ -46,7 +47,7 @@ final class BoolGameRule extends GameRule{
$out->putBool($this->value);
}
public static function decode(PacketSerializer $in) : self{
return new self($in->getBool());
public static function decode(PacketSerializer $in, bool $isPlayerModifiable) : self{
return new self($in->getBool(), $isPlayerModifiable);
}
}

View File

@ -29,7 +29,8 @@ final class FloatGameRule extends GameRule{
/** @var float */
private $value;
public function __construct(float $value){
public function __construct(float $value, bool $isPlayerModifiable){
parent::__construct($isPlayerModifiable);
$this->value = $value;
}
@ -45,7 +46,7 @@ final class FloatGameRule extends GameRule{
$out->putLFloat($this->value);
}
public static function decode(PacketSerializer $in) : self{
return new self($in->getLFloat());
public static function decode(PacketSerializer $in, bool $isPlayerModifiable) : self{
return new self($in->getLFloat(), $isPlayerModifiable);
}
}

View File

@ -27,6 +27,14 @@ use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
abstract class GameRule{
private bool $playerModifiable;
public function __construct(bool $isPlayerModifiable){
$this->playerModifiable = $isPlayerModifiable;
}
public function isPlayerModifiable() : bool{ return $this->playerModifiable; }
abstract public function getType() : int;
abstract public function encode(PacketSerializer $out) : void;

View File

@ -30,7 +30,8 @@ final class IntGameRule extends GameRule{
/** @var int */
private $value;
public function __construct(int $value){
public function __construct(int $value, bool $isPlayerModifiable){
parent::__construct($isPlayerModifiable);
$this->value = $value;
}
@ -46,7 +47,7 @@ final class IntGameRule extends GameRule{
$out->putUnsignedVarInt($this->value);
}
public static function decode(PacketSerializer $in) : self{
return new self($in->getUnsignedVarInt());
public static function decode(PacketSerializer $in, bool $isPlayerModifiable) : self{
return new self($in->getUnsignedVarInt(), $isPlayerModifiable);
}
}