From cac5a16198cc22540e80955f6c84b3d9a3d5cb3a Mon Sep 17 00:00:00 2001 From: Superomarking <71559522+Superomarking@users.noreply.github.com> Date: Sat, 17 Aug 2024 21:11:09 +0300 Subject: [PATCH 1/4] Added property getters in packets (#265) A few packets (mostly new) don't have getters for certain private properties --- src/CameraInstructionPacket.php | 2 ++ src/ChangeDimensionPacket.php | 2 ++ src/UpdateClientInputLocksPacket.php | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/src/CameraInstructionPacket.php b/src/CameraInstructionPacket.php index 1f1f3db7..1871e9e0 100644 --- a/src/CameraInstructionPacket.php +++ b/src/CameraInstructionPacket.php @@ -49,6 +49,8 @@ public function getFade() : ?CameraFadeInstruction{ return $this->fade; } public function getTarget() : ?CameraTargetInstruction{ return $this->target; } + public function getRemoveTarget() : ?bool{ return $this->removeTarget; } + protected function decodePayload(PacketSerializer $in) : void{ $this->set = $in->readOptional(fn() => CameraSetInstruction::read($in)); $this->clear = $in->readOptional($in->getBool(...)); diff --git a/src/ChangeDimensionPacket.php b/src/ChangeDimensionPacket.php index 6e2cdd34..dd2f12ae 100644 --- a/src/ChangeDimensionPacket.php +++ b/src/ChangeDimensionPacket.php @@ -37,6 +37,8 @@ public static function create(int $dimension, Vector3 $position, bool $respawn, return $result; } + public function getLoadingScreenId() : ?int{ return $this->loadingScreenId; } + protected function decodePayload(PacketSerializer $in) : void{ $this->dimension = $in->getVarInt(); $this->position = $in->getVector3(); diff --git a/src/UpdateClientInputLocksPacket.php b/src/UpdateClientInputLocksPacket.php index 25a6f098..add3e60b 100644 --- a/src/UpdateClientInputLocksPacket.php +++ b/src/UpdateClientInputLocksPacket.php @@ -33,6 +33,10 @@ public static function create(int $flags, Vector3 $position) : self{ return $result; } + public function getFlags() : int{ return $this->flags; } + + public function getPosition() : Vector3{ return $this->position; } + protected function decodePayload(PacketSerializer $in) : void{ $this->flags = $in->getUnsignedVarInt(); $this->position = $in->getVector3(); From 21d8038d60f15887fdfb2532edf52aac9e446f68 Mon Sep 17 00:00:00 2001 From: Dries C Date: Sun, 1 Sep 2024 17:14:34 +0200 Subject: [PATCH 2/4] Protocol changes for 1.21.30 --- src/CameraAimAssistPacket.php | 67 +++++++++++++++ src/ContainerRegistryCleanupPacket.php | 59 +++++++++++++ src/EmotePacket.php | 8 +- src/InventoryContentPacket.php | 15 ++-- src/InventorySlotPacket.php | 15 ++-- src/PacketHandlerDefaultImplTrait.php | 8 ++ src/PacketHandlerInterface.php | 4 + src/ProtocolInfo.php | 8 +- src/ResourcePacksInfoPacket.php | 27 +----- src/TransferPacket.php | 6 +- src/UpdateAttributesPacket.php | 17 ++-- src/serializer/PacketSerializer.php | 49 ----------- src/types/PlayerAction.php | 2 +- src/types/PlayerAuthInputFlags.php | 5 ++ .../camera/CameraAimAssistActionType.php | 24 ++++++ .../camera/CameraAimAssistTargetMode.php | 24 ++++++ src/types/camera/CameraPreset.php | 19 +++++ src/types/entity/UpdateAttribute.php | 85 +++++++++++++++++++ src/types/inventory/ContainerIds.php | 2 + src/types/inventory/FullContainerName.php | 8 +- .../resourcepacks/BehaviorPackInfoEntry.php | 83 ------------------ 21 files changed, 351 insertions(+), 184 deletions(-) create mode 100644 src/CameraAimAssistPacket.php create mode 100644 src/ContainerRegistryCleanupPacket.php create mode 100644 src/types/camera/CameraAimAssistActionType.php create mode 100644 src/types/camera/CameraAimAssistTargetMode.php create mode 100644 src/types/entity/UpdateAttribute.php delete mode 100644 src/types/resourcepacks/BehaviorPackInfoEntry.php diff --git a/src/CameraAimAssistPacket.php b/src/CameraAimAssistPacket.php new file mode 100644 index 00000000..e15eab2b --- /dev/null +++ b/src/CameraAimAssistPacket.php @@ -0,0 +1,67 @@ + + * + * 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\math\Vector2; +use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; +use pocketmine\network\mcpe\protocol\types\camera\CameraAimAssistActionType; +use pocketmine\network\mcpe\protocol\types\camera\CameraAimAssistTargetMode; + +class CameraAimAssistPacket extends DataPacket implements ClientboundPacket{ + public const NETWORK_ID = ProtocolInfo::CAMERA_AIM_ASSIST_PACKET; + + private Vector2 $viewAngle; + private float $distance; + private CameraAimAssistTargetMode $targetMode; + private CameraAimAssistActionType $actionType; + + /** + * @generate-create-func + */ + public static function create(Vector2 $viewAngle, float $distance, CameraAimAssistTargetMode $targetMode, CameraAimAssistActionType $actionType) : self{ + $result = new self; + $result->viewAngle = $viewAngle; + $result->distance = $distance; + $result->targetMode = $targetMode; + $result->actionType = $actionType; + return $result; + } + + public function getViewAngle() : Vector2{ return $this->viewAngle; } + + public function getDistance() : float{ return $this->distance; } + + public function getTargetMode() : CameraAimAssistTargetMode{ return $this->targetMode; } + + public function getActionType() : CameraAimAssistActionType{ return $this->actionType; } + + protected function decodePayload(PacketSerializer $in) : void{ + $this->viewAngle = $in->getVector2(); + $this->distance = $in->getLFloat(); + $this->targetMode = CameraAimAssistTargetMode::fromPacket($in->getByte()); + $this->actionType = CameraAimAssistActionType::fromPacket($in->getByte()); + } + + protected function encodePayload(PacketSerializer $out) : void{ + $out->putVector2($this->viewAngle); + $out->putLFloat($this->distance); + $out->putByte($this->targetMode->value); + $out->putByte($this->actionType->value); + } + + public function handle(PacketHandlerInterface $handler) : bool{ + return $handler->handleCameraAimAssist($this); + } +} diff --git a/src/ContainerRegistryCleanupPacket.php b/src/ContainerRegistryCleanupPacket.php new file mode 100644 index 00000000..0d7ca58d --- /dev/null +++ b/src/ContainerRegistryCleanupPacket.php @@ -0,0 +1,59 @@ + + * + * 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\inventory\FullContainerName; +use function count; + +class ContainerRegistryCleanupPacket extends DataPacket implements ClientboundPacket{ + public const NETWORK_ID = ProtocolInfo::CONTAINER_REGISTRY_CLEANUP_PACKET; + + /** @var FullContainerName[] */ + private array $removedContainers; + + /** + * @generate-create-func + * @param FullContainerName[] $removedContainers + */ + public static function create(array $removedContainers) : self{ + $result = new self; + $result->removedContainers = $removedContainers; + return $result; + } + + /** + * @return FullContainerName[] + */ + public function getRemovedContainers() : array{ return $this->removedContainers; } + + protected function decodePayload(PacketSerializer $in) : void{ + $this->removedContainers = []; + for($i = 0, $len = $in->getUnsignedVarInt(); $i < $len; ++$i){ + $this->removedContainers[] = FullContainerName::read($in); + } + } + + protected function encodePayload(PacketSerializer $out) : void{ + $out->putUnsignedVarInt(count($this->removedContainers)); + foreach($this->removedContainers as $container){ + $container->write($out); + } + } + + public function handle(PacketHandlerInterface $handler) : bool{ + return $handler->handleContainerRegistryCleanup($this); + } +} diff --git a/src/EmotePacket.php b/src/EmotePacket.php index b925fea1..52b072be 100644 --- a/src/EmotePacket.php +++ b/src/EmotePacket.php @@ -24,6 +24,7 @@ class EmotePacket extends DataPacket implements ClientboundPacket, ServerboundPa private int $actorRuntimeId; private string $emoteId; + private int $emoteLengthTicks; private string $xboxUserId; private string $platformChatId; private int $flags; @@ -31,10 +32,11 @@ class EmotePacket extends DataPacket implements ClientboundPacket, ServerboundPa /** * @generate-create-func */ - public static function create(int $actorRuntimeId, string $emoteId, string $xboxUserId, string $platformChatId, int $flags) : self{ + public static function create(int $actorRuntimeId, string $emoteId, int $emoteLengthTicks, string $xboxUserId, string $platformChatId, int $flags) : self{ $result = new self; $result->actorRuntimeId = $actorRuntimeId; $result->emoteId = $emoteId; + $result->emoteLengthTicks = $emoteLengthTicks; $result->xboxUserId = $xboxUserId; $result->platformChatId = $platformChatId; $result->flags = $flags; @@ -49,6 +51,8 @@ public function getEmoteId() : string{ return $this->emoteId; } + public function getEmoteLengthTicks() : int{ return $this->emoteLengthTicks; } + public function getXboxUserId() : string{ return $this->xboxUserId; } public function getPlatformChatId() : string{ return $this->platformChatId; } @@ -60,6 +64,7 @@ public function getFlags() : int{ protected function decodePayload(PacketSerializer $in) : void{ $this->actorRuntimeId = $in->getActorRuntimeId(); $this->emoteId = $in->getString(); + $this->emoteLengthTicks = $in->getUnsignedVarInt(); $this->xboxUserId = $in->getString(); $this->platformChatId = $in->getString(); $this->flags = $in->getByte(); @@ -68,6 +73,7 @@ protected function decodePayload(PacketSerializer $in) : void{ protected function encodePayload(PacketSerializer $out) : void{ $out->putActorRuntimeId($this->actorRuntimeId); $out->putString($this->emoteId); + $out->putUnsignedVarInt($this->emoteLengthTicks); $out->putString($this->xboxUserId); $out->putString($this->platformChatId); $out->putByte($this->flags); diff --git a/src/InventoryContentPacket.php b/src/InventoryContentPacket.php index c3cb7702..1e7e5f64 100644 --- a/src/InventoryContentPacket.php +++ b/src/InventoryContentPacket.php @@ -15,6 +15,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; +use pocketmine\network\mcpe\protocol\types\inventory\FullContainerName; use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper; use function count; @@ -24,17 +25,19 @@ class InventoryContentPacket extends DataPacket implements ClientboundPacket{ public int $windowId; /** @var ItemStackWrapper[] */ public array $items = []; - public int $dynamicContainerId; + public FullContainerName $containerName; + public int $dynamicContainerSize; /** * @generate-create-func * @param ItemStackWrapper[] $items */ - public static function create(int $windowId, array $items, int $dynamicContainerId) : self{ + public static function create(int $windowId, array $items, FullContainerName $containerName, int $dynamicContainerSize) : self{ $result = new self; $result->windowId = $windowId; $result->items = $items; - $result->dynamicContainerId = $dynamicContainerId; + $result->containerName = $containerName; + $result->dynamicContainerSize = $dynamicContainerSize; return $result; } @@ -44,7 +47,8 @@ protected function decodePayload(PacketSerializer $in) : void{ for($i = 0; $i < $count; ++$i){ $this->items[] = $in->getItemStackWrapper(); } - $this->dynamicContainerId = $in->getUnsignedVarInt(); + $this->containerName = FullContainerName::read($in); + $this->dynamicContainerSize = $in->getUnsignedVarInt(); } protected function encodePayload(PacketSerializer $out) : void{ @@ -53,7 +57,8 @@ protected function encodePayload(PacketSerializer $out) : void{ foreach($this->items as $item){ $out->putItemStackWrapper($item); } - $out->putUnsignedVarInt($this->dynamicContainerId); + $this->containerName->write($out); + $out->putUnsignedVarInt($this->dynamicContainerSize); } public function handle(PacketHandlerInterface $handler) : bool{ diff --git a/src/InventorySlotPacket.php b/src/InventorySlotPacket.php index cb860ecc..b98af415 100644 --- a/src/InventorySlotPacket.php +++ b/src/InventorySlotPacket.php @@ -15,6 +15,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; +use pocketmine\network\mcpe\protocol\types\inventory\FullContainerName; use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper; class InventorySlotPacket extends DataPacket implements ClientboundPacket{ @@ -22,32 +23,36 @@ class InventorySlotPacket extends DataPacket implements ClientboundPacket{ public int $windowId; public int $inventorySlot; + public FullContainerName $containerName; + public int $dynamicContainerSize; public ItemStackWrapper $item; - public int $dynamicContainerId; /** * @generate-create-func */ - public static function create(int $windowId, int $inventorySlot, ItemStackWrapper $item, int $dynamicContainerId) : self{ + public static function create(int $windowId, int $inventorySlot, FullContainerName $containerName, int $dynamicContainerSize, ItemStackWrapper $item) : self{ $result = new self; $result->windowId = $windowId; $result->inventorySlot = $inventorySlot; + $result->containerName = $containerName; + $result->dynamicContainerSize = $dynamicContainerSize; $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->containerName = FullContainerName::read($in); + $this->dynamicContainerSize = $in->getUnsignedVarInt(); $this->item = $in->getItemStackWrapper(); } protected function encodePayload(PacketSerializer $out) : void{ $out->putUnsignedVarInt($this->windowId); $out->putUnsignedVarInt($this->inventorySlot); - $out->putUnsignedVarInt($this->dynamicContainerId); + $this->containerName->write($out); + $out->putUnsignedVarInt($this->dynamicContainerSize); $out->putItemStackWrapper($this->item); } diff --git a/src/PacketHandlerDefaultImplTrait.php b/src/PacketHandlerDefaultImplTrait.php index 3b68ea2d..4f658842 100644 --- a/src/PacketHandlerDefaultImplTrait.php +++ b/src/PacketHandlerDefaultImplTrait.php @@ -821,4 +821,12 @@ public function handleCurrentStructureFeature(CurrentStructureFeaturePacket $pac public function handleServerboundDiagnostics(ServerboundDiagnosticsPacket $packet) : bool{ return false; } + + public function handleCameraAimAssist(CameraAimAssistPacket $packet) : bool{ + return false; + } + + public function handleContainerRegistryCleanup(ContainerRegistryCleanupPacket $packet) : bool{ + return false; + } } diff --git a/src/PacketHandlerInterface.php b/src/PacketHandlerInterface.php index c79632fa..0a606333 100644 --- a/src/PacketHandlerInterface.php +++ b/src/PacketHandlerInterface.php @@ -417,4 +417,8 @@ public function handleJigsawStructureData(JigsawStructureDataPacket $packet) : b public function handleCurrentStructureFeature(CurrentStructureFeaturePacket $packet) : bool; public function handleServerboundDiagnostics(ServerboundDiagnosticsPacket $packet) : bool; + + public function handleCameraAimAssist(CameraAimAssistPacket $packet) : bool; + + public function handleContainerRegistryCleanup(ContainerRegistryCleanupPacket $packet) : bool; } diff --git a/src/ProtocolInfo.php b/src/ProtocolInfo.php index c73ec6de..97a42c84 100644 --- a/src/ProtocolInfo.php +++ b/src/ProtocolInfo.php @@ -32,11 +32,11 @@ private function __construct(){ */ /** Actual Minecraft: PE protocol version */ - public const CURRENT_PROTOCOL = 712; + public const CURRENT_PROTOCOL = 729; /** Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. */ - public const MINECRAFT_VERSION = 'v1.21.20'; + public const MINECRAFT_VERSION = 'v1.21.30'; /** Version number sent to clients in ping responses. */ - public const MINECRAFT_VERSION_NETWORK = '1.21.20'; + public const MINECRAFT_VERSION_NETWORK = '1.21.30'; public const LOGIN_PACKET = 0x01; public const PLAY_STATUS_PACKET = 0x02; @@ -251,4 +251,6 @@ private function __construct(){ public const JIGSAW_STRUCTURE_DATA_PACKET = 0x139; public const CURRENT_STRUCTURE_FEATURE_PACKET = 0x13a; public const SERVERBOUND_DIAGNOSTICS_PACKET = 0x13b; + public const CAMERA_AIM_ASSIST_PACKET = 0x13c; + public const CONTAINER_REGISTRY_CLEANUP_PACKET = 0x13d; } diff --git a/src/ResourcePacksInfoPacket.php b/src/ResourcePacksInfoPacket.php index 769d7120..dfdbffa4 100644 --- a/src/ResourcePacksInfoPacket.php +++ b/src/ResourcePacksInfoPacket.php @@ -15,7 +15,6 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; -use pocketmine\network\mcpe\protocol\types\resourcepacks\BehaviorPackInfoEntry; use pocketmine\network\mcpe\protocol\types\resourcepacks\ResourcePackInfoEntry; use function count; @@ -24,12 +23,9 @@ class ResourcePacksInfoPacket extends DataPacket implements ClientboundPacket{ /** @var ResourcePackInfoEntry[] */ public array $resourcePackEntries = []; - /** @var BehaviorPackInfoEntry[] */ - public array $behaviorPackEntries = []; public bool $mustAccept = false; //if true, forces client to choose between accepting packs or being disconnected public bool $hasAddons = false; public bool $hasScripts = false; //if true, causes disconnect for any platform that doesn't support scripts yet - public bool $forceServerPacks = false; /** * @var string[] * @phpstan-var array @@ -39,26 +35,15 @@ class ResourcePacksInfoPacket extends DataPacket implements ClientboundPacket{ /** * @generate-create-func * @param ResourcePackInfoEntry[] $resourcePackEntries - * @param BehaviorPackInfoEntry[] $behaviorPackEntries * @param string[] $cdnUrls * @phpstan-param array $cdnUrls */ - public static function create( - array $resourcePackEntries, - array $behaviorPackEntries, - bool $mustAccept, - bool $hasAddons, - bool $hasScripts, - bool $forceServerPacks, - array $cdnUrls, - ) : self{ + public static function create(array $resourcePackEntries, bool $mustAccept, bool $hasAddons, bool $hasScripts, array $cdnUrls) : self{ $result = new self; $result->resourcePackEntries = $resourcePackEntries; - $result->behaviorPackEntries = $behaviorPackEntries; $result->mustAccept = $mustAccept; $result->hasAddons = $hasAddons; $result->hasScripts = $hasScripts; - $result->forceServerPacks = $forceServerPacks; $result->cdnUrls = $cdnUrls; return $result; } @@ -67,11 +52,6 @@ protected function decodePayload(PacketSerializer $in) : void{ $this->mustAccept = $in->getBool(); $this->hasAddons = $in->getBool(); $this->hasScripts = $in->getBool(); - $this->forceServerPacks = $in->getBool(); - $behaviorPackCount = $in->getLShort(); - while($behaviorPackCount-- > 0){ - $this->behaviorPackEntries[] = BehaviorPackInfoEntry::read($in); - } $resourcePackCount = $in->getLShort(); while($resourcePackCount-- > 0){ @@ -90,11 +70,6 @@ protected function encodePayload(PacketSerializer $out) : void{ $out->putBool($this->mustAccept); $out->putBool($this->hasAddons); $out->putBool($this->hasScripts); - $out->putBool($this->forceServerPacks); - $out->putLShort(count($this->behaviorPackEntries)); - foreach($this->behaviorPackEntries as $entry){ - $entry->write($out); - } $out->putLShort(count($this->resourcePackEntries)); foreach($this->resourcePackEntries as $entry){ $entry->write($out); diff --git a/src/TransferPacket.php b/src/TransferPacket.php index f9d2013e..eaf54985 100644 --- a/src/TransferPacket.php +++ b/src/TransferPacket.php @@ -21,25 +21,29 @@ class TransferPacket extends DataPacket implements ClientboundPacket{ public string $address; public int $port = 19132; + public bool $reloadWorld; /** * @generate-create-func */ - public static function create(string $address, int $port) : self{ + public static function create(string $address, int $port, bool $reloadWorld) : self{ $result = new self; $result->address = $address; $result->port = $port; + $result->reloadWorld = $reloadWorld; return $result; } protected function decodePayload(PacketSerializer $in) : void{ $this->address = $in->getString(); $this->port = $in->getLShort(); + $this->reloadWorld = $in->getBool(); } protected function encodePayload(PacketSerializer $out) : void{ $out->putString($this->address); $out->putLShort($this->port); + $out->putBool($this->reloadWorld); } public function handle(PacketHandlerInterface $handler) : bool{ diff --git a/src/UpdateAttributesPacket.php b/src/UpdateAttributesPacket.php index b21fca54..0f87684d 100644 --- a/src/UpdateAttributesPacket.php +++ b/src/UpdateAttributesPacket.php @@ -15,20 +15,20 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; -use pocketmine\network\mcpe\protocol\types\entity\Attribute; -use function array_values; +use pocketmine\network\mcpe\protocol\types\entity\UpdateAttribute; +use function count; class UpdateAttributesPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::UPDATE_ATTRIBUTES_PACKET; public int $actorRuntimeId; - /** @var Attribute[] */ + /** @var UpdateAttribute[] */ public array $entries = []; public int $tick = 0; /** * @generate-create-func - * @param Attribute[] $entries + * @param UpdateAttribute[] $entries */ public static function create(int $actorRuntimeId, array $entries, int $tick) : self{ $result = new self; @@ -40,13 +40,18 @@ public static function create(int $actorRuntimeId, array $entries, int $tick) : protected function decodePayload(PacketSerializer $in) : void{ $this->actorRuntimeId = $in->getActorRuntimeId(); - $this->entries = $in->getAttributeList(); + for($i = 0, $len = $in->getUnsignedVarInt(); $i < $len; ++$i){ + $this->entries[] = UpdateAttribute::read($in); + } $this->tick = $in->getUnsignedVarLong(); } protected function encodePayload(PacketSerializer $out) : void{ $out->putActorRuntimeId($this->actorRuntimeId); - $out->putAttributeList(...array_values($this->entries)); + $out->putUnsignedVarInt(count($this->entries)); + foreach($this->entries as $entry){ + $entry->write($out); + } $out->putUnsignedVarLong($this->tick); } diff --git a/src/serializer/PacketSerializer.php b/src/serializer/PacketSerializer.php index e893362d..a83032eb 100644 --- a/src/serializer/PacketSerializer.php +++ b/src/serializer/PacketSerializer.php @@ -23,8 +23,6 @@ use pocketmine\network\mcpe\protocol\types\BlockPosition; use pocketmine\network\mcpe\protocol\types\BoolGameRule; use pocketmine\network\mcpe\protocol\types\command\CommandOriginData; -use pocketmine\network\mcpe\protocol\types\entity\Attribute; -use pocketmine\network\mcpe\protocol\types\entity\AttributeModifier; use pocketmine\network\mcpe\protocol\types\entity\BlockPosMetadataProperty; use pocketmine\network\mcpe\protocol\types\entity\ByteMetadataProperty; use pocketmine\network\mcpe\protocol\types\entity\CompoundTagMetadataProperty; @@ -408,53 +406,6 @@ public function putEntityMetadata(array $metadata) : void{ } } - /** - * Reads a list of Attributes from the stream. - * @return Attribute[] - * - * @throws BinaryDataException - */ - public function getAttributeList() : array{ - $list = []; - $count = $this->getUnsignedVarInt(); - - for($i = 0; $i < $count; ++$i){ - $min = $this->getLFloat(); - $max = $this->getLFloat(); - $current = $this->getLFloat(); - $default = $this->getLFloat(); - $id = $this->getString(); - - $modifiers = []; - for($j = 0, $modifierCount = $this->getUnsignedVarInt(); $j < $modifierCount; $j++){ - $modifiers[] = AttributeModifier::read($this); - } - - $list[] = new Attribute($id, $min, $max, $current, $default, $modifiers); - } - - return $list; - } - - /** - * Writes a list of Attributes to the packet buffer using the standard format. - */ - public function putAttributeList(Attribute ...$attributes) : void{ - $this->putUnsignedVarInt(count($attributes)); - foreach($attributes as $attribute){ - $this->putLFloat($attribute->getMin()); - $this->putLFloat($attribute->getMax()); - $this->putLFloat($attribute->getCurrent()); - $this->putLFloat($attribute->getDefault()); - $this->putString($attribute->getId()); - - $this->putUnsignedVarInt(count($attribute->getModifiers())); - foreach($attribute->getModifiers() as $modifier){ - $modifier->write($this); - } - } - } - /** * @throws BinaryDataException */ diff --git a/src/types/PlayerAction.php b/src/types/PlayerAction.php index bb0558f6..30060a6a 100644 --- a/src/types/PlayerAction.php +++ b/src/types/PlayerAction.php @@ -42,7 +42,7 @@ private function __construct(){ public const SET_ENCHANTMENT_SEED = 20; //no longer used public const START_SWIMMING = 21; public const STOP_SWIMMING = 22; - public const START_SPIN_ATTACK = 23; + public const START_SPIN_ATTACK = 23; //no longer used public const STOP_SPIN_ATTACK = 24; public const INTERACT_BLOCK = 25; public const PREDICT_DESTROY_BLOCK = 26; diff --git a/src/types/PlayerAuthInputFlags.php b/src/types/PlayerAuthInputFlags.php index 2fcaaed2..77ea7259 100644 --- a/src/types/PlayerAuthInputFlags.php +++ b/src/types/PlayerAuthInputFlags.php @@ -101,5 +101,10 @@ final class PlayerAuthInputFlags{ public const IN_CLIENT_PREDICTED_VEHICLE = 45; public const PADDLING_LEFT = 46; public const PADDLING_RIGHT = 47; + public const BLOCK_BREAKING_DELAY_ENABLED = 48; + public const HORIZONTAL_COLLISION = 49; + public const VERTICAL_COLLISION = 50; + public const DOWN_LEFT = 51; + public const DOWN_RIGHT = 52; } diff --git a/src/types/camera/CameraAimAssistActionType.php b/src/types/camera/CameraAimAssistActionType.php new file mode 100644 index 00000000..55e09140 --- /dev/null +++ b/src/types/camera/CameraAimAssistActionType.php @@ -0,0 +1,24 @@ + + * + * 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\camera; + +use pocketmine\network\mcpe\protocol\types\PacketIntEnumTrait; + +enum CameraAimAssistActionType : int{ + use PacketIntEnumTrait; + + case SET = 0; + case CLEAR = 1; +} diff --git a/src/types/camera/CameraAimAssistTargetMode.php b/src/types/camera/CameraAimAssistTargetMode.php new file mode 100644 index 00000000..b6ae9fed --- /dev/null +++ b/src/types/camera/CameraAimAssistTargetMode.php @@ -0,0 +1,24 @@ + + * + * 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\camera; + +use pocketmine\network\mcpe\protocol\types\PacketIntEnumTrait; + +enum CameraAimAssistTargetMode : int{ + use PacketIntEnumTrait; + + case ANGLE = 0; + case DISTANCE = 1; +} diff --git a/src/types/camera/CameraPreset.php b/src/types/camera/CameraPreset.php index 4b3ee8df..b1642329 100644 --- a/src/types/camera/CameraPreset.php +++ b/src/types/camera/CameraPreset.php @@ -15,6 +15,7 @@ namespace pocketmine\network\mcpe\protocol\types\camera; use pocketmine\math\Vector2; +use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; final class CameraPreset{ @@ -29,7 +30,10 @@ public function __construct( private ?float $zPosition, private ?float $pitch, private ?float $yaw, + private ?float $rotationSpeed, + private ?bool $snapToTarget, private ?Vector2 $viewOffset, + private ?Vector3 $entityOffset, private ?float $radius, private ?int $audioListenerType, private ?bool $playerEffects @@ -49,8 +53,14 @@ public function getPitch() : ?float{ return $this->pitch; } public function getYaw() : ?float{ return $this->yaw; } + public function getRotationSpeed() : ?float { return $this->rotationSpeed; } + + public function getSnapToTarget() : ?bool { return $this->snapToTarget; } + public function getViewOffset() : ?Vector2{ return $this->viewOffset; } + public function getEntityOffset() : ?Vector3{ return $this->entityOffset; } + public function getRadius() : ?float{ return $this->radius; } public function getAudioListenerType() : ?int{ return $this->audioListenerType; } @@ -65,7 +75,10 @@ public static function read(PacketSerializer $in) : self{ $zPosition = $in->readOptional($in->getLFloat(...)); $pitch = $in->readOptional($in->getLFloat(...)); $yaw = $in->readOptional($in->getLFloat(...)); + $rotationSpeed = $in->readOptional($in->getLFloat(...)); + $snapToTarget = $in->readOptional($in->getBool(...)); $viewOffset = $in->readOptional($in->getVector2(...)); + $entityOffset = $in->readOptional($in->getVector3(...)); $radius = $in->readOptional($in->getLFloat(...)); $audioListenerType = $in->readOptional($in->getByte(...)); $playerEffects = $in->readOptional($in->getBool(...)); @@ -78,7 +91,10 @@ public static function read(PacketSerializer $in) : self{ $zPosition, $pitch, $yaw, + $rotationSpeed, + $snapToTarget, $viewOffset, + $entityOffset, $radius, $audioListenerType, $playerEffects @@ -93,7 +109,10 @@ public function write(PacketSerializer $out) : void{ $out->writeOptional($this->zPosition, $out->putLFloat(...)); $out->writeOptional($this->pitch, $out->putLFloat(...)); $out->writeOptional($this->yaw, $out->putLFloat(...)); + $out->writeOptional($this->rotationSpeed, $out->putLFloat(...)); + $out->writeOptional($this->snapToTarget, $out->putBool(...)); $out->writeOptional($this->viewOffset, $out->putVector2(...)); + $out->writeOptional($this->entityOffset, $out->putVector3(...)); $out->writeOptional($this->radius, $out->putLFloat(...)); $out->writeOptional($this->audioListenerType, $out->putByte(...)); $out->writeOptional($this->playerEffects, $out->putBool(...)); diff --git a/src/types/entity/UpdateAttribute.php b/src/types/entity/UpdateAttribute.php new file mode 100644 index 00000000..15425433 --- /dev/null +++ b/src/types/entity/UpdateAttribute.php @@ -0,0 +1,85 @@ + + * + * 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\entity; + +use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; +use function count; + +final class UpdateAttribute{ + /** + * @param AttributeModifier[] $modifiers + */ + public function __construct( + private string $id, + private float $min, + private float $max, + private float $current, + private float $defaultMin, + private float $defaultMax, + private float $default, + private array $modifiers + ){} + + public function getId() : string{ return $this->id; } + + public function getMin() : float{ return $this->min; } + + public function getMax() : float{ return $this->max; } + + public function getCurrent() : float{ return $this->current; } + + public function getDefaultMin() : float{ return $this->defaultMin; } + + public function getDefaultMax() : float{ return $this->defaultMax; } + + public function getDefault() : float{ return $this->default; } + + /** + * @return AttributeModifier[] + */ + public function getModifiers() : array{ return $this->modifiers; } + + public static function read(PacketSerializer $in) : self{ + $min = $in->getLFloat(); + $max = $in->getLFloat(); + $current = $in->getLFloat(); + $defaultMin = $in->getLFloat(); + $defaultMax = $in->getLFloat(); + $default = $in->getLFloat(); + $id = $in->getString(); + + $modifiers = []; + for($j = 0, $modifierCount = $in->getUnsignedVarInt(); $j < $modifierCount; $j++){ + $modifiers[] = AttributeModifier::read($in); + } + + return new self($id, $min, $max, $current, $defaultMin, $defaultMax, $default, $modifiers); + } + + public function write(PacketSerializer $out) : void{ + $out->putLFloat($this->min); + $out->putLFloat($this->max); + $out->putLFloat($this->current); + $out->putLFloat($this->defaultMin); + $out->putLFloat($this->defaultMax); + $out->putLFloat($this->default); + $out->putString($this->id); + + $out->putUnsignedVarInt(count($this->modifiers)); + foreach($this->modifiers as $modifier){ + $modifier->write($out); + } + } +} diff --git a/src/types/inventory/ContainerIds.php b/src/types/inventory/ContainerIds.php index 74eb6949..fa36c231 100644 --- a/src/types/inventory/ContainerIds.php +++ b/src/types/inventory/ContainerIds.php @@ -30,5 +30,7 @@ private function __construct(){ public const HOTBAR = 122; public const FIXED_INVENTORY = 123; public const UI = 124; + public const CONTAINER_ID_REGISTRY = 125; + public const CONTAINER_ID_REGISTRY_INVENTORY = 126; } diff --git a/src/types/inventory/FullContainerName.php b/src/types/inventory/FullContainerName.php index 49b90884..04227d0d 100644 --- a/src/types/inventory/FullContainerName.php +++ b/src/types/inventory/FullContainerName.php @@ -19,21 +19,21 @@ final class FullContainerName{ public function __construct( private int $containerId, - private int $dynamicId = 0 + private ?int $dynamicId = null ){} public function getContainerId() : int{ return $this->containerId; } - public function getDynamicId() : int{ return $this->dynamicId; } + public function getDynamicId() : ?int{ return $this->dynamicId; } public static function read(PacketSerializer $in) : self{ $containerId = $in->getByte(); - $dynamicId = $in->getLInt(); + $dynamicId = $in->readOptional($in->getLInt(...)); return new self($containerId, $dynamicId); } public function write(PacketSerializer $out) : void{ $out->putByte($this->containerId); - $out->putLInt($this->dynamicId); + $out->writeOptional($this->dynamicId, $out->putLInt(...)); } } diff --git a/src/types/resourcepacks/BehaviorPackInfoEntry.php b/src/types/resourcepacks/BehaviorPackInfoEntry.php deleted file mode 100644 index 230f73f6..00000000 --- a/src/types/resourcepacks/BehaviorPackInfoEntry.php +++ /dev/null @@ -1,83 +0,0 @@ - - * - * 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\resourcepacks; - -use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; - -class BehaviorPackInfoEntry{ - public function __construct( - private string $packId, - private string $version, - private int $sizeBytes, - private string $encryptionKey = "", - private string $subPackName = "", - private string $contentId = "", - private bool $hasScripts = false, - private bool $isAddonPack = false - ){} - - public function getPackId() : string{ - return $this->packId; - } - - public function getVersion() : string{ - return $this->version; - } - - public function getSizeBytes() : int{ - return $this->sizeBytes; - } - - public function getEncryptionKey() : string{ - return $this->encryptionKey; - } - - public function getSubPackName() : string{ - return $this->subPackName; - } - - public function getContentId() : string{ - return $this->contentId; - } - - public function hasScripts() : bool{ - return $this->hasScripts; - } - - public function isAddonPack() : bool{ return $this->isAddonPack; } - - public function write(PacketSerializer $out) : void{ - $out->putString($this->packId); - $out->putString($this->version); - $out->putLLong($this->sizeBytes); - $out->putString($this->encryptionKey); - $out->putString($this->subPackName); - $out->putString($this->contentId); - $out->putBool($this->hasScripts); - $out->putBool($this->isAddonPack); - } - - public static function read(PacketSerializer $in) : self{ - $uuid = $in->getString(); - $version = $in->getString(); - $sizeBytes = $in->getLLong(); - $encryptionKey = $in->getString(); - $subPackName = $in->getString(); - $contentId = $in->getString(); - $hasScripts = $in->getBool(); - $isAddonPack = $in->getBool(); - return new self($uuid, $version, $sizeBytes, $encryptionKey, $subPackName, $contentId, $hasScripts, $isAddonPack); - } -} From f03b01ce67e41397290066646b0e70fcf0e45752 Mon Sep 17 00:00:00 2001 From: Dries C Date: Sat, 14 Sep 2024 20:21:59 +0200 Subject: [PATCH 3/4] Update sound ids --- src/types/LevelSoundEvent.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/types/LevelSoundEvent.php b/src/types/LevelSoundEvent.php index 13a836d4..0ddba26e 100644 --- a/src/types/LevelSoundEvent.php +++ b/src/types/LevelSoundEvent.php @@ -329,7 +329,7 @@ private function __construct(){ public const AMBIENT_WARPED_FOREST_MOOD = 303; public const AMBIENT_SOULSAND_VALLEY_MOOD = 304; public const AMBIENT_NETHER_WASTES_MOOD = 305; - public const RESPAWN_ANCHOR_BASALT_DELTAS_MOOD = 306; + public const AMBIENT_BASALT_DELTAS_MOOD = 306; public const AMBIENT_CRIMSON_FOREST_MOOD = 307; public const RESPAWN_ANCHOR_CHARGE = 308; public const RESPAWN_ANCHOR_DEPLETE = 309; @@ -520,6 +520,9 @@ private function __construct(){ public const RECORD_CREATOR_MUSIC_BOX = 528; public const RECORD_PRECIPICE = 529; public const VAULT_REJECT_REWARDED_PLAYER = 530; + public const IMITATE_DROWNED = 531; + + public const BUNDLE_INSERT_FAIL = 533; //The following aliases are kept for backwards compatibility only public const SCULK_SENSOR_POWER_ON = self::POWER_ON_SCULK_SENSOR; From 722be3c0ffbc057955bb5f8868b054a262d95a28 Mon Sep 17 00:00:00 2001 From: Dries C Date: Sat, 14 Sep 2024 22:34:26 +0200 Subject: [PATCH 4/4] Register new packets --- src/PacketPool.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/PacketPool.php b/src/PacketPool.php index d19df2d7..ab095cc2 100644 --- a/src/PacketPool.php +++ b/src/PacketPool.php @@ -233,6 +233,8 @@ public function __construct(){ $this->registerPacket(new JigsawStructureDataPacket()); $this->registerPacket(new CurrentStructureFeaturePacket()); $this->registerPacket(new ServerboundDiagnosticsPacket()); + $this->registerPacket(new CameraAimAssistPacket()); + $this->registerPacket(new ContainerRegistryCleanupPacket()); } public function registerPacket(Packet $packet) : void{