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