Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocol changes for 1.21.20 #260

Merged
merged 6 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/CameraInstructionPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\camera\CameraFadeInstruction;
use pocketmine\network\mcpe\protocol\types\camera\CameraSetInstruction;
use pocketmine\network\mcpe\protocol\types\camera\CameraTargetInstruction;

class CameraInstructionPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::CAMERA_INSTRUCTION_PACKET;

private ?CameraSetInstruction $set;
private ?bool $clear;
private ?CameraFadeInstruction $fade;
private ?CameraTargetInstruction $target;
private ?bool $removeTarget;

/**
* @generate-create-func
*/
public static function create(?CameraSetInstruction $set, ?bool $clear, ?CameraFadeInstruction $fade) : self{
public static function create(?CameraSetInstruction $set, ?bool $clear, ?CameraFadeInstruction $fade, ?CameraTargetInstruction $target, ?bool $removeTarget) : self{
$result = new self;
$result->set = $set;
$result->clear = $clear;
$result->fade = $fade;
$result->target = $target;
$result->removeTarget = $removeTarget;
return $result;
}

Expand All @@ -42,16 +47,22 @@ public function getClear() : ?bool{ return $this->clear; }

public function getFade() : ?CameraFadeInstruction{ return $this->fade; }

public function getTarget() : ?CameraTargetInstruction{ return $this->target; }

protected function decodePayload(PacketSerializer $in) : void{
$this->set = $in->readOptional(fn() => CameraSetInstruction::read($in));
$this->clear = $in->readOptional($in->getBool(...));
$this->fade = $in->readOptional(fn() => CameraFadeInstruction::read($in));
$this->target = $in->readOptional(fn() => CameraTargetInstruction::read($in));
$this->removeTarget = $in->readOptional($in->getBool(...));
}

protected function encodePayload(PacketSerializer $out) : void{
$out->writeOptional($this->set, fn(CameraSetInstruction $v) => $v->write($out));
$out->writeOptional($this->clear, $out->putBool(...));
$out->writeOptional($this->fade, fn(CameraFadeInstruction $v) => $v->write($out));
$out->writeOptional($this->target, fn(CameraTargetInstruction $v) => $v->write($out));
$out->writeOptional($this->removeTarget, $out->putBool(...));
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
6 changes: 5 additions & 1 deletion src/ChangeDimensionPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,32 @@ class ChangeDimensionPacket extends DataPacket implements ClientboundPacket{
public int $dimension;
public Vector3 $position;
public bool $respawn = false;
private ?int $loadingScreenId = null;

/**
* @generate-create-func
*/
public static function create(int $dimension, Vector3 $position, bool $respawn) : self{
public static function create(int $dimension, Vector3 $position, bool $respawn, ?int $loadingScreenId) : self{
$result = new self;
$result->dimension = $dimension;
$result->position = $position;
$result->respawn = $respawn;
$result->loadingScreenId = $loadingScreenId;
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->dimension = $in->getVarInt();
$this->position = $in->getVector3();
$this->respawn = $in->getBool();
$this->loadingScreenId = $in->readOptional(fn() => $in->getLInt());
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putVarInt($this->dimension);
$out->putVector3($this->position);
$out->putBool($this->respawn);
$out->writeOptional($this->loadingScreenId, $out->putLInt(...));
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
2 changes: 1 addition & 1 deletion src/ClientboundCloseFormPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ protected function encodePayload(PacketSerializer $out) : void{
}

public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleCloseForm($this);
return $handler->handleClientboundCloseForm($this);
}
}
44 changes: 44 additions & 0 deletions src/CurrentStructureFeaturePacket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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 CurrentStructureFeaturePacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::CURRENT_STRUCTURE_FEATURE_PACKET;

public string $currentStructureFeature;

/**
* @generate-create-func
*/
public static function create(string $currentStructureFeature) : self{
$result = new self;
$result->currentStructureFeature = $currentStructureFeature;
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->currentStructureFeature = $in->getString();
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putString($this->currentStructureFeature);
}

public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleCurrentStructureFeature($this);
}
}
16 changes: 10 additions & 6 deletions src/DisconnectPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ class DisconnectPacket extends DataPacket implements ClientboundPacket, Serverbo

public int $reason; //TODO: add constants / enum
public ?string $message;
public ?string $filteredMessage;

/**
* @generate-create-func
*/
public static function create(int $reason, ?string $message) : self{
public static function create(int $reason, ?string $message, ?string $filteredMessage) : self{
$result = new self;
$result->reason = $reason;
$result->message = $message;
$result->filteredMessage = $filteredMessage;
return $result;
}

Expand All @@ -38,15 +40,17 @@ public function canBeSentBeforeLogin() : bool{

protected function decodePayload(PacketSerializer $in) : void{
$this->reason = $in->getVarInt();
$hideDisconnectionScreen = $in->getBool();
$this->message = $hideDisconnectionScreen ? null : $in->getString();
$skipMessage = $in->getBool();
$this->message = $skipMessage ? null : $in->getString();
$this->filteredMessage = $skipMessage ? null : $in->getString();
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putVarInt($this->reason);
$out->putBool($this->message === null);
if($this->message !== null){
$out->putString($this->message);
$out->putBool($skipMessage = $this->message === null && $this->filteredMessage === null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bool is not obvious what it is, what it does is to hide/skip the disconnection screen, please document this

if(!$skipMessage){
$out->putString($this->message ?? "");
$out->putString($this->filteredMessage ?? "");
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/EditorNetworkPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,33 @@
class EditorNetworkPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{
public const NETWORK_ID = ProtocolInfo::EDITOR_NETWORK_PACKET;

private bool $isRouteToManager;
/** @phpstan-var CacheableNbt<\pocketmine\nbt\tag\CompoundTag> */
private CacheableNbt $payload;

/**
* @generate-create-func
* @phpstan-param CacheableNbt<\pocketmine\nbt\tag\CompoundTag> $payload
*/
public static function create(CacheableNbt $payload) : self{
public static function create(bool $isRouteToManager, CacheableNbt $payload) : self{
$result = new self;
$result->isRouteToManager = $isRouteToManager;
$result->payload = $payload;
return $result;
}

/** @phpstan-return CacheableNbt<\pocketmine\nbt\tag\CompoundTag> */
public function getPayload() : CacheableNbt{ return $this->payload; }

public function isRouteToManager() : bool{ return $this->isRouteToManager; }

protected function decodePayload(PacketSerializer $in) : void{
$this->isRouteToManager = $in->getBool();
$this->payload = new CacheableNbt($in->getNbtCompoundRoot());
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putBool($this->isRouteToManager);
$out->put($this->payload->getEncodedNbt());
}

Expand Down
6 changes: 5 additions & 1 deletion src/InventoryContentPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ class InventoryContentPacket extends DataPacket implements ClientboundPacket{
public int $windowId;
/** @var ItemStackWrapper[] */
public array $items = [];
public int $dynamicContainerId;

/**
* @generate-create-func
* @param ItemStackWrapper[] $items
*/
public static function create(int $windowId, array $items) : self{
public static function create(int $windowId, array $items, int $dynamicContainerId) : self{
$result = new self;
$result->windowId = $windowId;
$result->items = $items;
$result->dynamicContainerId = $dynamicContainerId;
return $result;
}

Expand All @@ -42,6 +44,7 @@ protected function decodePayload(PacketSerializer $in) : void{
for($i = 0; $i < $count; ++$i){
$this->items[] = $in->getItemStackWrapper();
}
$this->dynamicContainerId = $in->getUnsignedVarInt();
}

protected function encodePayload(PacketSerializer $out) : void{
Expand All @@ -50,6 +53,7 @@ protected function encodePayload(PacketSerializer $out) : void{
foreach($this->items as $item){
$out->putItemStackWrapper($item);
}
$out->putUnsignedVarInt($this->dynamicContainerId);
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
6 changes: 5 additions & 1 deletion src/InventorySlotPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,31 @@ class InventorySlotPacket extends DataPacket implements ClientboundPacket{
public int $windowId;
public int $inventorySlot;
public ItemStackWrapper $item;
public int $dynamicContainerId;

/**
* @generate-create-func
*/
public static function create(int $windowId, int $inventorySlot, ItemStackWrapper $item) : self{
public static function create(int $windowId, int $inventorySlot, ItemStackWrapper $item, int $dynamicContainerId) : self{
$result = new self;
$result->windowId = $windowId;
$result->inventorySlot = $inventorySlot;
$result->item = $item;
$result->dynamicContainerId = $dynamicContainerId;
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->windowId = $in->getUnsignedVarInt();
$this->inventorySlot = $in->getUnsignedVarInt();
$this->dynamicContainerId = $in->getUnsignedVarInt();
$this->item = $in->getItemStackWrapper();
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt($this->windowId);
$out->putUnsignedVarInt($this->inventorySlot);
$out->putUnsignedVarInt($this->dynamicContainerId);
$out->putItemStackWrapper($this->item);
}

Expand Down
50 changes: 50 additions & 0 deletions src/JigsawStructureDataPacket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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;
use pocketmine\network\mcpe\protocol\types\CacheableNbt;

class JigsawStructureDataPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::JIGSAW_STRUCTURE_DATA_PACKET;

/** @phpstan-var CacheableNbt<\pocketmine\nbt\tag\CompoundTag> */
ShockedPlot7560 marked this conversation as resolved.
Show resolved Hide resolved
private CacheableNbt $nbt;

/**
* @generate-create-func
* @phpstan-param CacheableNbt<\pocketmine\nbt\tag\CompoundTag> $nbt
ShockedPlot7560 marked this conversation as resolved.
Show resolved Hide resolved
*/
public static function create(CacheableNbt $nbt) : self{
$result = new self;
$result->nbt = $nbt;
return $result;
}

/** @phpstan-return CacheableNbt<\pocketmine\nbt\tag\CompoundTag> */
ShockedPlot7560 marked this conversation as resolved.
Show resolved Hide resolved
public function getNbt() : CacheableNbt{ return $this->nbt; }

protected function decodePayload(PacketSerializer $in) : void{
$this->nbt = new CacheableNbt($in->getNbtCompoundRoot());
}

protected function encodePayload(PacketSerializer $out) : void{
$out->put($this->nbt->getEncodedNbt());
}

public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleJigsawStructureData($this);
}
}
6 changes: 5 additions & 1 deletion src/MobArmorEquipmentPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ class MobArmorEquipmentPacket extends DataPacket implements ClientboundPacket, S
public ItemStackWrapper $chest;
public ItemStackWrapper $legs;
public ItemStackWrapper $feet;
public ItemStackWrapper $body;

/**
* @generate-create-func
*/
public static function create(int $actorRuntimeId, ItemStackWrapper $head, ItemStackWrapper $chest, ItemStackWrapper $legs, ItemStackWrapper $feet) : self{
public static function create(int $actorRuntimeId, ItemStackWrapper $head, ItemStackWrapper $chest, ItemStackWrapper $legs, ItemStackWrapper $feet, ItemStackWrapper $body) : self{
$result = new self;
$result->actorRuntimeId = $actorRuntimeId;
$result->head = $head;
$result->chest = $chest;
$result->legs = $legs;
$result->feet = $feet;
$result->body = $body;
return $result;
}

Expand All @@ -47,6 +49,7 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->chest = $in->getItemStackWrapper();
$this->legs = $in->getItemStackWrapper();
$this->feet = $in->getItemStackWrapper();
$this->body = $in->getItemStackWrapper();
}

protected function encodePayload(PacketSerializer $out) : void{
Expand All @@ -55,6 +58,7 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putItemStackWrapper($this->chest);
$out->putItemStackWrapper($this->legs);
$out->putItemStackWrapper($this->feet);
$out->putItemStackWrapper($this->body);
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
18 changes: 17 additions & 1 deletion src/PacketHandlerDefaultImplTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,23 @@ public function handleAwardAchievement(AwardAchievementPacket $packet) : bool{
return false;
}

public function handleCloseForm(ClientboundCloseFormPacket $packet) : bool{
public function handleClientboundCloseForm(ClientboundCloseFormPacket $packet) : bool{
return false;
}

public function handleServerboundLoadingScreen(ServerboundLoadingScreenPacket $packet) : bool{
return false;
}

public function handleJigsawStructureData(JigsawStructureDataPacket $packet) : bool{
return false;
}

public function handleCurrentStructureFeature(CurrentStructureFeaturePacket $packet) : bool{
return false;
}

public function handleServerboundDiagnostics(ServerboundDiagnosticsPacket $packet) : bool{
return false;
}
}
Loading