PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
CameraShakePacket.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\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\LE;
21
23 public const NETWORK_ID = ProtocolInfo::CAMERA_SHAKE_PACKET;
24
25 public const TYPE_POSITIONAL = 0;
26 public const TYPE_ROTATIONAL = 1;
27
28 public const ACTION_ADD = 0;
29 public const ACTION_STOP = 1;
30
31 private float $intensity;
32 private float $duration;
33 private int $shakeType;
34 private int $shakeAction;
35
39 public static function create(float $intensity, float $duration, int $shakeType, int $shakeAction) : self{
40 $result = new self;
41 $result->intensity = $intensity;
42 $result->duration = $duration;
43 $result->shakeType = $shakeType;
44 $result->shakeAction = $shakeAction;
45 return $result;
46 }
47
48 public function getIntensity() : float{ return $this->intensity; }
49
50 public function getDuration() : float{ return $this->duration; }
51
52 public function getShakeType() : int{ return $this->shakeType; }
53
54 public function getShakeAction() : int{ return $this->shakeAction; }
55
56 protected function decodePayload(ByteBufferReader $in) : void{
57 $this->intensity = LE::readFloat($in);
58 $this->duration = LE::readFloat($in);
59 $this->shakeType = Byte::readUnsigned($in);
60 $this->shakeAction = Byte::readUnsigned($in);
61 }
62
63 protected function encodePayload(ByteBufferWriter $out) : void{
64 LE::writeFloat($out, $this->intensity);
65 LE::writeFloat($out, $this->duration);
66 Byte::writeUnsigned($out, $this->shakeType);
67 Byte::writeUnsigned($out, $this->shakeAction);
68 }
69
70 public function handle(PacketHandlerInterface $handler) : bool{
71 return $handler->handleCameraShake($this);
72 }
73}
static create(float $intensity, float $duration, int $shakeType, int $shakeAction)