PocketMine-MP 5.42.2 git-40e2639b20bdc4ddba49d9f7f5fa0d5e92aa266f
Loading...
Searching...
No Matches
CameraSplineInstruction.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\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\LE;
21use pmmp\encoding\VarInt;
24use function count;
25
27
35 public function __construct(
36 private float $totalTime,
37 private int $easeType,
38 private array $curve,
39 private array $progressKeyFrames,
40 private array $rotationOptions,
41 private string $splineIdentifier,
42 private bool $loadFromJson
43 ){}
44
45 public function getTotalTime() : float{ return $this->totalTime; }
46
50 public function getEaseType() : int{ return $this->easeType; }
51
55 public function getCurve() : array{ return $this->curve; }
56
60 public function getProgressKeyFrames() : array{ return $this->progressKeyFrames; }
61
65 public function getRotationOptions() : array{ return $this->rotationOptions; }
66
67 public function getSplineIdentifier() : string{ return $this->splineIdentifier; }
68
69 public function isLoadFromJson() : bool{ return $this->loadFromJson; }
70
71 public static function read(ByteBufferReader $in) : self{
72 $totalTime = LE::readFloat($in);
73 $easeType = Byte::readUnsigned($in);
74
75 $curve = [];
76 $curveCount = VarInt::readUnsignedInt($in);
77 for($i = 0; $i < $curveCount; ++$i){
78 $curve[] = CommonTypes::getVector3($in);
79 }
80
81 $progressKeyFrames = [];
82 $progressKeyFrameCount = VarInt::readUnsignedInt($in);
83 for($i = 0; $i < $progressKeyFrameCount; ++$i){
84 $progressKeyFrames[] = CameraProgressOption::read($in);
85 }
86
87 $rotationOptions = [];
88 $rotationOptionCount = VarInt::readUnsignedInt($in);
89 for($i = 0; $i < $rotationOptionCount; ++$i){
90 $rotationOptions[] = CameraRotationOption::read($in);
91 }
92
93 $splineIdentifier = CommonTypes::getString($in);
94 $loadFromJson = CommonTypes::getBool($in);
95
96 return new self($totalTime, $easeType, $curve, $progressKeyFrames, $rotationOptions, $splineIdentifier, $loadFromJson);
97 }
98
99 public function write(ByteBufferWriter $out) : void{
100 LE::writeFloat($out, $this->totalTime);
101 Byte::writeUnsigned($out, $this->easeType);
102
103 VarInt::writeUnsignedInt($out, count($this->curve));
104 foreach($this->curve as $point){
105 CommonTypes::putVector3($out, $point);
106 }
107
108 VarInt::writeUnsignedInt($out, count($this->progressKeyFrames));
109 foreach($this->progressKeyFrames as $keyFrame){
110 $keyFrame->write($out);
111 }
112
113 VarInt::writeUnsignedInt($out, count($this->rotationOptions));
114 foreach($this->rotationOptions as $option){
115 $option->write($out);
116 }
117
118 CommonTypes::putString($out, $this->splineIdentifier);
119 CommonTypes::putBool($out, $this->loadFromJson);
120 }
121}
__construct(private float $totalTime, private int $easeType, private array $curve, private array $progressKeyFrames, private array $rotationOptions, private string $splineIdentifier, private bool $loadFromJson)