Skip to content

Commit

Permalink
Protocol changes for 1.20.60
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Feb 7, 2024
1 parent 1015502 commit 19e6411
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 152 deletions.
11 changes: 10 additions & 1 deletion src/LevelChunkPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\ChunkPosition;
use pocketmine\network\mcpe\protocol\types\DimensionIds;
use pocketmine\utils\Limits;
use function count;
use const PHP_INT_MAX;
Expand All @@ -37,6 +38,8 @@ class LevelChunkPacket extends DataPacket implements ClientboundPacket{
private const MAX_BLOB_HASHES = 64;

private ChunkPosition $chunkPosition;
/** @phpstan-var DimensionIds::* */
private int $dimensionId;
private int $subChunkCount;
private bool $clientSubChunkRequestsEnabled;
/** @var int[]|null */
Expand All @@ -46,10 +49,12 @@ class LevelChunkPacket extends DataPacket implements ClientboundPacket{
/**
* @generate-create-func
* @param int[] $usedBlobHashes
* @phpstan-param DimensionIds::* $dimensionId
*/
public static function create(ChunkPosition $chunkPosition, int $subChunkCount, bool $clientSubChunkRequestsEnabled, ?array $usedBlobHashes, string $extraPayload) : self{
public static function create(ChunkPosition $chunkPosition, int $dimensionId, int $subChunkCount, bool $clientSubChunkRequestsEnabled, ?array $usedBlobHashes, string $extraPayload) : self{
$result = new self;
$result->chunkPosition = $chunkPosition;
$result->dimensionId = $dimensionId;
$result->subChunkCount = $subChunkCount;
$result->clientSubChunkRequestsEnabled = $clientSubChunkRequestsEnabled;
$result->usedBlobHashes = $usedBlobHashes;
Expand All @@ -59,6 +64,8 @@ public static function create(ChunkPosition $chunkPosition, int $subChunkCount,

public function getChunkPosition() : ChunkPosition{ return $this->chunkPosition; }

public function getDimensionId() : int{ return $this->dimensionId; }

public function getSubChunkCount() : int{
return $this->subChunkCount;
}
Expand All @@ -84,6 +91,7 @@ public function getExtraPayload() : string{

protected function decodePayload(PacketSerializer $in) : void{
$this->chunkPosition = ChunkPosition::read($in);
$this->dimensionId = $in->getVarInt();

Check failure on line 94 in src/LevelChunkPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.1)

Property pocketmine\network\mcpe\protocol\LevelChunkPacket::$dimensionId (0|1|2) does not accept int.

Check failure on line 94 in src/LevelChunkPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.1)

Property pocketmine\network\mcpe\protocol\LevelChunkPacket::$dimensionId (0|1|2) does not accept int.

Check failure on line 94 in src/LevelChunkPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.2)

Property pocketmine\network\mcpe\protocol\LevelChunkPacket::$dimensionId (0|1|2) does not accept int.

Check failure on line 94 in src/LevelChunkPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.3)

Property pocketmine\network\mcpe\protocol\LevelChunkPacket::$dimensionId (0|1|2) does not accept int.

Check failure on line 94 in src/LevelChunkPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.2)

Property pocketmine\network\mcpe\protocol\LevelChunkPacket::$dimensionId (0|1|2) does not accept int.

Check failure on line 94 in src/LevelChunkPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.3)

Property pocketmine\network\mcpe\protocol\LevelChunkPacket::$dimensionId (0|1|2) does not accept int.

$subChunkCountButNotReally = $in->getUnsignedVarInt();
if($subChunkCountButNotReally === self::CLIENT_REQUEST_FULL_COLUMN_FAKE_COUNT){
Expand Down Expand Up @@ -113,6 +121,7 @@ protected function decodePayload(PacketSerializer $in) : void{

protected function encodePayload(PacketSerializer $out) : void{
$this->chunkPosition->write($out);
$out->putVarInt($this->dimensionId);

if($this->clientSubChunkRequestsEnabled){
if($this->subChunkCount === PHP_INT_MAX){
Expand Down
16 changes: 8 additions & 8 deletions src/PacketHandlerDefaultImplTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public function handleAddItemActor(AddItemActorPacket $packet) : bool{
return false;
}

public function handleServerPlayerPostMovePosition(ServerPlayerPostMovePositionPacket $packet) : bool{
return false;
}

public function handleTakeItemActor(TakeItemActorPacket $packet) : bool{
return false;
}
Expand Down Expand Up @@ -498,14 +502,6 @@ public function handleLecternUpdate(LecternUpdatePacket $packet) : bool{
return false;
}

public function handleAddEntity(AddEntityPacket $packet) : bool{
return false;
}

public function handleRemoveEntity(RemoveEntityPacket $packet) : bool{
return false;
}

public function handleClientCacheStatus(ClientCacheStatusPacket $packet) : bool{
return false;
}
Expand Down Expand Up @@ -809,4 +805,8 @@ public function handlePlayerToggleCrafterSlotRequest(PlayerToggleCrafterSlotRequ
public function handleSetPlayerInventoryOptions(SetPlayerInventoryOptionsPacket $packet) : bool{
return false;
}

public function handleSetHud(SetHudPacket $packet) : bool{
return false;
}
}
8 changes: 4 additions & 4 deletions src/PacketHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function handleRemoveActor(RemoveActorPacket $packet) : bool;

public function handleAddItemActor(AddItemActorPacket $packet) : bool;

public function handleServerPlayerPostMovePosition(ServerPlayerPostMovePositionPacket $packet) : bool;

public function handleTakeItemActor(TakeItemActorPacket $packet) : bool;

public function handleMoveActorAbsolute(MoveActorAbsolutePacket $packet) : bool;
Expand Down Expand Up @@ -256,10 +258,6 @@ public function handleLevelEventGeneric(LevelEventGenericPacket $packet) : bool;

public function handleLecternUpdate(LecternUpdatePacket $packet) : bool;

public function handleAddEntity(AddEntityPacket $packet) : bool;

public function handleRemoveEntity(RemoveEntityPacket $packet) : bool;

public function handleClientCacheStatus(ClientCacheStatusPacket $packet) : bool;

public function handleOnScreenTextureAnimation(OnScreenTextureAnimationPacket $packet) : bool;
Expand Down Expand Up @@ -411,4 +409,6 @@ public function handleRefreshEntitlements(RefreshEntitlementsPacket $packet) : b
public function handlePlayerToggleCrafterSlotRequest(PlayerToggleCrafterSlotRequestPacket $packet) : bool;

public function handleSetPlayerInventoryOptions(SetPlayerInventoryOptionsPacket $packet) : bool;

public function handleSetHud(SetHudPacket $packet) : bool;
}
4 changes: 2 additions & 2 deletions src/PacketPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function __construct(){
$this->registerPacket(new AddActorPacket());
$this->registerPacket(new RemoveActorPacket());
$this->registerPacket(new AddItemActorPacket());
$this->registerPacket(new ServerPlayerPostMovePositionPacket());
$this->registerPacket(new TakeItemActorPacket());
$this->registerPacket(new MoveActorAbsolutePacket());
$this->registerPacket(new MovePlayerPacket());
Expand Down Expand Up @@ -152,8 +153,6 @@ public function __construct(){
$this->registerPacket(new LevelSoundEventPacket());
$this->registerPacket(new LevelEventGenericPacket());
$this->registerPacket(new LecternUpdatePacket());
$this->registerPacket(new AddEntityPacket());
$this->registerPacket(new RemoveEntityPacket());
$this->registerPacket(new ClientCacheStatusPacket());
$this->registerPacket(new OnScreenTextureAnimationPacket());
$this->registerPacket(new MapCreateLockedCopyPacket());
Expand Down Expand Up @@ -230,6 +229,7 @@ public function __construct(){
$this->registerPacket(new RefreshEntitlementsPacket());
$this->registerPacket(new PlayerToggleCrafterSlotRequestPacket());
$this->registerPacket(new SetPlayerInventoryOptionsPacket());
$this->registerPacket(new SetHudPacket());
}

public function registerPacket(Packet $packet) : void{
Expand Down
14 changes: 14 additions & 0 deletions src/PlayerAuthInputPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
private ?ItemStackRequest $itemStackRequest = null;
/** @var PlayerBlockAction[]|null */
private ?array $blockActions = null;
private ?int $clientPredictedVehicleActorUniqueId = null;
private float $analogMoveVecX;
private float $analogMoveVecZ;

Expand Down Expand Up @@ -77,6 +78,7 @@ public static function create(
?ItemInteractionData $itemInteractionData,
?ItemStackRequest $itemStackRequest,
?array $blockActions,
?int $clientPredictedVehicleActorUniqueId,
float $analogMoveVecX,
float $analogMoveVecZ
) : self{
Expand All @@ -102,6 +104,9 @@ public static function create(
if($blockActions !== null){
$result->inputFlags |= 1 << PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS;
}
if($clientPredictedVehicleActorUniqueId !== null){
$result->inputFlags |= 1 << PlayerAuthInputFlags::IN_CLIENT_PREDICTED_VEHICLE;
}

$result->inputMode = $inputMode;
$result->playMode = $playMode;
Expand All @@ -114,6 +119,7 @@ public static function create(
$result->itemInteractionData = $itemInteractionData;
$result->itemStackRequest = $itemStackRequest;
$result->blockActions = $blockActions;
$result->clientPredictedVehicleActorUniqueId = $clientPredictedVehicleActorUniqueId;
$result->analogMoveVecX = $analogMoveVecX;
$result->analogMoveVecZ = $analogMoveVecZ;
return $result;
Expand Down Expand Up @@ -198,6 +204,8 @@ public function getBlockActions() : ?array{
return $this->blockActions;
}

public function getClientPredictedVehicleActorUniqueId() : ?int{ return $this->clientPredictedVehicleActorUniqueId; }

public function getAnalogMoveVecX() : float{ return $this->analogMoveVecX; }

public function getAnalogMoveVecZ() : float{ return $this->analogMoveVecZ; }
Expand Down Expand Up @@ -240,6 +248,9 @@ protected function decodePayload(PacketSerializer $in) : void{
};
}
}
if($this->hasFlag(PlayerAuthInputFlags::IN_CLIENT_PREDICTED_VEHICLE)){
$this->clientPredictedVehicleActorUniqueId = $in->getActorUniqueId();
}
$this->analogMoveVecX = $in->getLFloat();
$this->analogMoveVecZ = $in->getLFloat();
}
Expand Down Expand Up @@ -274,6 +285,9 @@ protected function encodePayload(PacketSerializer $out) : void{
$blockAction->write($out);
}
}
if($this->clientPredictedVehicleActorUniqueId !== null){
$out->putActorUniqueId($this->clientPredictedVehicleActorUniqueId);
}
$out->putLFloat($this->analogMoveVecX);
$out->putLFloat($this->analogMoveVecZ);
}
Expand Down
2 changes: 2 additions & 0 deletions src/PlayerListPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protected function decodePayload(PacketSerializer $in) : void{
$entry->skinData = $in->getSkin();
$entry->isTeacher = $in->getBool();
$entry->isHost = $in->getBool();
$entry->isSubClient = $in->getBool();
}else{
$entry->uuid = $in->getUUID();
}
Expand Down Expand Up @@ -96,6 +97,7 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putSkin($entry->skinData);
$out->putBool($entry->isTeacher);
$out->putBool($entry->isHost);
$out->putBool($entry->isSubClient);
}else{
$out->putUUID($entry->uuid);
}
Expand Down
11 changes: 5 additions & 6 deletions src/ProtocolInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ private function __construct(){
*/

/** Actual Minecraft: PE protocol version */
public const CURRENT_PROTOCOL = 630;
public const CURRENT_PROTOCOL = 649;
/** Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. */
public const MINECRAFT_VERSION = 'v1.20.50';
public const MINECRAFT_VERSION = 'v1.20.60';
/** Version number sent to clients in ping responses. */
public const MINECRAFT_VERSION_NETWORK = '1.20.50';
public const MINECRAFT_VERSION_NETWORK = '1.20.60';

public const LOGIN_PACKET = 0x01;
public const PLAY_STATUS_PACKET = 0x02;
Expand All @@ -53,7 +53,7 @@ private function __construct(){
public const ADD_ACTOR_PACKET = 0x0d;
public const REMOVE_ACTOR_PACKET = 0x0e;
public const ADD_ITEM_ACTOR_PACKET = 0x0f;

public const SERVER_PLAYER_POST_MOVE_POSITION_PACKET = 0x10;
public const TAKE_ITEM_ACTOR_PACKET = 0x11;
public const MOVE_ACTOR_ABSOLUTE_PACKET = 0x12;
public const MOVE_PLAYER_PACKET = 0x13;
Expand Down Expand Up @@ -163,8 +163,6 @@ private function __construct(){
public const LEVEL_EVENT_GENERIC_PACKET = 0x7c;
public const LECTERN_UPDATE_PACKET = 0x7d;

public const ADD_ENTITY_PACKET = 0x7f;
public const REMOVE_ENTITY_PACKET = 0x80;
public const CLIENT_CACHE_STATUS_PACKET = 0x81;
public const ON_SCREEN_TEXTURE_ANIMATION_PACKET = 0x82;
public const MAP_CREATE_LOCKED_COPY_PACKET = 0x83;
Expand Down Expand Up @@ -245,5 +243,6 @@ private function __construct(){
public const REFRESH_ENTITLEMENTS_PACKET = 0x131;
public const PLAYER_TOGGLE_CRAFTER_SLOT_REQUEST_PACKET = 0x132;
public const SET_PLAYER_INVENTORY_OPTIONS_PACKET = 0x133;
public const SET_HUD_PACKET = 0x134;

}
48 changes: 0 additions & 48 deletions src/RemoveEntityPacket.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,34 @@

namespace pocketmine\network\mcpe\protocol;

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

class AddEntityPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::ADD_ENTITY_PACKET;
class ServerPlayerPostMovePositionPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::SERVER_PLAYER_POST_MOVE_POSITION_PACKET;

private int $entityNetId;
private Vector3 $position;

/**
* @generate-create-func
*/
public static function create(int $entityNetId) : self{
public static function create(Vector3 $position) : self{
$result = new self;
$result->entityNetId = $entityNetId;
$result->position = $position;
return $result;
}

public function getEntityNetId() : int{
return $this->entityNetId;
}
public function getPosition() : Vector3{ return $this->position; }

protected function decodePayload(PacketSerializer $in) : void{
$this->entityNetId = $in->getUnsignedVarInt();
$this->position = $in->getVector3();
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt($this->entityNetId);
$out->putVector3($this->position);
}

public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleAddEntity($this);
return $handler->handleServerPlayerPostMovePosition($this);
}
}
Loading

0 comments on commit 19e6411

Please sign in to comment.