PocketMine-MP 5.36.1 git-eaa7c4834c8fe2f379d24e7f0ee6cc63cfb18ccc
Loading...
Searching...
No Matches
CommandEnumConstraintRawData.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\types\command\raw;
16
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\LE;
21use pmmp\encoding\VarInt;
22use function count;
23
25
30 public function __construct(
31 private int $affectedValueIndex,
32 private int $enumIndex,
33 private array $constraints
34 ){}
35
36 public function getAffectedValueIndex() : int{ return $this->affectedValueIndex; }
37
38 public function getEnumIndex() : int{ return $this->enumIndex; }
39
44 public function getConstraints() : array{ return $this->constraints; }
45
46 public static function read(ByteBufferReader $in) : self{
47 $affectedValueIndex = LE::readUnsignedInt($in);
48 $enumIndex = LE::readUnsignedInt($in);
49
50 $constraints = [];
51 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
52 $constraints[] = Byte::readUnsigned($in);
53 }
54
55 return new self(
56 affectedValueIndex: $affectedValueIndex,
57 enumIndex: $enumIndex,
58 constraints: $constraints
59 );
60 }
61
62 public function write(ByteBufferWriter $out) : void{
63 LE::writeUnsignedInt($out, $this->affectedValueIndex);
64 LE::writeUnsignedInt($out, $this->enumIndex);
65
66 VarInt::writeUnsignedInt($out, count($this->constraints));
67 foreach($this->constraints as $constraint){
68 Byte::writeUnsigned($out, $constraint);
69 }
70 }
71}
__construct(private int $affectedValueIndex, private int $enumIndex, private array $constraints)