PocketMine-MP 5.17.1 git-df4ada81e5d74a14046f27cf44a37dcee69d657e
CameraPreset.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\types\camera;
16
18
19final class CameraPreset{
20 public const AUDIO_LISTENER_TYPE_CAMERA = 0;
21 public const AUDIO_LISTENER_TYPE_PLAYER = 1;
22
23 public function __construct(
24 private string $name,
25 private string $parent,
26 private ?float $xPosition,
27 private ?float $yPosition,
28 private ?float $zPosition,
29 private ?float $pitch,
30 private ?float $yaw,
31 private ?int $audioListenerType,
32 private ?bool $playerEffects
33 ){}
34
35 public function getName() : string{ return $this->name; }
36
37 public function getParent() : string{ return $this->parent; }
38
39 public function getXPosition() : ?float{ return $this->xPosition; }
40
41 public function getYPosition() : ?float{ return $this->yPosition; }
42
43 public function getZPosition() : ?float{ return $this->zPosition; }
44
45 public function getPitch() : ?float{ return $this->pitch; }
46
47 public function getYaw() : ?float{ return $this->yaw; }
48
49 public function getAudioListenerType() : ?int{ return $this->audioListenerType; }
50
51 public function getPlayerEffects() : ?bool{ return $this->playerEffects; }
52
53 public static function read(PacketSerializer $in) : self{
54 $name = $in->getString();
55 $parent = $in->getString();
56 $xPosition = $in->readOptional($in->getLFloat(...));
57 $yPosition = $in->readOptional($in->getLFloat(...));
58 $zPosition = $in->readOptional($in->getLFloat(...));
59 $pitch = $in->readOptional($in->getLFloat(...));
60 $yaw = $in->readOptional($in->getLFloat(...));
61 $audioListenerType = $in->readOptional($in->getByte(...));
62 $playerEffects = $in->readOptional($in->getBool(...));
63
64 return new self(
65 $name,
66 $parent,
67 $xPosition,
68 $yPosition,
69 $zPosition,
70 $pitch,
71 $yaw,
72 $audioListenerType,
73 $playerEffects
74 );
75 }
76
77 public function write(PacketSerializer $out) : void{
78 $out->putString($this->name);
79 $out->putString($this->parent);
80 $out->writeOptional($this->xPosition, $out->putLFloat(...));
81 $out->writeOptional($this->yPosition, $out->putLFloat(...));
82 $out->writeOptional($this->zPosition, $out->putLFloat(...));
83 $out->writeOptional($this->pitch, $out->putLFloat(...));
84 $out->writeOptional($this->yaw, $out->putLFloat(...));
85 $out->writeOptional($this->audioListenerType, $out->putByte(...));
86 $out->writeOptional($this->playerEffects, $out->putBool(...));
87 }
88}