PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
CameraSetInstruction.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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
23
25
26 public function __construct(
27 private int $preset,
28 private ?CameraSetInstructionEase $ease,
29 private ?Vector3 $cameraPosition,
30 private ?CameraSetInstructionRotation $rotation,
31 private ?Vector3 $facingPosition,
32 private ?Vector2 $viewOffset,
33 private ?Vector3 $entityOffset,
34 private ?bool $default,
35 private bool $ignoreStartingValuesComponent
36 ){}
37
38 public function getPreset() : int{ return $this->preset; }
39
40 public function getEase() : ?CameraSetInstructionEase{ return $this->ease; }
41
42 public function getCameraPosition() : ?Vector3{ return $this->cameraPosition; }
43
44 public function getRotation() : ?CameraSetInstructionRotation{ return $this->rotation; }
45
46 public function getFacingPosition() : ?Vector3{ return $this->facingPosition; }
47
48 public function getViewOffset() : ?Vector2{ return $this->viewOffset; }
49
50 public function getEntityOffset() : ?Vector3{ return $this->entityOffset; }
51
52 public function getDefault() : ?bool{ return $this->default; }
53
54 public function isIgnoringStartingValuesComponent() : bool{ return $this->ignoreStartingValuesComponent; }
55
56 public static function read(ByteBufferReader $in) : self{
57 $preset = LE::readUnsignedInt($in);
58 $ease = CommonTypes::readOptional($in, CameraSetInstructionEase::read(...));
59 $cameraPosition = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
60 $rotation = CommonTypes::readOptional($in, CameraSetInstructionRotation::read(...));
61 $facingPosition = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
62 $viewOffset = CommonTypes::readOptional($in, CommonTypes::getVector2(...));
63 $entityOffset = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
64 $default = CommonTypes::readOptional($in, CommonTypes::getBool(...));
65 $ignoreStartingValuesComponent = CommonTypes::getBool($in);
66
67 return new self(
68 $preset,
69 $ease,
70 $cameraPosition,
71 $rotation,
72 $facingPosition,
73 $viewOffset,
74 $entityOffset,
75 $default,
76 $ignoreStartingValuesComponent
77 );
78 }
79
80 public function write(ByteBufferWriter $out) : void{
81 LE::writeUnsignedInt($out, $this->preset);
82 CommonTypes::writeOptional($out, $this->ease, fn(ByteBufferWriter $out, CameraSetInstructionEase $v) => $v->write($out));
83 CommonTypes::writeOptional($out, $this->cameraPosition, CommonTypes::putVector3(...));
84 CommonTypes::writeOptional($out, $this->rotation, fn(ByteBufferWriter $out, CameraSetInstructionRotation $v) => $v->write($out));
85 CommonTypes::writeOptional($out, $this->facingPosition, CommonTypes::putVector3(...));
86 CommonTypes::writeOptional($out, $this->viewOffset, CommonTypes::putVector2(...));
87 CommonTypes::writeOptional($out, $this->entityOffset, CommonTypes::putVector3(...));
88 CommonTypes::writeOptional($out, $this->default, CommonTypes::putBool(...));
89 CommonTypes::putBool($out, $this->ignoreStartingValuesComponent);
90 }
91}