PocketMine-MP 5.37.1 git-cef37e7835c666594588f957a47b27d521c6a58e
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;
19use pmmp\encoding\LE;
26
28 public const NETWORK_ID = ProtocolInfo::CAMERA_INSTRUCTION_PACKET;
29
30 private ?CameraSetInstruction $set;
31 private ?bool $clear;
32 private ?CameraFadeInstruction $fade;
33 private ?CameraTargetInstruction $target;
34 private ?bool $removeTarget;
35 private ?CameraFovInstruction $fieldOfView;
36 private ?CameraSplineInstruction $spline;
37 private ?int $attachToEntity;
38 private ?bool $detachFromEntity;
39
43 public static function create(
45 ?bool $clear,
48 ?bool $removeTarget,
49 ?CameraFovInstruction $fieldOfView,
51 ?int $attachToEntity,
52 ?bool $detachFromEntity,
53 ) : self{
54 $result = new self;
55 $result->set = $set;
56 $result->clear = $clear;
57 $result->fade = $fade;
58 $result->target = $target;
59 $result->removeTarget = $removeTarget;
60 $result->fieldOfView = $fieldOfView;
61 $result->spline = $spline;
62 $result->attachToEntity = $attachToEntity;
63 $result->detachFromEntity = $detachFromEntity;
64 return $result;
65 }
66
67 public function getSet() : ?CameraSetInstruction{ return $this->set; }
68
69 public function getClear() : ?bool{ return $this->clear; }
70
71 public function getFade() : ?CameraFadeInstruction{ return $this->fade; }
72
73 public function getTarget() : ?CameraTargetInstruction{ return $this->target; }
74
75 public function getRemoveTarget() : ?bool{ return $this->removeTarget; }
76
77 public function getFieldOfView() : ?CameraFovInstruction{ return $this->fieldOfView; }
78
79 public function getSpline() : ?CameraSplineInstruction{ return $this->spline; }
80
81 public function getAttachToEntity() : ?int{ return $this->attachToEntity; }
82
83 public function getDetachFromEntity() : ?bool{ return $this->detachFromEntity; }
84
85 protected function decodePayload(ByteBufferReader $in) : void{
86 $this->set = CommonTypes::readOptional($in, CameraSetInstruction::read(...));
87 $this->clear = CommonTypes::readOptional($in, CommonTypes::getBool(...));
88 $this->fade = CommonTypes::readOptional($in, CameraFadeInstruction::read(...));
89 $this->target = CommonTypes::readOptional($in, CameraTargetInstruction::read(...));
90 $this->removeTarget = CommonTypes::readOptional($in, CommonTypes::getBool(...));
91 $this->fieldOfView = CommonTypes::readOptional($in, CameraFovInstruction::read(...));
92 $this->spline = CommonTypes::readOptional($in, CameraSplineInstruction::read(...));
93 $this->attachToEntity = CommonTypes::readOptional($in, LE::readSignedLong(...)); //WHY IS THIS NON-STANDARD?
94 $this->detachFromEntity = CommonTypes::readOptional($in, CommonTypes::getBool(...));
95 }
96
97 protected function encodePayload(ByteBufferWriter $out) : void{
98 CommonTypes::writeOptional($out, $this->set, fn(ByteBufferWriter $out, CameraSetInstruction $v) => $v->write($out));
99 CommonTypes::writeOptional($out, $this->clear, CommonTypes::putBool(...));
100 CommonTypes::writeOptional($out, $this->fade, fn(ByteBufferWriter $out, CameraFadeInstruction $v) => $v->write($out));
101 CommonTypes::writeOptional($out, $this->target, fn(ByteBufferWriter $out, CameraTargetInstruction $v) => $v->write($out));
102 CommonTypes::writeOptional($out, $this->removeTarget, CommonTypes::putBool(...));
103 CommonTypes::writeOptional($out, $this->fieldOfView, fn(ByteBufferWriter $out, CameraFovInstruction $v) => $v->write($out));
104 CommonTypes::writeOptional($out, $this->spline, fn(ByteBufferWriter $out, CameraSplineInstruction $v) => $v->write($out));
105 CommonTypes::writeOptional($out, $this->attachToEntity, LE::writeSignedLong(...)); //WHY IS THIS NON-STANDARD?
106 CommonTypes::writeOptional($out, $this->detachFromEntity, CommonTypes::putBool(...));
107 }
108
109 public function handle(PacketHandlerInterface $handler) : bool{
110 return $handler->handleCameraInstruction($this);
111 }
112}
static create(?CameraSetInstruction $set, ?bool $clear, ?CameraFadeInstruction $fade, ?CameraTargetInstruction $target, ?bool $removeTarget, ?CameraFovInstruction $fieldOfView, ?CameraSplineInstruction $spline, ?int $attachToEntity, ?bool $detachFromEntity,)