13declare(strict_types=1);
15namespace pocketmine\network\mcpe\protocol;
22 public const NETWORK_ID = ProtocolInfo::CORRECT_PLAYER_MOVE_PREDICTION_PACKET;
24 public const PREDICTION_TYPE_PLAYER = 0;
25 public const PREDICTION_TYPE_VEHICLE = 1;
29 private bool $onGround;
31 private int $predictionType;
32 private ?
Vector2 $vehicleRotation;
33 private ?
float $vehicleAngularVelocity;
38 private static function internalCreate(
45 ?
float $vehicleAngularVelocity,
48 $result->position = $position;
49 $result->delta = $delta;
50 $result->onGround = $onGround;
51 $result->tick = $tick;
52 $result->predictionType = $predictionType;
53 $result->vehicleRotation = $vehicleRotation;
54 $result->vehicleAngularVelocity = $vehicleAngularVelocity;
58 public static function create(
Vector3 $position,
Vector3 $delta,
bool $onGround,
int $tick,
int $predictionType, ?
Vector2 $vehicleRotation, ?
float $vehicleAngularVelocity) :
self{
59 if($predictionType === self::PREDICTION_TYPE_VEHICLE && $vehicleRotation ===
null){
60 throw new \LogicException(
"CorrectPlayerMovePredictionPackets with type VEHICLE require a vehicleRotation to be provided");
63 return self::internalCreate($position, $delta, $onGround, $tick, $predictionType, $vehicleRotation, $vehicleAngularVelocity);
66 public function getPosition() :
Vector3{
return $this->position; }
68 public function getDelta() :
Vector3{
return $this->delta; }
70 public function isOnGround() :
bool{
return $this->onGround; }
72 public function getTick() :
int{
return $this->tick; }
74 public function getPredictionType() :
int{
return $this->predictionType; }
76 public function getVehicleRotation() : ?
Vector2{
return $this->vehicleRotation; }
78 public function getVehicleAngularVelocity() : ?
float{
return $this->vehicleAngularVelocity; }
81 $this->predictionType = $in->getByte();
84 if($this->predictionType === self::PREDICTION_TYPE_VEHICLE){
88 $this->onGround = $in->
getBool();
93 $out->putByte($this->predictionType);
96 if($this->predictionType === self::PREDICTION_TYPE_VEHICLE){
97 if($this->vehicleRotation ===
null){
98 throw new \LogicException(
"CorrectPlayerMovePredictionPackets with type VEHICLE require a vehicleRotation to be provided");
101 $out->putFloat($this->vehicleRotation->getX());
102 $out->putFloat($this->vehicleRotation->getY());
103 $out->
writeOptional($this->vehicleAngularVelocity, $out->putFloat(...));
105 $out->putBool($this->onGround);
110 return $handler->handleCorrectPlayerMovePrediction($this);
handle(PacketHandlerInterface $handler)
encodePayload(PacketSerializer $out)
decodePayload(PacketSerializer $in)
writeOptional(mixed $value, \Closure $writer)
putVector3(Vector3 $vector)
readOptional(\Closure $reader)
putUnsignedVarLong(int $v)