PocketMine-MP 5.37.1 git-cef37e7835c666594588f957a47b27d521c6a58e
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\VarInt;
22use pocketmine\network\mcpe\protocol\types\GraphicsOverrideParameterType;
24use function count;
25
27 public const NETWORK_ID = ProtocolInfo::GRAPHICS_OVERRIDE_PARAMETER_PACKET;
28
30 private array $values = [];
31 private string $biomeIdentifier;
32 private GraphicsOverrideParameterType $parameterType;
33 private bool $reset;
34
39 public static function create(array $values, string $biomeIdentifier, GraphicsOverrideParameterType $parameterType, bool $reset) : self{
40 $result = new self;
41 $result->values = $values;
42 $result->biomeIdentifier = $biomeIdentifier;
43 $result->parameterType = $parameterType;
44 $result->reset = $reset;
45 return $result;
46 }
47
51 public function getValues() : array{ return $this->values; }
52
53 public function getBiomeIdentifier() : string{ return $this->biomeIdentifier; }
54
55 public function getParameterType() : GraphicsOverrideParameterType{ return $this->parameterType; }
56
57 public function isReset() : bool{ return $this->reset; }
58
59 protected function decodePayload(ByteBufferReader $in) : void{
60 $count = VarInt::readUnsignedInt($in);
61 for($i = 0; $i < $count; ++$i){
62 $this->values[] = ParameterKeyframeValue::read($in);
63 }
64 $this->biomeIdentifier = CommonTypes::getString($in);
65 $this->parameterType = GraphicsOverrideParameterType::fromPacket(Byte::readUnsigned($in));
66 $this->reset = CommonTypes::getBool($in);
67 }
68
69 protected function encodePayload(ByteBufferWriter $out) : void{
70 VarInt::writeUnsignedInt($out, count($this->values));
71 foreach($this->values as $value){
72 $value->write($out);
73 }
74 CommonTypes::putString($out, $this->biomeIdentifier);
75 Byte::writeUnsigned($out, $this->parameterType->value);
76 CommonTypes::putBool($out, $this->reset);
77 }
78
79 public function handle(PacketHandlerInterface $handler) : bool{
80 return $handler->handleGraphicsOverrideParameter($this);
81 }
82}
static create(array $values, string $biomeIdentifier, GraphicsOverrideParameterType $parameterType, bool $reset)