Skip to content

Commit

Permalink
Merge remote-tracking branch 'dries/bedrock-1.21.30'
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Sep 17, 2024
2 parents cea5a53 + 722be3c commit db73c98
Show file tree
Hide file tree
Showing 25 changed files with 393 additions and 108 deletions.
67 changes: 67 additions & 0 deletions src/CameraAimAssistPacket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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\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);
}
}
2 changes: 2 additions & 0 deletions src/CameraInstructionPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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{
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_20_30){
$this->set = $in->readOptional(fn() => CameraSetInstruction::read($in));
Expand Down
2 changes: 2 additions & 0 deletions src/ChangeDimensionPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
59 changes: 59 additions & 0 deletions src/ContainerRegistryCleanupPacket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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\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);
}
}
8 changes: 7 additions & 1 deletion src/EmotePacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ 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;

/**
* @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;
Expand All @@ -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; }
Expand All @@ -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();
Expand All @@ -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);
Expand Down
23 changes: 16 additions & 7 deletions src/InventoryContentPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand All @@ -44,8 +47,11 @@ protected function decodePayload(PacketSerializer $in) : void{
for($i = 0; $i < $count; ++$i){
$this->items[] = $in->getItemStackWrapper();
}
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_20){
$this->dynamicContainerId = $in->getUnsignedVarInt();
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_30){
$this->containerName = FullContainerName::read($in);
$this->dynamicContainerSize = $in->getUnsignedVarInt();
}elseif($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_20){
$this->containerName = new FullContainerName(0, $in->getUnsignedVarInt());
}
}

Expand All @@ -55,8 +61,11 @@ protected function encodePayload(PacketSerializer $out) : void{
foreach($this->items as $item){
$out->putItemStackWrapper($item);
}
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_20){
$out->putUnsignedVarInt($this->dynamicContainerId);
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_30){
$this->containerName->write($out);
$out->putUnsignedVarInt($this->dynamicContainerSize);
}elseif($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_20){
$out->putUnsignedVarInt($this->containerName->getDynamicId() ?? 0);
}
}

Expand Down
23 changes: 16 additions & 7 deletions src/InventorySlotPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,51 @@
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{
public const NETWORK_ID = ProtocolInfo::INVENTORY_SLOT_PACKET;

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();
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_20){
$this->dynamicContainerId = $in->getUnsignedVarInt();
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_30){
$this->containerName = FullContainerName::read($in);
$this->dynamicContainerSize = $in->getUnsignedVarInt();
}elseif($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_20){
$this->containerName = new FullContainerName(0, $in->getUnsignedVarInt());
}
$this->item = $in->getItemStackWrapper();
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt($this->windowId);
$out->putUnsignedVarInt($this->inventorySlot);
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_20){
$out->putUnsignedVarInt($this->dynamicContainerId);
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_30){
$this->containerName->write($out);
$out->putUnsignedVarInt($this->dynamicContainerSize);
}elseif($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_20){
$out->putUnsignedVarInt($this->containerName->getDynamicId() ?? 0);
}
$out->putItemStackWrapper($this->item);
}
Expand Down
8 changes: 8 additions & 0 deletions src/PacketHandlerDefaultImplTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,4 +829,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;
}
}
4 changes: 4 additions & 0 deletions src/PacketHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,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;
}
2 changes: 2 additions & 0 deletions src/PacketPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,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{
Expand Down
10 changes: 7 additions & 3 deletions src/ProtocolInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private function __construct(){
*/

/** Actual Minecraft: PE protocol version */
public const CURRENT_PROTOCOL = self::PROTOCOL_1_21_20;
public const CURRENT_PROTOCOL = self::PROTOCOL_1_21_30;
public const ACCEPTED_PROTOCOL = [
self::PROTOCOL_1_20_0,
self::PROTOCOL_1_20_10,
Expand All @@ -44,14 +44,16 @@ private function __construct(){
self::PROTOCOL_1_20_80,
self::PROTOCOL_1_21_0,
self::PROTOCOL_1_21_2,
self::PROTOCOL_1_21_20,
self::CURRENT_PROTOCOL,
];

/** 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 PROTOCOL_1_21_30 = 729;
public const PROTOCOL_1_21_20 = 712;
public const PROTOCOL_1_21_2 = 686;
public const PROTOCOL_1_21_0 = 685;
Expand Down Expand Up @@ -277,4 +279,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;
}
Loading

0 comments on commit db73c98

Please sign in to comment.