PocketMine-MP 5.44.4 git-bc94a0da0c87abe7eb99d229a9ec672b3c405d11
Loading...
Searching...
No Matches
GraphicsOverrideParameterPacket.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;
21use pmmp\encoding\VarInt;
24use pocketmine\network\mcpe\protocol\types\GraphicsOverrideParameterType;
26use function count;
27
29 public const NETWORK_ID = ProtocolInfo::GRAPHICS_OVERRIDE_PARAMETER_PACKET;
30
32 private array $values = [];
33 private ?float $unknownFloat;
34 private ?Vector3 $unknownVector3;
35 private string $biomeIdentifier;
36 private ?string $playerIdentifier;
37 private GraphicsOverrideParameterType $parameterType;
38 private bool $reset;
39
44 public static function create(
45 array $values,
46 ?float $unknownFloat,
47 ?Vector3 $unknownVector3,
48 string $biomeIdentifier,
49 ?string $playerIdentifier,
50 GraphicsOverrideParameterType $parameterType,
51 bool $reset,
52 ) : self{
53 $result = new self;
54 $result->values = $values;
55 $result->unknownFloat = $unknownFloat;
56 $result->unknownVector3 = $unknownVector3;
57 $result->biomeIdentifier = $biomeIdentifier;
58 $result->playerIdentifier = $playerIdentifier;
59 $result->parameterType = $parameterType;
60 $result->reset = $reset;
61 return $result;
62 }
63
67 public function getValues() : array{ return $this->values; }
68
69 public function getUnknownFloat() : ?float{ return $this->unknownFloat; }
70
71 public function getUnknownVector3() : ?Vector3{ return $this->unknownVector3; }
72
73 public function getBiomeIdentifier() : string{ return $this->biomeIdentifier; }
74
75 public function getPlayerIdentifier() : ?string{ return $this->playerIdentifier; }
76
77 public function getParameterType() : GraphicsOverrideParameterType{ return $this->parameterType; }
78
79 public function isReset() : bool{ return $this->reset; }
80
81 protected function decodePayload(ByteBufferReader $in) : void{
82 $count = VarInt::readUnsignedInt($in);
83 for($i = 0; $i < $count; ++$i){
84 $this->values[] = ParameterKeyframeValue::read($in);
85 }
86 $this->unknownFloat = CommonTypes::readOptional($in, LE::readFloat(...));
87 $this->unknownVector3 = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
88 $this->biomeIdentifier = CommonTypes::getString($in);
89 $this->playerIdentifier = CommonTypes::readOptional($in, CommonTypes::getString(...));
90 $this->parameterType = GraphicsOverrideParameterType::fromPacket(Byte::readUnsigned($in));
91 $this->reset = CommonTypes::getBool($in);
92 }
93
94 protected function encodePayload(ByteBufferWriter $out) : void{
95 VarInt::writeUnsignedInt($out, count($this->values));
96 foreach($this->values as $value){
97 $value->write($out);
98 }
99 CommonTypes::writeOptional($out, $this->unknownFloat, LE::writeFloat(...));
100 CommonTypes::writeOptional($out, $this->unknownVector3, CommonTypes::putVector3(...));
101 CommonTypes::putString($out, $this->biomeIdentifier);
102 CommonTypes::writeOptional($out, $this->playerIdentifier, CommonTypes::putString(...));
103 Byte::writeUnsigned($out, $this->parameterType->value);
104 CommonTypes::putBool($out, $this->reset);
105 }
106
107 public function handle(PacketHandlerInterface $handler) : bool{
108 return $handler->handleGraphicsOverrideParameter($this);
109 }
110}
static create(array $values, ?float $unknownFloat, ?Vector3 $unknownVector3, string $biomeIdentifier, ?string $playerIdentifier, GraphicsOverrideParameterType $parameterType, bool $reset,)