PocketMine-MP 5.43.2 git-a137a986d01d9af23452b2e741699a770c7ae112
Loading...
Searching...
No Matches
BiomeNoiseGradientSurfaceData.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
31 public function __construct(
32 private array $nonReplaceableBlocks,
33 private array $gradientBlocks,
34 private string $noiseSeed,
35 private int $firstOctave,
36 private array $amplitudes
37 ){}
38
42 public function getNonReplaceableBlocks() : array{ return $this->nonReplaceableBlocks; }
43
47 public function getGradientBlocks() : array{ return $this->gradientBlocks; }
48
49 public function getNoiseSeed() : string{ return $this->noiseSeed; }
50
51 public function getFirstOctave() : int{ return $this->firstOctave; }
52
56 public function getAmplitudes() : array{ return $this->amplitudes; }
57
58 public static function read(ByteBufferReader $in) : self{
59 $nonReplaceableBlocks = [];
60 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
61 $nonReplaceableBlocks[] = LE::readUnsignedInt($in);
62 }
63
64 $gradientBlocks = [];
65 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
66 $gradientBlocks[] = LE::readUnsignedInt($in);
67 }
68
69 $noiseSeed = CommonTypes::getString($in);
70 $firstOctave = LE::readUnsignedInt($in);
71
72 $amplitudes = [];
73 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
74 $amplitudes[] = LE::readFloat($in);
75 }
76
77 return new self(
78 $nonReplaceableBlocks,
79 $gradientBlocks,
80 $noiseSeed,
81 $firstOctave,
82 $amplitudes
83 );
84 }
85
86 public function write(ByteBufferWriter $out) : void{
87 VarInt::writeUnsignedInt($out, count($this->nonReplaceableBlocks));
88 foreach($this->nonReplaceableBlocks as $value){
89 LE::writeUnsignedInt($out, $value);
90 }
91
92 VarInt::writeUnsignedInt($out, count($this->gradientBlocks));
93 foreach($this->gradientBlocks as $value){
94 LE::writeUnsignedInt($out, $value);
95 }
96
97 CommonTypes::putString($out, $this->noiseSeed);
98 LE::writeUnsignedInt($out, $this->firstOctave);
99
100 VarInt::writeUnsignedInt($out, count($this->amplitudes));
101 foreach($this->amplitudes as $value){
102 LE::writeFloat($out, $value);
103 }
104 }
105}
__construct(private array $nonReplaceableBlocks, private array $gradientBlocks, private string $noiseSeed, private int $firstOctave, private array $amplitudes)