From a871e126375c6fc269f77297fdf73d0db6549714 Mon Sep 17 00:00:00 2001 From: Tobias Grether Date: Tue, 13 Aug 2024 20:25:54 +0200 Subject: [PATCH] Update field order and fix enum values in CorrectPlayerMovePredictionPacket (#259) --- src/CorrectPlayerMovePredictionPacket.php | 34 +++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index 4f2de83e..e322ca25 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -14,34 +14,45 @@ namespace pocketmine\network\mcpe\protocol; +use pocketmine\math\Vector2; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; class CorrectPlayerMovePredictionPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::CORRECT_PLAYER_MOVE_PREDICTION_PACKET; - public const PREDICTION_TYPE_VEHICLE = 0; - public const PREDICTION_TYPE_PLAYER = 1; + public const PREDICTION_TYPE_PLAYER = 0; + public const PREDICTION_TYPE_VEHICLE = 1; private Vector3 $position; private Vector3 $delta; private bool $onGround; private int $tick; private int $predictionType; + private ?Vector2 $vehicleRotation; /** * @generate-create-func */ - public static function create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType) : self{ + private static function internalCreate(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $vehicleRotation) : self{ $result = new self; $result->position = $position; $result->delta = $delta; $result->onGround = $onGround; $result->tick = $tick; $result->predictionType = $predictionType; + $result->vehicleRotation = $vehicleRotation; return $result; } + public static function create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $vehicleRotation) : 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); + } + public function getPosition() : Vector3{ return $this->position; } public function getDelta() : Vector3{ return $this->delta; } @@ -52,20 +63,33 @@ public function getTick() : int{ return $this->tick; } public function getPredictionType() : int{ return $this->predictionType; } + public function getVehicleRotation() : ?Vector2{ return $this->vehicleRotation; } + 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->onGround = $in->getBool(); $this->tick = $in->getUnsignedVarLong(); - $this->predictionType = $in->getByte(); } protected function encodePayload(PacketSerializer $out) : void{ + $out->putByte($this->predictionType); $out->putVector3($this->position); $out->putVector3($this->delta); + if($this->predictionType === self::PREDICTION_TYPE_VEHICLE){ + if($this->vehicleRotation === null){ // this should never be the case + throw new \LogicException("CorrectPlayerMovePredictionPackets with type VEHICLE require a vehicleRotation to be provided"); + } + + $out->putFloat($this->vehicleRotation->getX()); + $out->putFloat($this->vehicleRotation->getY()); + } $out->putBool($this->onGround); $out->putUnsignedVarLong($this->tick); - $out->putByte($this->predictionType); } public function handle(PacketHandlerInterface $handler) : bool{