PocketMine-MP 5.21.2 git-09bf203267aca9b83a09640e17bfac0fc7b58ff8
Loading...
Searching...
No Matches
MoveActorDeltaPacket.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::MOVE_ACTOR_DELTA_PACKET;
22
23 public const FLAG_HAS_X = 0x01;
24 public const FLAG_HAS_Y = 0x02;
25 public const FLAG_HAS_Z = 0x04;
26 public const FLAG_HAS_PITCH = 0x08;
27 public const FLAG_HAS_YAW = 0x10;
28 public const FLAG_HAS_HEAD_YAW = 0x20;
29 public const FLAG_GROUND = 0x40;
30 public const FLAG_TELEPORT = 0x80;
31 public const FLAG_FORCE_MOVE_LOCAL_ENTITY = 0x100;
32
33 public int $actorRuntimeId;
34 public int $flags;
35 public float $xPos = 0;
36 public float $yPos = 0;
37 public float $zPos = 0;
38 public float $pitch = 0.0;
39 public float $yaw = 0.0;
40 public float $headYaw = 0.0;
41
45 private function maybeReadCoord(int $flag, PacketSerializer $in) : float{
46 if(($this->flags & $flag) !== 0){
47 return $in->getLFloat();
48 }
49 return 0;
50 }
51
55 private function maybeReadRotation(int $flag, PacketSerializer $in) : float{
56 if(($this->flags & $flag) !== 0){
57 return $in->getRotationByte();
58 }
59 return 0.0;
60 }
61
62 protected function decodePayload(PacketSerializer $in) : void{
63 $this->actorRuntimeId = $in->getActorRuntimeId();
64 $this->flags = $in->getLShort();
65 $this->xPos = $this->maybeReadCoord(self::FLAG_HAS_X, $in);
66 $this->yPos = $this->maybeReadCoord(self::FLAG_HAS_Y, $in);
67 $this->zPos = $this->maybeReadCoord(self::FLAG_HAS_Z, $in);
68 $this->pitch = $this->maybeReadRotation(self::FLAG_HAS_PITCH, $in);
69 $this->yaw = $this->maybeReadRotation(self::FLAG_HAS_YAW, $in);
70 $this->headYaw = $this->maybeReadRotation(self::FLAG_HAS_HEAD_YAW, $in);
71 }
72
73 private function maybeWriteCoord(int $flag, float $val, PacketSerializer $out) : void{
74 if(($this->flags & $flag) !== 0){
75 $out->putLFloat($val);
76 }
77 }
78
79 private function maybeWriteRotation(int $flag, float $val, PacketSerializer $out) : void{
80 if(($this->flags & $flag) !== 0){
81 $out->putRotationByte($val);
82 }
83 }
84
85 protected function encodePayload(PacketSerializer $out) : void{
86 $out->putActorRuntimeId($this->actorRuntimeId);
87 $out->putLShort($this->flags);
88 $this->maybeWriteCoord(self::FLAG_HAS_X, $this->xPos, $out);
89 $this->maybeWriteCoord(self::FLAG_HAS_Y, $this->yPos, $out);
90 $this->maybeWriteCoord(self::FLAG_HAS_Z, $this->zPos, $out);
91 $this->maybeWriteRotation(self::FLAG_HAS_PITCH, $this->pitch, $out);
92 $this->maybeWriteRotation(self::FLAG_HAS_YAW, $this->yaw, $out);
93 $this->maybeWriteRotation(self::FLAG_HAS_HEAD_YAW, $this->headYaw, $out);
94 }
95
96 public function handle(PacketHandlerInterface $handler) : bool{
97 return $handler->handleMoveActorDelta($this);
98 }
99}