PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
BiomeCappedSurfaceData.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\biome\chunkgen;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
20use pmmp\encoding\VarInt;
22use function count;
23
25
30 public function __construct(
31 private array $floorBlocks,
32 private array $ceilingBlocks,
33 private ?int $seaBlock,
34 private ?int $foundationBlock,
35 private ?int $beachBlock,
36 ){}
37
41 public function getFloorBlocks() : array{ return $this->floorBlocks; }
42
46 public function getCeilingBlocks() : array{ return $this->ceilingBlocks; }
47
48 public function getSeaBlock() : ?int{ return $this->seaBlock; }
49
50 public function getFoundationBlock() : ?int{ return $this->foundationBlock; }
51
52 public function getBeachBlock() : ?int{ return $this->beachBlock; }
53
54 public static function read(ByteBufferReader $in) : self{
55 $floorBlocks = [];
56 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
57 $floorBlocks[] = LE::readUnsignedInt($in);
58 }
59
60 $ceilingBlocks = [];
61 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
62 $ceilingBlocks[] = LE::readUnsignedInt($in);
63 }
64
65 $seaBlock = CommonTypes::readOptional($in, LE::readUnsignedInt(...));
66 $foundationBlock = CommonTypes::readOptional($in, LE::readUnsignedInt(...));
67 $beachBlock = CommonTypes::readOptional($in, LE::readUnsignedInt(...));
68
69 return new self(
70 $floorBlocks,
71 $ceilingBlocks,
72 $seaBlock,
73 $foundationBlock,
74 $beachBlock
75 );
76 }
77
78 public function write(ByteBufferWriter $out) : void{
79 VarInt::writeUnsignedInt($out, count($this->floorBlocks));
80 foreach($this->floorBlocks as $block){
81 LE::writeUnsignedInt($out, $block);
82 }
83
84 VarInt::writeUnsignedInt($out, count($this->ceilingBlocks));
85 foreach($this->ceilingBlocks as $block){
86 LE::writeUnsignedInt($out, $block);
87 }
88
89 CommonTypes::writeOptional($out, $this->seaBlock, LE::writeUnsignedInt(...));
90 CommonTypes::writeOptional($out, $this->foundationBlock, LE::writeUnsignedInt(...));
91 CommonTypes::writeOptional($out, $this->beachBlock, LE::writeUnsignedInt(...));
92 }
93}
__construct(private array $floorBlocks, private array $ceilingBlocks, private ?int $seaBlock, private ?int $foundationBlock, private ?int $beachBlock,)