PocketMine-MP 5.18.1 git-9381fc4172e5dce4cada1cb356050c8a2ab57b94
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
21
23 public const NETWORK_ID = ProtocolInfo::CAMERA_INSTRUCTION_PACKET;
24
25 private ?CameraSetInstruction $set;
26 private ?bool $clear;
27 private ?CameraFadeInstruction $fade;
28 private ?CameraTargetInstruction $target;
29 private ?bool $removeTarget;
30
34 public static function create(?CameraSetInstruction $set, ?bool $clear, ?CameraFadeInstruction $fade, ?CameraTargetInstruction $target, ?bool $removeTarget) : self{
35 $result = new self;
36 $result->set = $set;
37 $result->clear = $clear;
38 $result->fade = $fade;
39 $result->target = $target;
40 $result->removeTarget = $removeTarget;
41 return $result;
42 }
43
44 public function getSet() : ?CameraSetInstruction{ return $this->set; }
45
46 public function getClear() : ?bool{ return $this->clear; }
47
48 public function getFade() : ?CameraFadeInstruction{ return $this->fade; }
49
50 public function getTarget() : ?CameraTargetInstruction{ return $this->target; }
51
52 protected function decodePayload(PacketSerializer $in) : void{
53 $this->set = $in->readOptional(fn() => CameraSetInstruction::read($in));
54 $this->clear = $in->readOptional($in->getBool(...));
55 $this->fade = $in->readOptional(fn() => CameraFadeInstruction::read($in));
56 $this->target = $in->readOptional(fn() => CameraTargetInstruction::read($in));
57 $this->removeTarget = $in->readOptional($in->getBool(...));
58 }
59
60 protected function encodePayload(PacketSerializer $out) : void{
61 $out->writeOptional($this->set, fn(CameraSetInstruction $v) => $v->write($out));
62 $out->writeOptional($this->clear, $out->putBool(...));
63 $out->writeOptional($this->fade, fn(CameraFadeInstruction $v) => $v->write($out));
64 $out->writeOptional($this->target, fn(CameraTargetInstruction $v) => $v->write($out));
65 $out->writeOptional($this->removeTarget, $out->putBool(...));
66 }
67
68 public function handle(PacketHandlerInterface $handler) : bool{
69 return $handler->handleCameraInstruction($this);
70 }
71}
static create(?CameraSetInstruction $set, ?bool $clear, ?CameraFadeInstruction $fade, ?CameraTargetInstruction $target, ?bool $removeTarget)