PocketMine-MP 5.43.2 git-c9e7b3ab9bd2149f206392522e8eb7e9d8d68cfa
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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
23
25 public const NETWORK_ID = ProtocolInfo::CLIENT_MOVEMENT_PREDICTION_SYNC_PACKET;
26
27 public const FLAG_LENGTH = EntityMetadataFlags::NUMBER_OF_FLAGS;
28
29 private BitSet $flags;
30
31 private float $scale;
32 private float $width;
33 private float $height;
34
35 private float $movementSpeed;
36 private float $underwaterMovementSpeed;
37 private float $lavaMovementSpeed;
38 private float $jumpStrength;
39 private float $health;
40 private float $hunger;
41 private float $frictionModifier;
42 private float $bounciness;
43 private float $airDragModifier;
44
45 private int $actorUniqueId;
46 private bool $actorFlyingState;
47
51 private static function internalCreate(
52 BitSet $flags,
53 float $scale,
54 float $width,
55 float $height,
56 float $movementSpeed,
57 float $underwaterMovementSpeed,
58 float $lavaMovementSpeed,
59 float $jumpStrength,
60 float $health,
61 float $hunger,
62 float $frictionModifier,
63 float $bounciness,
64 float $airDragModifier,
65 int $actorUniqueId,
66 bool $actorFlyingState,
67 ) : self{
68 $result = new self;
69 $result->flags = $flags;
70 $result->scale = $scale;
71 $result->width = $width;
72 $result->height = $height;
73 $result->movementSpeed = $movementSpeed;
74 $result->underwaterMovementSpeed = $underwaterMovementSpeed;
75 $result->lavaMovementSpeed = $lavaMovementSpeed;
76 $result->jumpStrength = $jumpStrength;
77 $result->health = $health;
78 $result->hunger = $hunger;
79 $result->frictionModifier = $frictionModifier;
80 $result->bounciness = $bounciness;
81 $result->airDragModifier = $airDragModifier;
82 $result->actorUniqueId = $actorUniqueId;
83 $result->actorFlyingState = $actorFlyingState;
84 return $result;
85 }
86
87 public static function create(
88 BitSet $flags,
89 float $scale,
90 float $width,
91 float $height,
92 float $movementSpeed,
93 float $underwaterMovementSpeed,
94 float $lavaMovementSpeed,
95 float $jumpStrength,
96 float $health,
97 float $hunger,
98 float $frictionModifier,
99 float $bounciness,
100 float $airDragModifier,
101 int $actorUniqueId,
102 bool $actorFlyingState,
103 ) : self{
104 if($flags->getLength() !== self::FLAG_LENGTH){
105 throw new \InvalidArgumentException("Input flags must be " . self::FLAG_LENGTH . " bits long");
106 }
107
108 return self::internalCreate($flags, $scale, $width, $height, $movementSpeed, $underwaterMovementSpeed, $lavaMovementSpeed, $jumpStrength, $health, $hunger, $frictionModifier, $bounciness, $airDragModifier, $actorUniqueId, $actorFlyingState);
109 }
110
111 public function getFlags() : BitSet{ return $this->flags; }
112
113 public function getScale() : float{ return $this->scale; }
114
115 public function getWidth() : float{ return $this->width; }
116
117 public function getHeight() : float{ return $this->height; }
118
119 public function getMovementSpeed() : float{ return $this->movementSpeed; }
120
121 public function getUnderwaterMovementSpeed() : float{ return $this->underwaterMovementSpeed; }
122
123 public function getLavaMovementSpeed() : float{ return $this->lavaMovementSpeed; }
124
125 public function getJumpStrength() : float{ return $this->jumpStrength; }
126
127 public function getHealth() : float{ return $this->health; }
128
129 public function getHunger() : float{ return $this->hunger; }
130
131 public function getFrictionModifier() : float{ return $this->frictionModifier; }
132
133 public function getBounciness() : float{ return $this->bounciness; }
134
135 public function getAirDragModifier() : float{ return $this->airDragModifier; }
136
137 public function getActorUniqueId() : int{ return $this->actorUniqueId; }
138
139 public function getActorFlyingState() : bool{ return $this->actorFlyingState; }
140
141 protected function decodePayload(ByteBufferReader $in) : void{
142 $this->flags = BitSet::read($in, self::FLAG_LENGTH);
143 $this->scale = LE::readFloat($in);
144 $this->width = LE::readFloat($in);
145 $this->height = LE::readFloat($in);
146 $this->movementSpeed = LE::readFloat($in);
147 $this->underwaterMovementSpeed = LE::readFloat($in);
148 $this->lavaMovementSpeed = LE::readFloat($in);
149 $this->jumpStrength = LE::readFloat($in);
150 $this->health = LE::readFloat($in);
151 $this->hunger = LE::readFloat($in);
152 $this->frictionModifier = LE::readFloat($in);
153 $this->bounciness = LE::readFloat($in);
154 $this->airDragModifier = LE::readFloat($in);
155 $this->actorUniqueId = CommonTypes::getActorUniqueId($in);
156 $this->actorFlyingState = CommonTypes::getBool($in);
157 }
158
159 protected function encodePayload(ByteBufferWriter $out) : void{
160 $this->flags->write($out);
161 LE::writeFloat($out, $this->scale);
162 LE::writeFloat($out, $this->width);
163 LE::writeFloat($out, $this->height);
164 LE::writeFloat($out, $this->movementSpeed);
165 LE::writeFloat($out, $this->underwaterMovementSpeed);
166 LE::writeFloat($out, $this->lavaMovementSpeed);
167 LE::writeFloat($out, $this->jumpStrength);
168 LE::writeFloat($out, $this->health);
169 LE::writeFloat($out, $this->hunger);
170 LE::writeFloat($out, $this->frictionModifier);
171 LE::writeFloat($out, $this->bounciness);
172 LE::writeFloat($out, $this->airDragModifier);
173 CommonTypes::putActorUniqueId($out, $this->actorUniqueId);
174 CommonTypes::putBool($out, $this->actorFlyingState);
175 }
176
177 public function handle(PacketHandlerInterface $handler) : bool{
178 return $handler->handleClientMovementPredictionSync($this);
179 }
180}