PocketMine-MP 5.21.2 git-09bf203267aca9b83a09640e17bfac0fc7b58ff8
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
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 public function getRemoveTarget() : ?bool{ return $this->removeTarget; }
53
54 protected function decodePayload(PacketSerializer $in) : void{
55 $this->set = $in->readOptional(fn() => CameraSetInstruction::read($in));
56 $this->clear = $in->readOptional($in->getBool(...));
57 $this->fade = $in->readOptional(fn() => CameraFadeInstruction::read($in));
58 $this->target = $in->readOptional(fn() => CameraTargetInstruction::read($in));
59 $this->removeTarget = $in->readOptional($in->getBool(...));
60 }
61
62 protected function encodePayload(PacketSerializer $out) : void{
63 $out->writeOptional($this->set, fn(CameraSetInstruction $v) => $v->write($out));
64 $out->writeOptional($this->clear, $out->putBool(...));
65 $out->writeOptional($this->fade, fn(CameraFadeInstruction $v) => $v->write($out));
66 $out->writeOptional($this->target, fn(CameraTargetInstruction $v) => $v->write($out));
67 $out->writeOptional($this->removeTarget, $out->putBool(...));
68 }
69
70 public function handle(PacketHandlerInterface $handler) : bool{
71 return $handler->handleCameraInstruction($this);
72 }
73}
static create(?CameraSetInstruction $set, ?bool $clear, ?CameraFadeInstruction $fade, ?CameraTargetInstruction $target, ?bool $removeTarget)