PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
42 private int $actorUniqueId;
43 private bool $actorFlyingState;
44
48 private static function internalCreate(
49 BitSet $flags,
50 float $scale,
51 float $width,
52 float $height,
53 float $movementSpeed,
54 float $underwaterMovementSpeed,
55 float $lavaMovementSpeed,
56 float $jumpStrength,
57 float $health,
58 float $hunger,
59 int $actorUniqueId,
60 bool $actorFlyingState,
61 ) : self{
62 $result = new self;
63 $result->flags = $flags;
64 $result->scale = $scale;
65 $result->width = $width;
66 $result->height = $height;
67 $result->movementSpeed = $movementSpeed;
68 $result->underwaterMovementSpeed = $underwaterMovementSpeed;
69 $result->lavaMovementSpeed = $lavaMovementSpeed;
70 $result->jumpStrength = $jumpStrength;
71 $result->health = $health;
72 $result->hunger = $hunger;
73 $result->actorUniqueId = $actorUniqueId;
74 $result->actorFlyingState = $actorFlyingState;
75 return $result;
76 }
77
78 public static function create(
79 BitSet $flags,
80 float $scale,
81 float $width,
82 float $height,
83 float $movementSpeed,
84 float $underwaterMovementSpeed,
85 float $lavaMovementSpeed,
86 float $jumpStrength,
87 float $health,
88 float $hunger,
89 int $actorUniqueId,
90 bool $actorFlyingState,
91 ) : self{
92 if($flags->getLength() !== self::FLAG_LENGTH){
93 throw new \InvalidArgumentException("Input flags must be " . self::FLAG_LENGTH . " bits long");
94 }
95
96 return self::internalCreate($flags, $scale, $width, $height, $movementSpeed, $underwaterMovementSpeed, $lavaMovementSpeed, $jumpStrength, $health, $hunger, $actorUniqueId, $actorFlyingState);
97 }
98
99 public function getFlags() : BitSet{ return $this->flags; }
100
101 public function getScale() : float{ return $this->scale; }
102
103 public function getWidth() : float{ return $this->width; }
104
105 public function getHeight() : float{ return $this->height; }
106
107 public function getMovementSpeed() : float{ return $this->movementSpeed; }
108
109 public function getUnderwaterMovementSpeed() : float{ return $this->underwaterMovementSpeed; }
110
111 public function getLavaMovementSpeed() : float{ return $this->lavaMovementSpeed; }
112
113 public function getJumpStrength() : float{ return $this->jumpStrength; }
114
115 public function getHealth() : float{ return $this->health; }
116
117 public function getHunger() : float{ return $this->hunger; }
118
119 public function getActorUniqueId() : int{ return $this->actorUniqueId; }
120
121 public function getActorFlyingState() : bool{ return $this->actorFlyingState; }
122
123 protected function decodePayload(ByteBufferReader $in) : void{
124 $this->flags = BitSet::read($in, self::FLAG_LENGTH);
125 $this->scale = LE::readFloat($in);
126 $this->width = LE::readFloat($in);
127 $this->height = LE::readFloat($in);
128 $this->movementSpeed = LE::readFloat($in);
129 $this->underwaterMovementSpeed = LE::readFloat($in);
130 $this->lavaMovementSpeed = LE::readFloat($in);
131 $this->jumpStrength = LE::readFloat($in);
132 $this->health = LE::readFloat($in);
133 $this->hunger = LE::readFloat($in);
134 $this->actorUniqueId = CommonTypes::getActorUniqueId($in);
135 $this->actorFlyingState = CommonTypes::getBool($in);
136 }
137
138 protected function encodePayload(ByteBufferWriter $out) : void{
139 $this->flags->write($out);
140 LE::writeFloat($out, $this->scale);
141 LE::writeFloat($out, $this->width);
142 LE::writeFloat($out, $this->height);
143 LE::writeFloat($out, $this->movementSpeed);
144 LE::writeFloat($out, $this->underwaterMovementSpeed);
145 LE::writeFloat($out, $this->lavaMovementSpeed);
146 LE::writeFloat($out, $this->jumpStrength);
147 LE::writeFloat($out, $this->health);
148 LE::writeFloat($out, $this->hunger);
149 CommonTypes::putActorUniqueId($out, $this->actorUniqueId);
150 CommonTypes::putBool($out, $this->actorFlyingState);
151 }
152
153 public function handle(PacketHandlerInterface $handler) : bool{
154 return $handler->handleClientMovementPredictionSync($this);
155 }
156}