PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
CameraAimAssistPacket.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\LE;
23use pocketmine\network\mcpe\protocol\types\camera\CameraAimAssistActionType;
24use pocketmine\network\mcpe\protocol\types\camera\CameraAimAssistTargetMode;
25
27 public const NETWORK_ID = ProtocolInfo::CAMERA_AIM_ASSIST_PACKET;
28
29 private string $presetId;
30 private Vector2 $viewAngle;
31 private float $distance;
32 private CameraAimAssistTargetMode $targetMode;
33 private CameraAimAssistActionType $actionType;
34 private bool $showDebugRender;
35
39 public static function create(string $presetId, Vector2 $viewAngle, float $distance, CameraAimAssistTargetMode $targetMode, CameraAimAssistActionType $actionType, bool $showDebugRender) : self{
40 $result = new self;
41 $result->presetId = $presetId;
42 $result->viewAngle = $viewAngle;
43 $result->distance = $distance;
44 $result->targetMode = $targetMode;
45 $result->actionType = $actionType;
46 $result->showDebugRender = $showDebugRender;
47 return $result;
48 }
49
50 public function getPresetId() : string{ return $this->presetId; }
51
52 public function getViewAngle() : Vector2{ return $this->viewAngle; }
53
54 public function getDistance() : float{ return $this->distance; }
55
56 public function getTargetMode() : CameraAimAssistTargetMode{ return $this->targetMode; }
57
58 public function getActionType() : CameraAimAssistActionType{ return $this->actionType; }
59
60 public function getShowDebugRender() : bool{ return $this->showDebugRender; }
61
62 protected function decodePayload(ByteBufferReader $in) : void{
63 $this->presetId = CommonTypes::getString($in);
64 $this->viewAngle = CommonTypes::getVector2($in);
65 $this->distance = LE::readFloat($in);
66 $this->targetMode = CameraAimAssistTargetMode::fromPacket(Byte::readUnsigned($in));
67 $this->actionType = CameraAimAssistActionType::fromPacket(Byte::readUnsigned($in));
68 $this->showDebugRender = CommonTypes::getBool($in);
69 }
70
71 protected function encodePayload(ByteBufferWriter $out) : void{
72 CommonTypes::putString($out, $this->presetId);
73 CommonTypes::putVector2($out, $this->viewAngle);
74 LE::writeFloat($out, $this->distance);
75 Byte::writeUnsigned($out, $this->targetMode->value);
76 Byte::writeUnsigned($out, $this->actionType->value);
77 CommonTypes::putBool($out, $this->showDebugRender);
78 }
79
80 public function handle(PacketHandlerInterface $handler) : bool{
81 return $handler->handleCameraAimAssist($this);
82 }
83}
static create(string $presetId, Vector2 $viewAngle, float $distance, CameraAimAssistTargetMode $targetMode, CameraAimAssistActionType $actionType, bool $showDebugRender)