PocketMine-MP 5.42.1 git-443151900a14fe9dc682cbf786fa441be1294fab
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
30 public function __construct(
31 private SerializableVoxelCells $cells,
32 private array $xCoordinates,
33 private array $yCoordinates,
34 private array $zCoordinates
35 ){}
36
37 public function getCells() : SerializableVoxelCells{ return $this->cells; }
38
42 public function getXCoordinates() : array{ return $this->xCoordinates; }
43
47 public function getYCoordinates() : array{ return $this->yCoordinates; }
48
52 public function getZCoordinates() : array{ return $this->zCoordinates; }
53
54 public static function read(ByteBufferReader $in) : self{
55 $cells = SerializableVoxelCells::read($in);
56
57 $xCoordinates = [];
58 for($i = 0, $xCoordinatesCount = VarInt::readUnsignedInt($in); $i < $xCoordinatesCount; ++$i){
59 $xCoordinates[] = LE::readFloat($in);
60 }
61
62 $yCoordinates = [];
63 for($i = 0, $yCoordinatesCount = VarInt::readUnsignedInt($in); $i < $yCoordinatesCount; ++$i){
64 $yCoordinates[] = LE::readFloat($in);
65 }
66
67 $zCoordinates = [];
68 for($i = 0, $zCoordinatesCount = VarInt::readUnsignedInt($in); $i < $zCoordinatesCount; ++$i){
69 $zCoordinates[] = LE::readFloat($in);
70 }
71
72 return new self(
73 $cells,
74 $xCoordinates,
75 $yCoordinates,
76 $zCoordinates
77 );
78 }
79
80 public function write(ByteBufferWriter $out) : void{
81 $this->cells->write($out);
82
83 VarInt::writeUnsignedInt($out, count($this->xCoordinates));
84 foreach($this->xCoordinates as $value){
85 LE::writeFloat($out, $value);
86 }
87
88 VarInt::writeUnsignedInt($out, count($this->yCoordinates));
89 foreach($this->yCoordinates as $value){
90 LE::writeFloat($out, $value);
91 }
92
93 VarInt::writeUnsignedInt($out, count($this->zCoordinates));
94 foreach($this->zCoordinates as $value){
95 LE::writeFloat($out, $value);
96 }
97 }
98}
__construct(private SerializableVoxelCells $cells, private array $xCoordinates, private array $yCoordinates, private array $zCoordinates)