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