PocketMine-MP 5.17.1 git-df4ada81e5d74a14046f27cf44a37dcee69d657e
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
20
22 public const NETWORK_ID = ProtocolInfo::CAMERA_INSTRUCTION_PACKET;
23
24 private ?CameraSetInstruction $set;
25 private ?bool $clear;
26 private ?CameraFadeInstruction $fade;
27
31 public static function create(?CameraSetInstruction $set, ?bool $clear, ?CameraFadeInstruction $fade) : self{
32 $result = new self;
33 $result->set = $set;
34 $result->clear = $clear;
35 $result->fade = $fade;
36 return $result;
37 }
38
39 public function getSet() : ?CameraSetInstruction{ return $this->set; }
40
41 public function getClear() : ?bool{ return $this->clear; }
42
43 public function getFade() : ?CameraFadeInstruction{ return $this->fade; }
44
45 protected function decodePayload(PacketSerializer $in) : void{
46 $this->set = $in->readOptional(fn() => CameraSetInstruction::read($in));
47 $this->clear = $in->readOptional($in->getBool(...));
48 $this->fade = $in->readOptional(fn() => CameraFadeInstruction::read($in));
49 }
50
51 protected function encodePayload(PacketSerializer $out) : void{
52 $out->writeOptional($this->set, fn(CameraSetInstruction $v) => $v->write($out));
53 $out->writeOptional($this->clear, $out->putBool(...));
54 $out->writeOptional($this->fade, fn(CameraFadeInstruction $v) => $v->write($out));
55 }
56
57 public function handle(PacketHandlerInterface $handler) : bool{
58 return $handler->handleCameraInstruction($this);
59 }
60}
static create(?CameraSetInstruction $set, ?bool $clear, ?CameraFadeInstruction $fade)