PocketMine-MP 5.27.1 git-9af3cde03fabbe4129c79e46dc87ffa0fff446e6
Loading...
Searching...
No Matches
ClientMovementPredictionSyncPacket.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
19
21 public const NETWORK_ID = ProtocolInfo::CLIENT_MOVEMENT_PREDICTION_SYNC_PACKET;
22
23 public const FLAG_LENGTH = 123;
24
25 private BitSet $flags;
26
27 private float $scale;
28 private float $width;
29 private float $height;
30
31 private float $movementSpeed;
32 private float $underwaterMovementSpeed;
33 private float $lavaMovementSpeed;
34 private float $jumpStrength;
35 private float $health;
36 private float $hunger;
37
38 private int $actorUniqueId;
39 private bool $actorFlyingState;
40
44 private static function internalCreate(
45 BitSet $flags,
46 float $scale,
47 float $width,
48 float $height,
49 float $movementSpeed,
50 float $underwaterMovementSpeed,
51 float $lavaMovementSpeed,
52 float $jumpStrength,
53 float $health,
54 float $hunger,
55 int $actorUniqueId,
56 bool $actorFlyingState,
57 ) : self{
58 $result = new self;
59 $result->flags = $flags;
60 $result->scale = $scale;
61 $result->width = $width;
62 $result->height = $height;
63 $result->movementSpeed = $movementSpeed;
64 $result->underwaterMovementSpeed = $underwaterMovementSpeed;
65 $result->lavaMovementSpeed = $lavaMovementSpeed;
66 $result->jumpStrength = $jumpStrength;
67 $result->health = $health;
68 $result->hunger = $hunger;
69 $result->actorUniqueId = $actorUniqueId;
70 $result->actorFlyingState = $actorFlyingState;
71 return $result;
72 }
73
74 public static function create(
75 BitSet $flags,
76 float $scale,
77 float $width,
78 float $height,
79 float $movementSpeed,
80 float $underwaterMovementSpeed,
81 float $lavaMovementSpeed,
82 float $jumpStrength,
83 float $health,
84 float $hunger,
85 int $actorUniqueId,
86 bool $actorFlyingState,
87 ) : self{
88 if($flags->getLength() !== self::FLAG_LENGTH){
89 throw new \InvalidArgumentException("Input flags must be " . self::FLAG_LENGTH . " bits long");
90 }
91
92 return self::internalCreate($flags, $scale, $width, $height, $movementSpeed, $underwaterMovementSpeed, $lavaMovementSpeed, $jumpStrength, $health, $hunger, $actorUniqueId, $actorFlyingState);
93 }
94
95 public function getFlags() : BitSet{ return $this->flags; }
96
97 public function getScale() : float{ return $this->scale; }
98
99 public function getWidth() : float{ return $this->width; }
100
101 public function getHeight() : float{ return $this->height; }
102
103 public function getMovementSpeed() : float{ return $this->movementSpeed; }
104
105 public function getUnderwaterMovementSpeed() : float{ return $this->underwaterMovementSpeed; }
106
107 public function getLavaMovementSpeed() : float{ return $this->lavaMovementSpeed; }
108
109 public function getJumpStrength() : float{ return $this->jumpStrength; }
110
111 public function getHealth() : float{ return $this->health; }
112
113 public function getHunger() : float{ return $this->hunger; }
114
115 public function getActorUniqueId() : int{ return $this->actorUniqueId; }
116
117 public function getActorFlyingState() : bool{ return $this->actorFlyingState; }
118
119 protected function decodePayload(PacketSerializer $in) : void{
120 $this->flags = BitSet::read($in, self::FLAG_LENGTH);
121 $this->scale = $in->getLFloat();
122 $this->width = $in->getLFloat();
123 $this->height = $in->getLFloat();
124 $this->movementSpeed = $in->getLFloat();
125 $this->underwaterMovementSpeed = $in->getLFloat();
126 $this->lavaMovementSpeed = $in->getLFloat();
127 $this->jumpStrength = $in->getLFloat();
128 $this->health = $in->getLFloat();
129 $this->hunger = $in->getLFloat();
130 $this->actorUniqueId = $in->getActorUniqueId();
131 $this->actorFlyingState = $in->getBool();
132 }
133
134 protected function encodePayload(PacketSerializer $out) : void{
135 $this->flags->write($out);
136 $out->putLFloat($this->scale);
137 $out->putLFloat($this->width);
138 $out->putLFloat($this->height);
139 $out->putLFloat($this->movementSpeed);
140 $out->putLFloat($this->underwaterMovementSpeed);
141 $out->putLFloat($this->lavaMovementSpeed);
142 $out->putLFloat($this->jumpStrength);
143 $out->putLFloat($this->health);
144 $out->putLFloat($this->hunger);
145 $out->putActorUniqueId($this->actorUniqueId);
146 $out->putBool($this->actorFlyingState);
147 }
148
149 public function handle(PacketHandlerInterface $handler) : bool{
150 return $handler->handleClientMovementPredictionSync($this);
151 }
152}