Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update field order and fix enum values in CorrectPlayerMovePredictionPacket #259

Merged
merged 14 commits into from
Aug 13, 2024
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/CorrectPlayerMovePredictionPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,34 @@

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{
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;
$result->onGround = $onGround;
$result->tick = $tick;
$result->predictionType = $predictionType;
$result->vehicleRotation = $vehicleRotation;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the check removed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the check removed here?

PHP-CS-Fixer complained about it, and whether its set is only relevant in the encoding process where it needs to be present

return $result;
}

Expand All @@ -52,20 +55,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) {
dktapps marked this conversation as resolved.
Show resolved Hide resolved
$this->vehicleRotation = new Vector2($in->getFloat(), $in->getFloat());
dktapps marked this conversation as resolved.
Show resolved Hide resolved
}
$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) {
dktapps marked this conversation as resolved.
Show resolved Hide resolved
if($this->vehicleRotation == null) { // this should never be the case
dktapps marked this conversation as resolved.
Show resolved Hide resolved
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{
Expand Down