PocketMine-MP 5.40.1 git-25718e8ccd903d1408fb25666ef84028379bbea6
Loading...
Searching...
No Matches
SerializableVoxelCells.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;
16
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\VarInt;
21use function count;
22
24
28 public function __construct(
29 private int $xSize,
30 private int $ySize,
31 private int $zSize,
32 private array $storage
33 ){}
34
35 public function getXSize() : int{ return $this->xSize; }
36
37 public function getYSize() : int{ return $this->ySize; }
38
39 public function getZSize() : int{ return $this->zSize; }
40
44 public function getStorage() : array{ return $this->storage; }
45
46 public static function read(ByteBufferReader $in) : self{
47 $xSize = Byte::readUnsigned($in);
48 $ySize = Byte::readUnsigned($in);
49 $zSize = Byte::readUnsigned($in);
50
51 $storage = [];
52 for($i = 0, $storageCount = VarInt::readUnsignedInt($in); $i < $storageCount; ++$i){
53 $storage[] = Byte::readUnsigned($in);
54 }
55
56 return new self(
57 $xSize,
58 $ySize,
59 $zSize,
60 $storage
61 );
62 }
63
64 public function write(ByteBufferWriter $out) : void{
65 Byte::writeUnsigned($out, $this->xSize);
66 Byte::writeUnsigned($out, $this->ySize);
67 Byte::writeUnsigned($out, $this->zSize);
68
69 VarInt::writeUnsignedInt($out, count($this->storage));
70 foreach($this->storage as $value){
71 Byte::writeUnsigned($out, $value);
72 }
73 }
74}
__construct(private int $xSize, private int $ySize, private int $zSize, private array $storage)