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