PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
CameraInstructionPacket.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;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
24
26 public const NETWORK_ID = ProtocolInfo::CAMERA_INSTRUCTION_PACKET;
27
28 private ?CameraSetInstruction $set;
29 private ?bool $clear;
30 private ?CameraFadeInstruction $fade;
31 private ?CameraTargetInstruction $target;
32 private ?bool $removeTarget;
33 private ?CameraFovInstruction $fieldOfView;
34
38 public static function create(?CameraSetInstruction $set, ?bool $clear, ?CameraFadeInstruction $fade, ?CameraTargetInstruction $target, ?bool $removeTarget, ?CameraFovInstruction $fieldOfView) : self{
39 $result = new self;
40 $result->set = $set;
41 $result->clear = $clear;
42 $result->fade = $fade;
43 $result->target = $target;
44 $result->removeTarget = $removeTarget;
45 $result->fieldOfView = $fieldOfView;
46 return $result;
47 }
48
49 public function getSet() : ?CameraSetInstruction{ return $this->set; }
50
51 public function getClear() : ?bool{ return $this->clear; }
52
53 public function getFade() : ?CameraFadeInstruction{ return $this->fade; }
54
55 public function getTarget() : ?CameraTargetInstruction{ return $this->target; }
56
57 public function getRemoveTarget() : ?bool{ return $this->removeTarget; }
58
59 public function getFieldOfView() : ?CameraFovInstruction{ return $this->fieldOfView; }
60
61 protected function decodePayload(ByteBufferReader $in) : void{
62 $this->set = CommonTypes::readOptional($in, CameraSetInstruction::read(...));
63 $this->clear = CommonTypes::readOptional($in, CommonTypes::getBool(...));
64 $this->fade = CommonTypes::readOptional($in, CameraFadeInstruction::read(...));
65 $this->target = CommonTypes::readOptional($in, CameraTargetInstruction::read(...));
66 $this->removeTarget = CommonTypes::readOptional($in, CommonTypes::getBool(...));
67 $this->fieldOfView = CommonTypes::readOptional($in, CameraFovInstruction::read(...));
68 }
69
70 protected function encodePayload(ByteBufferWriter $out) : void{
71 CommonTypes::writeOptional($out, $this->set, fn(ByteBufferWriter $out, CameraSetInstruction $v) => $v->write($out));
72 CommonTypes::writeOptional($out, $this->clear, CommonTypes::putBool(...));
73 CommonTypes::writeOptional($out, $this->fade, fn(ByteBufferWriter $out, CameraFadeInstruction $v) => $v->write($out));
74 CommonTypes::writeOptional($out, $this->target, fn(ByteBufferWriter $out, CameraTargetInstruction $v) => $v->write($out));
75 CommonTypes::writeOptional($out, $this->removeTarget, CommonTypes::putBool(...));
76 CommonTypes::writeOptional($out, $this->fieldOfView, fn(ByteBufferWriter $out, CameraFovInstruction $v) => $v->write($out));
77 }
78
79 public function handle(PacketHandlerInterface $handler) : bool{
80 return $handler->handleCameraInstruction($this);
81 }
82}
static create(?CameraSetInstruction $set, ?bool $clear, ?CameraFadeInstruction $fade, ?CameraTargetInstruction $target, ?bool $removeTarget, ?CameraFovInstruction $fieldOfView)