From e2264137c5cd0522de2c6ee4921a3a803818ea32 Mon Sep 17 00:00:00 2001 From: IvanCraft623 <57236932+IvanCraft623@users.noreply.github.com> Date: Thu, 15 Aug 2024 18:07:53 -0500 Subject: [PATCH] Improvements on 1.21.2 support (#263) - Added missing `vehicleAngularVelocity` property on `CorrectPlayerMovePredictionPacket` when `predictionType` is `VEHICLE` - Renamed `ServerboundLoadingScreenPacketType` => `LoadingScreenType` - `repetitions` fields are now in a logical sequence on `CraftRecipeAutoStackRequestAction` --- src/CorrectPlayerMovePredictionPacket.php | 20 ++++++++++++++++--- src/ServerboundLoadingScreenPacket.php | 10 +++++----- ...enPacketType.php => LoadingScreenType.php} | 2 +- .../CraftRecipeAutoStackRequestAction.php | 8 ++++---- 4 files changed, 27 insertions(+), 13 deletions(-) rename src/types/hud/{ServerboundLoadingScreenPacketType.php => LoadingScreenType.php} (93%) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index e322ca25..04432fda 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -30,11 +30,20 @@ class CorrectPlayerMovePredictionPacket extends DataPacket implements Clientboun private int $tick; private int $predictionType; private ?Vector2 $vehicleRotation; + private ?float $vehicleAngularVelocity; /** * @generate-create-func */ - private static function internalCreate(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $vehicleRotation) : self{ + private static function internalCreate( + Vector3 $position, + Vector3 $delta, + bool $onGround, + int $tick, + int $predictionType, + ?Vector2 $vehicleRotation, + ?float $vehicleAngularVelocity, + ) : self{ $result = new self; $result->position = $position; $result->delta = $delta; @@ -42,15 +51,16 @@ private static function internalCreate(Vector3 $position, Vector3 $delta, bool $ $result->tick = $tick; $result->predictionType = $predictionType; $result->vehicleRotation = $vehicleRotation; + $result->vehicleAngularVelocity = $vehicleAngularVelocity; return $result; } - public static function create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $vehicleRotation) : self{ + public static function create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $vehicleRotation, ?float $vehicleAngularVelocity) : self{ if($predictionType === self::PREDICTION_TYPE_VEHICLE && $vehicleRotation === null){ throw new \LogicException("CorrectPlayerMovePredictionPackets with type VEHICLE require a vehicleRotation to be provided"); } - return self::internalCreate($position, $delta, $onGround, $tick, $predictionType, $vehicleRotation); + return self::internalCreate($position, $delta, $onGround, $tick, $predictionType, $vehicleRotation, $vehicleAngularVelocity); } public function getPosition() : Vector3{ return $this->position; } @@ -65,12 +75,15 @@ public function getPredictionType() : int{ return $this->predictionType; } public function getVehicleRotation() : ?Vector2{ return $this->vehicleRotation; } + public function getVehicleAngularVelocity() : ?float{ return $this->vehicleAngularVelocity; } + protected function decodePayload(PacketSerializer $in) : void{ $this->predictionType = $in->getByte(); $this->position = $in->getVector3(); $this->delta = $in->getVector3(); if($this->predictionType === self::PREDICTION_TYPE_VEHICLE){ $this->vehicleRotation = new Vector2($in->getFloat(), $in->getFloat()); + $this->vehicleAngularVelocity = $in->readOptional($in->getFloat(...)); } $this->onGround = $in->getBool(); $this->tick = $in->getUnsignedVarLong(); @@ -87,6 +100,7 @@ protected function encodePayload(PacketSerializer $out) : void{ $out->putFloat($this->vehicleRotation->getX()); $out->putFloat($this->vehicleRotation->getY()); + $out->writeOptional($this->vehicleAngularVelocity, $out->putFloat(...)); } $out->putBool($this->onGround); $out->putUnsignedVarLong($this->tick); diff --git a/src/ServerboundLoadingScreenPacket.php b/src/ServerboundLoadingScreenPacket.php index 41cddf86..e16e9821 100644 --- a/src/ServerboundLoadingScreenPacket.php +++ b/src/ServerboundLoadingScreenPacket.php @@ -15,30 +15,30 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; -use pocketmine\network\mcpe\protocol\types\hud\ServerboundLoadingScreenPacketType; +use pocketmine\network\mcpe\protocol\types\hud\LoadingScreenType; class ServerboundLoadingScreenPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::SERVERBOUND_LOADING_SCREEN_PACKET; - private ServerboundLoadingScreenPacketType $loadingScreenType; + private LoadingScreenType $loadingScreenType; private ?int $loadingScreenId = null; /** * @generate-create-func */ - public static function create(ServerboundLoadingScreenPacketType $loadingScreenType, ?int $loadingScreenId) : self{ + public static function create(LoadingScreenType $loadingScreenType, ?int $loadingScreenId) : self{ $result = new self; $result->loadingScreenType = $loadingScreenType; $result->loadingScreenId = $loadingScreenId; return $result; } - public function getLoadingScreenType() : ServerboundLoadingScreenPacketType{ return $this->loadingScreenType; } + public function getLoadingScreenType() : LoadingScreenType{ return $this->loadingScreenType; } public function getLoadingScreenId() : ?int{ return $this->loadingScreenId; } protected function decodePayload(PacketSerializer $in) : void{ - $this->loadingScreenType = ServerboundLoadingScreenPacketType::fromPacket($in->getVarInt()); + $this->loadingScreenType = LoadingScreenType::fromPacket($in->getVarInt()); $this->loadingScreenId = $in->readOptional(fn() => $in->getLInt()); } diff --git a/src/types/hud/ServerboundLoadingScreenPacketType.php b/src/types/hud/LoadingScreenType.php similarity index 93% rename from src/types/hud/ServerboundLoadingScreenPacketType.php rename to src/types/hud/LoadingScreenType.php index 6143cde5..6e8f9614 100644 --- a/src/types/hud/ServerboundLoadingScreenPacketType.php +++ b/src/types/hud/LoadingScreenType.php @@ -16,7 +16,7 @@ use pocketmine\network\mcpe\protocol\types\PacketIntEnumTrait; -enum ServerboundLoadingScreenPacketType : int{ +enum LoadingScreenType : int{ use PacketIntEnumTrait; case UNKNOWN = 0; diff --git a/src/types/inventory/stackrequest/CraftRecipeAutoStackRequestAction.php b/src/types/inventory/stackrequest/CraftRecipeAutoStackRequestAction.php index 189e8569..228425dd 100644 --- a/src/types/inventory/stackrequest/CraftRecipeAutoStackRequestAction.php +++ b/src/types/inventory/stackrequest/CraftRecipeAutoStackRequestAction.php @@ -34,8 +34,8 @@ final class CraftRecipeAutoStackRequestAction extends ItemStackRequestAction{ */ final public function __construct( private int $recipeId, - private int $repetitions2, private int $repetitions, + private int $repetitions2, private array $ingredients ){} @@ -53,19 +53,19 @@ public function getIngredients() : array{ return $this->ingredients; } public static function read(PacketSerializer $in) : self{ $recipeId = $in->readRecipeNetId(); - $repetitions2 = $in->getByte(); $repetitions = $in->getByte(); + $repetitions2 = $in->getByte(); //repetitions property is sent twice, mojang... $ingredients = []; for($i = 0, $count = $in->getByte(); $i < $count; ++$i){ $ingredients[] = $in->getRecipeIngredient(); } - return new self($recipeId, $repetitions2, $repetitions, $ingredients); + return new self($recipeId, $repetitions, $repetitions2, $ingredients); } public function write(PacketSerializer $out) : void{ $out->writeRecipeNetId($this->recipeId); - $out->putByte($this->repetitions2); $out->putByte($this->repetitions); + $out->putByte($this->repetitions2); $out->putByte(count($this->ingredients)); foreach($this->ingredients as $ingredient){ $out->putRecipeIngredient($ingredient);