From 048ed0cd63d74a82def3150fc2acbdeb91b131ae Mon Sep 17 00:00:00 2001 From: Tobias Grether Date: Tue, 13 Aug 2024 15:44:16 +0200 Subject: [PATCH 01/13] fix: implement PredictionType enum and vehicle rotation property correctly --- src/CorrectPlayerMovePredictionPacket.php | 26 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index 4f2de83e..d64d924d 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -14,31 +14,38 @@ 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 $rotation; /** * @generate-create-func */ - public static function create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType) : self{ + public static function create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $rotation) : self{ $result = new self; $result->position = $position; $result->delta = $delta; $result->onGround = $onGround; $result->tick = $tick; $result->predictionType = $predictionType; + + if($predictionType === self::PREDICTION_TYPE_VEHICLE && $rotation == null) { + throw new \InvalidArgumentException("CorrectPlayerMovePredictionPackets with type VEHICLE require a rotation to be provided"); + } + return $result; } @@ -52,20 +59,29 @@ public function getTick() : int{ return $this->tick; } public function getPredictionType() : int{ return $this->predictionType; } + public function getRotation() : ?Vector2{ return $this->rotation; } + 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->rotation = 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) { + $out->putFloat($this->rotation->getX()); + $out->putFloat($this->rotation->getY()); + } $out->putBool($this->onGround); $out->putUnsignedVarLong($this->tick); - $out->putByte($this->predictionType); } public function handle(PacketHandlerInterface $handler) : bool{ From d98bf4d14998ce783b1dea80314d36984757c81b Mon Sep 17 00:00:00 2001 From: Tobias Grether Date: Tue, 13 Aug 2024 15:49:00 +0200 Subject: [PATCH 02/13] chore: rename from rotation to vehicleRotation --- src/CorrectPlayerMovePredictionPacket.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index d64d924d..0a690846 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -29,12 +29,12 @@ class CorrectPlayerMovePredictionPacket extends DataPacket implements Clientboun private bool $onGround; private int $tick; private int $predictionType; - private ?Vector2 $rotation; + private ?Vector2 $vehicleRotation; /** * @generate-create-func */ - public static function create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $rotation) : self{ + public static function create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $vehicleRotation) : self{ $result = new self; $result->position = $position; $result->delta = $delta; @@ -42,8 +42,8 @@ public static function create(Vector3 $position, Vector3 $delta, bool $onGround, $result->tick = $tick; $result->predictionType = $predictionType; - if($predictionType === self::PREDICTION_TYPE_VEHICLE && $rotation == null) { - throw new \InvalidArgumentException("CorrectPlayerMovePredictionPackets with type VEHICLE require a rotation to be provided"); + if($predictionType === self::PREDICTION_TYPE_VEHICLE && $vehicleRotation == null) { + throw new \InvalidArgumentException("CorrectPlayerMovePredictionPackets with type VEHICLE require a vehicleRotation to be provided"); } return $result; @@ -59,14 +59,14 @@ public function getTick() : int{ return $this->tick; } public function getPredictionType() : int{ return $this->predictionType; } - public function getRotation() : ?Vector2{ return $this->rotation; } + 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->rotation = new Vector2($in->getFloat(), $in->getFloat()); + $this->vehicleRotation = new Vector2($in->getFloat(), $in->getFloat()); } $this->onGround = $in->getBool(); $this->tick = $in->getUnsignedVarLong(); @@ -77,8 +77,8 @@ protected function encodePayload(PacketSerializer $out) : void{ $out->putVector3($this->position); $out->putVector3($this->delta); if($this->predictionType === self::PREDICTION_TYPE_VEHICLE) { - $out->putFloat($this->rotation->getX()); - $out->putFloat($this->rotation->getY()); + $out->putFloat($this->vehicleRotation->getX()); + $out->putFloat($this->vehicleRotation->getY()); } $out->putBool($this->onGround); $out->putUnsignedVarLong($this->tick); From 27a0a6c5234b21d9761f6b92a30098d7d94e4757 Mon Sep 17 00:00:00 2001 From: Tobias Grether Date: Tue, 13 Aug 2024 15:53:26 +0200 Subject: [PATCH 03/13] fix: Add null check for vehicle rotation --- src/CorrectPlayerMovePredictionPacket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index 0a690846..0fd2f787 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -76,7 +76,7 @@ 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->predictionType === self::PREDICTION_TYPE_VEHICLE && $this->vehicleRotation != null) { $out->putFloat($this->vehicleRotation->getX()); $out->putFloat($this->vehicleRotation->getY()); } From ff3bdfb607691b9aac32888434edffc0e4e92297 Mon Sep 17 00:00:00 2001 From: Tobias Grether Date: Tue, 13 Aug 2024 15:56:10 +0200 Subject: [PATCH 04/13] chore: fix codestyle --- src/CorrectPlayerMovePredictionPacket.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index 0fd2f787..aa6c42e8 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -59,7 +59,7 @@ public function getTick() : int{ return $this->tick; } public function getPredictionType() : int{ return $this->predictionType; } - public function getVehicleRotation() : ?Vector2{ return $this->vehicleRotation; } + public function getVehicleRotation() : ?Vector2{ return $this->vehicleRotation; } protected function decodePayload(PacketSerializer $in) : void{ $this->predictionType = $in->getByte(); @@ -76,7 +76,11 @@ 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 && $this->vehicleRotation != null) { + if($this->predictionType === self::PREDICTION_TYPE_VEHICLE) { + if($this->vehicleRotation == null) { // this should never be the case + throw new \InvalidArgumentException("CorrectPlayerMovePredictionPackets with type VEHICLE require a vehicleRotation to be provided"); + } + $out->putFloat($this->vehicleRotation->getX()); $out->putFloat($this->vehicleRotation->getY()); } From 82e97ffe768e06a24a8ee80fb40f09f0fc77a85e Mon Sep 17 00:00:00 2001 From: Tobias Grether Date: Tue, 13 Aug 2024 16:00:09 +0200 Subject: [PATCH 05/13] fix: remove unnecessary second null check --- src/CorrectPlayerMovePredictionPacket.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index aa6c42e8..84dfad2a 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -41,10 +41,7 @@ public static function create(Vector3 $position, Vector3 $delta, bool $onGround, $result->onGround = $onGround; $result->tick = $tick; $result->predictionType = $predictionType; - - if($predictionType === self::PREDICTION_TYPE_VEHICLE && $vehicleRotation == null) { - throw new \InvalidArgumentException("CorrectPlayerMovePredictionPackets with type VEHICLE require a vehicleRotation to be provided"); - } + $result->vehicleRotation = $vehicleRotation; return $result; } From 45f036c9f09520102fffd24aaef9fc1cdd21e37f Mon Sep 17 00:00:00 2001 From: Tobias Grether Date: Tue, 13 Aug 2024 16:02:37 +0200 Subject: [PATCH 06/13] chore: missing vehicleRotation is a LogicException --- src/CorrectPlayerMovePredictionPacket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index 84dfad2a..0449169e 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -75,7 +75,7 @@ protected function encodePayload(PacketSerializer $out) : void{ $out->putVector3($this->delta); if($this->predictionType === self::PREDICTION_TYPE_VEHICLE) { if($this->vehicleRotation == null) { // this should never be the case - throw new \InvalidArgumentException("CorrectPlayerMovePredictionPackets with type VEHICLE require a vehicleRotation to be provided"); + throw new \LogicException("CorrectPlayerMovePredictionPackets with type VEHICLE require a vehicleRotation to be provided"); } $out->putFloat($this->vehicleRotation->getX()); From a76d552c95517f1e4e14fcf10954977256896012 Mon Sep 17 00:00:00 2001 From: Tobias Grether Date: Tue, 13 Aug 2024 16:04:15 +0200 Subject: [PATCH 07/13] fix: remove empty line --- src/CorrectPlayerMovePredictionPacket.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index 0449169e..9968c2bf 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -42,7 +42,6 @@ public static function create(Vector3 $position, Vector3 $delta, bool $onGround, $result->tick = $tick; $result->predictionType = $predictionType; $result->vehicleRotation = $vehicleRotation; - return $result; } From aa1133fed9d18ece0c9475189ffcce5dab2bf610 Mon Sep 17 00:00:00 2001 From: Tobias Grether Date: Tue, 13 Aug 2024 16:50:52 +0200 Subject: [PATCH 08/13] chore: re-add vehicle rotation validation in create function --- src/CorrectPlayerMovePredictionPacket.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index 9968c2bf..6a126875 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -31,9 +31,6 @@ class CorrectPlayerMovePredictionPacket extends DataPacket implements Clientboun private int $predictionType; private ?Vector2 $vehicleRotation; - /** - * @generate-create-func - */ public static function create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $vehicleRotation) : self{ $result = new self; $result->position = $position; @@ -41,6 +38,11 @@ public static function create(Vector3 $position, Vector3 $delta, bool $onGround, $result->onGround = $onGround; $result->tick = $tick; $result->predictionType = $predictionType; + + if($predictionType === self::PREDICTION_TYPE_VEHICLE && $vehicleRotation == null) { + throw new \LogicException("CorrectPlayerMovePredictionPackets with type VEHICLE require a vehicleRotation to be provided"); + } + $result->vehicleRotation = $vehicleRotation; return $result; } From 1c9dbcde192418e49c09708683acfeb4a0026424 Mon Sep 17 00:00:00 2001 From: "Dylan T." Date: Tue, 13 Aug 2024 19:19:19 +0100 Subject: [PATCH 09/13] Update src/CorrectPlayerMovePredictionPacket.php --- src/CorrectPlayerMovePredictionPacket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index 6a126875..63a449b3 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -39,7 +39,7 @@ public static function create(Vector3 $position, Vector3 $delta, bool $onGround, $result->tick = $tick; $result->predictionType = $predictionType; - if($predictionType === self::PREDICTION_TYPE_VEHICLE && $vehicleRotation == null) { + if($predictionType === self::PREDICTION_TYPE_VEHICLE && $vehicleRotation === null){ throw new \LogicException("CorrectPlayerMovePredictionPackets with type VEHICLE require a vehicleRotation to be provided"); } From c5cccb16b88f9483025f938f4a700be45016df1f Mon Sep 17 00:00:00 2001 From: "Dylan T." Date: Tue, 13 Aug 2024 19:19:28 +0100 Subject: [PATCH 10/13] Update src/CorrectPlayerMovePredictionPacket.php --- src/CorrectPlayerMovePredictionPacket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index 63a449b3..b9e7e964 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -63,7 +63,7 @@ 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) { + if($this->predictionType === self::PREDICTION_TYPE_VEHICLE){ $this->vehicleRotation = new Vector2($in->getFloat(), $in->getFloat()); } $this->onGround = $in->getBool(); From d4d07b95b7ef22037f7647c7d9edb915af60d35b Mon Sep 17 00:00:00 2001 From: "Dylan T." Date: Tue, 13 Aug 2024 19:19:35 +0100 Subject: [PATCH 11/13] Update src/CorrectPlayerMovePredictionPacket.php --- src/CorrectPlayerMovePredictionPacket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index b9e7e964..919a2081 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -74,7 +74,7 @@ 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->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"); } From dc14d94afba615614f103814d66462d1c54bac49 Mon Sep 17 00:00:00 2001 From: "Dylan T." Date: Tue, 13 Aug 2024 19:19:42 +0100 Subject: [PATCH 12/13] Update src/CorrectPlayerMovePredictionPacket.php --- src/CorrectPlayerMovePredictionPacket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index 919a2081..1c21f179 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -75,7 +75,7 @@ protected function encodePayload(PacketSerializer $out) : void{ $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 + if($this->vehicleRotation === null){ // this should never be the case throw new \LogicException("CorrectPlayerMovePredictionPackets with type VEHICLE require a vehicleRotation to be provided"); } From 24d62ef95044891e787b37f1e008a9d7ffa5650a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 13 Aug 2024 19:23:33 +0100 Subject: [PATCH 13/13] Sync with master --- src/CorrectPlayerMovePredictionPacket.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/CorrectPlayerMovePredictionPacket.php b/src/CorrectPlayerMovePredictionPacket.php index 1c21f179..e322ca25 100644 --- a/src/CorrectPlayerMovePredictionPacket.php +++ b/src/CorrectPlayerMovePredictionPacket.php @@ -31,20 +31,26 @@ class CorrectPlayerMovePredictionPacket extends DataPacket implements Clientboun private int $predictionType; private ?Vector2 $vehicleRotation; - public static function create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $vehicleRotation) : self{ + /** + * @generate-create-func + */ + 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"); } - $result->vehicleRotation = $vehicleRotation; - return $result; + return self::internalCreate($position, $delta, $onGround, $tick, $predictionType, $vehicleRotation); } public function getPosition() : Vector3{ return $this->position; }