PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\LE;
21use pmmp\encoding\VarInt;
25
27 public const NETWORK_ID = ProtocolInfo::CORRECT_PLAYER_MOVE_PREDICTION_PACKET;
28
29 public const PREDICTION_TYPE_PLAYER = 0;
30 public const PREDICTION_TYPE_VEHICLE = 1;
31
32 private Vector3 $position;
33 private Vector3 $delta;
34 private bool $onGround;
35 private int $tick;
36 private int $predictionType;
37 private Vector2 $vehicleRotation;
38 private ?float $vehicleAngularVelocity;
39
43 public static function create(
44 Vector3 $position,
45 Vector3 $delta,
46 bool $onGround,
47 int $tick,
48 int $predictionType,
49 Vector2 $vehicleRotation,
50 ?float $vehicleAngularVelocity,
51 ) : self{
52 $result = new self;
53 $result->position = $position;
54 $result->delta = $delta;
55 $result->onGround = $onGround;
56 $result->tick = $tick;
57 $result->predictionType = $predictionType;
58 $result->vehicleRotation = $vehicleRotation;
59 $result->vehicleAngularVelocity = $vehicleAngularVelocity;
60 return $result;
61 }
62
63 public function getPosition() : Vector3{ return $this->position; }
64
65 public function getDelta() : Vector3{ return $this->delta; }
66
67 public function isOnGround() : bool{ return $this->onGround; }
68
69 public function getTick() : int{ return $this->tick; }
70
71 public function getPredictionType() : int{ return $this->predictionType; }
72
73 public function getVehicleRotation() : Vector2{ return $this->vehicleRotation; }
74
75 public function getVehicleAngularVelocity() : ?float{ return $this->vehicleAngularVelocity; }
76
77 protected function decodePayload(ByteBufferReader $in) : void{
78 $this->predictionType = Byte::readUnsigned($in);
79 $this->position = CommonTypes::getVector3($in);
80 $this->delta = CommonTypes::getVector3($in);
81 $this->vehicleRotation = new Vector2(LE::readFloat($in), LE::readFloat($in));
82 $this->vehicleAngularVelocity = CommonTypes::readOptional($in, LE::readFloat(...));
83 $this->onGround = CommonTypes::getBool($in);
84 $this->tick = VarInt::readUnsignedLong($in);
85 }
86
87 protected function encodePayload(ByteBufferWriter $out) : void{
88 Byte::writeUnsigned($out, $this->predictionType);
89 CommonTypes::putVector3($out, $this->position);
90 CommonTypes::putVector3($out, $this->delta);
91 LE::writeFloat($out, $this->vehicleRotation->getX());
92 LE::writeFloat($out, $this->vehicleRotation->getY());
93 CommonTypes::writeOptional($out, $this->vehicleAngularVelocity, LE::writeFloat(...));
94 CommonTypes::putBool($out, $this->onGround);
95 VarInt::writeUnsignedLong($out, $this->tick);
96 }
97
98 public function handle(PacketHandlerInterface $handler) : bool{
99 return $handler->handleCorrectPlayerMovePrediction($this);
100 }
101}
static create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, Vector2 $vehicleRotation, ?float $vehicleAngularVelocity,)