PocketMine-MP 5.40.1 git-25718e8ccd903d1408fb25666ef84028379bbea6
Loading...
Searching...
No Matches
SerializableVoxelShape.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\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
20use pmmp\encoding\VarInt;
21use function count;
22
24
31 public function __construct(
32 private array $cells,
33 private array $xCoordinates,
34 private array $yCoordinates,
35 private array $zCoordinates
36 ){}
37
41 public function getCells() : array{ return $this->cells; }
42
46 public function getXCoordinates() : array{ return $this->xCoordinates; }
47
51 public function getYCoordinates() : array{ return $this->yCoordinates; }
52
56 public function getZCoordinates() : array{ return $this->zCoordinates; }
57
58 public static function read(ByteBufferReader $in) : self{
59 $cells = [];
60 for($i = 0, $cellsCount = VarInt::readUnsignedInt($in); $i < $cellsCount; ++$i){
61 $cells[] = SerializableVoxelCells::read($in);
62 }
63
64 $xCoordinates = [];
65 for($i = 0, $xCoordinatesCount = VarInt::readUnsignedInt($in); $i < $xCoordinatesCount; ++$i){
66 $xCoordinates[] = LE::readFloat($in);
67 }
68
69 $yCoordinates = [];
70 for($i = 0, $yCoordinatesCount = VarInt::readUnsignedInt($in); $i < $yCoordinatesCount; ++$i){
71 $yCoordinates[] = LE::readFloat($in);
72 }
73
74 $zCoordinates = [];
75 for($i = 0, $zCoordinatesCount = VarInt::readUnsignedInt($in); $i < $zCoordinatesCount; ++$i){
76 $zCoordinates[] = LE::readFloat($in);
77 }
78
79 return new self(
80 $cells,
81 $xCoordinates,
82 $yCoordinates,
83 $zCoordinates
84 );
85 }
86
87 public function write(ByteBufferWriter $out) : void{
88 VarInt::writeUnsignedInt($out, count($this->cells));
89 foreach($this->cells as $cell){
90 $cell->write($out);
91 }
92
93 VarInt::writeUnsignedInt($out, count($this->xCoordinates));
94 foreach($this->xCoordinates as $value){
95 LE::writeFloat($out, $value);
96 }
97
98 VarInt::writeUnsignedInt($out, count($this->yCoordinates));
99 foreach($this->yCoordinates as $value){
100 LE::writeFloat($out, $value);
101 }
102
103 VarInt::writeUnsignedInt($out, count($this->zCoordinates));
104 foreach($this->zCoordinates as $value){
105 LE::writeFloat($out, $value);
106 }
107 }
108}
__construct(private array $cells, private array $xCoordinates, private array $yCoordinates, private array $zCoordinates)