PocketMine-MP 5.32.2 git-237b304ef9858756b018e44e8f298093f66f823b
Loading...
Searching...
No Matches
CorrectPlayerMovePredictionPacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
20
22 public const NETWORK_ID = ProtocolInfo::CORRECT_PLAYER_MOVE_PREDICTION_PACKET;
23
24 public const PREDICTION_TYPE_PLAYER = 0;
25 public const PREDICTION_TYPE_VEHICLE = 1;
26
27 private Vector3 $position;
28 private Vector3 $delta;
29 private bool $onGround;
30 private int $tick;
31 private int $predictionType;
32 private Vector2 $vehicleRotation;
33 private float $vehicleAngularVelocity;
34
38 public static function create(
39 Vector3 $position,
40 Vector3 $delta,
41 bool $onGround,
42 int $tick,
43 int $predictionType,
44 Vector2 $vehicleRotation,
45 float $vehicleAngularVelocity,
46 ) : self{
47 $result = new self;
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;
55 return $result;
56 }
57
58 public function getPosition() : Vector3{ return $this->position; }
59
60 public function getDelta() : Vector3{ return $this->delta; }
61
62 public function isOnGround() : bool{ return $this->onGround; }
63
64 public function getTick() : int{ return $this->tick; }
65
66 public function getPredictionType() : int{ return $this->predictionType; }
67
68 public function getVehicleRotation() : Vector2{ return $this->vehicleRotation; }
69
70 public function getVehicleAngularVelocity() : float{ return $this->vehicleAngularVelocity; }
71
72 protected function decodePayload(PacketSerializer $in) : void{
73 $this->predictionType = $in->getByte();
74 $this->position = $in->getVector3();
75 $this->delta = $in->getVector3();
76 $this->vehicleRotation = new Vector2($in->getFloat(), $in->getFloat());
77 $this->vehicleAngularVelocity = $in->getFloat();
78 $this->onGround = $in->getBool();
79 $this->tick = $in->getUnsignedVarLong();
80 }
81
82 protected function encodePayload(PacketSerializer $out) : void{
83 $out->putByte($this->predictionType);
84 $out->putVector3($this->position);
85 $out->putVector3($this->delta);
86 $out->putFloat($this->vehicleRotation->getX());
87 $out->putFloat($this->vehicleRotation->getY());
88 $out->putFloat($this->vehicleAngularVelocity);
89 $out->putBool($this->onGround);
90 $out->putUnsignedVarLong($this->tick);
91 }
92
93 public function handle(PacketHandlerInterface $handler) : bool{
94 return $handler->handleCorrectPlayerMovePrediction($this);
95 }
96}
static create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, Vector2 $vehicleRotation, float $vehicleAngularVelocity,)