PocketMine-MP 5.37.1 git-cef37e7835c666594588f957a47b27d521c6a58e
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;
25use function count;
26
28
36 public function __construct(
37 private float $totalTime,
38 private int $easeType,
39 private array $curve,
40 private array $progressKeyFrames,
41 private array $rotationOptions,
42 ){}
43
44 public function getTotalTime() : float{ return $this->totalTime; }
45
49 public function getEaseType() : int{ return $this->easeType; }
50
54 public function getCurve() : array{ return $this->curve; }
55
59 public function getProgressKeyFrames() : array{ return $this->progressKeyFrames; }
60
64 public function getRotationOptions() : array{ return $this->rotationOptions; }
65
66 public static function read(ByteBufferReader $in) : self{
67 $totalTime = LE::readFloat($in);
68 $easeType = Byte::readUnsigned($in);
69
70 $curve = [];
71 $curveCount = VarInt::readUnsignedInt($in);
72 for($i = 0; $i < $curveCount; ++$i){
73 $curve[] = CommonTypes::getVector3($in);
74 }
75
76 $progressKeyFrames = [];
77 $progressKeyFrameCount = VarInt::readUnsignedInt($in);
78 for($i = 0; $i < $progressKeyFrameCount; ++$i){
79 $progressKeyFrames[] = CommonTypes::getVector2($in);
80 }
81
82 $rotationOptions = [];
83 $rotationOptionCount = VarInt::readUnsignedInt($in);
84 for($i = 0; $i < $rotationOptionCount; ++$i){
85 $rotationOptions[] = CameraRotationOption::read($in);
86 }
87
88 return new self($totalTime, $easeType, $curve, $progressKeyFrames, $rotationOptions);
89 }
90
91 public function write(ByteBufferWriter $out) : void{
92 LE::writeFloat($out, $this->totalTime);
93 Byte::writeUnsigned($out, $this->easeType);
94
95 VarInt::writeUnsignedInt($out, count($this->curve));
96 foreach($this->curve as $point){
97 CommonTypes::putVector3($out, $point);
98 }
99
100 VarInt::writeUnsignedInt($out, count($this->progressKeyFrames));
101 foreach($this->progressKeyFrames as $keyFrame){
102 CommonTypes::putVector2($out, $keyFrame);
103 }
104
105 VarInt::writeUnsignedInt($out, count($this->rotationOptions));
106 foreach($this->rotationOptions as $option){
107 $option->write($out);
108 }
109 }
110}
__construct(private float $totalTime, private int $easeType, private array $curve, private array $progressKeyFrames, private array $rotationOptions,)