PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
CameraAimAssistPresetsPacket.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\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\VarInt;
23use function count;
24
26 public const NETWORK_ID = ProtocolInfo::CAMERA_AIM_ASSIST_PRESETS_PACKET;
27
29 private array $categories;
31 private array $presets;
32 private int $operation;
33
39 public static function create(array $categories, array $presets, int $operation) : self{
40 $result = new self;
41 $result->categories = $categories;
42 $result->presets = $presets;
43 $result->operation = $operation;
44 return $result;
45 }
46
50 public function getCategories() : array{ return $this->categories; }
51
55 public function getPresets() : array{ return $this->presets; }
56
57 public function getOperation() : int{ return $this->operation; }
58
59 protected function decodePayload(ByteBufferReader $in) : void{
60 $this->categories = [];
61 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
62 $this->categories[] = CameraAimAssistCategory::read($in);
63 }
64
65 $this->presets = [];
66 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
67 $this->presets[] = CameraAimAssistPreset::read($in);
68 }
69
70 $this->operation = Byte::readUnsigned($in);
71 }
72
73 protected function encodePayload(ByteBufferWriter $out) : void{
74 VarInt::writeUnsignedInt($out, count($this->categories));
75 foreach($this->categories as $category){
76 $category->write($out);
77 }
78
79 VarInt::writeUnsignedInt($out, count($this->presets));
80 foreach($this->presets as $preset){
81 $preset->write($out);
82 }
83
84 Byte::writeUnsigned($out, $this->operation);
85 }
86
87 public function handle(PacketHandlerInterface $handler) : bool{
88 return $handler->handleCameraAimAssistPresets($this);
89 }
90}
static create(array $categories, array $presets, int $operation)