PocketMine-MP 5.37.1 git-cef37e7835c666594588f957a47b27d521c6a58e
Loading...
Searching...
No Matches
BiomeReplacementData.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;
21use function count;
22
24
28 public function __construct(
29 private int $biome,
30 private int $dimension,
31 private array $targetBiomes,
32 private float $amount,
33 private int $replacementIndex
34 ){}
35
36 public function getBiome() : int{ return $this->biome; }
37
38 public function getDimension() : int{ return $this->dimension; }
39
43 public function getTargetBiomes() : array{ return $this->targetBiomes; }
44
45 public function getAmount() : float{ return $this->amount; }
46
47 public function getReplacementIndex() : int{ return $this->replacementIndex; }
48
49 public static function read(ByteBufferReader $in) : self{
50 $biome = LE::readSignedShort($in);
51 $dimension = VarInt::readSignedInt($in);
52 $targetBiomes = [];
53 $targetBiomeCount = VarInt::readUnsignedInt($in);
54 for($i = 0; $i < $targetBiomeCount; ++$i){
55 $targetBiomes[] = LE::readSignedShort($in);
56 }
57 $amount = LE::readFloat($in);
58 $replacementIndex = LE::readUnsignedInt($in);
59 return new self($biome, $dimension, $targetBiomes, $amount, $replacementIndex);
60 }
61
62 public function write(ByteBufferWriter $out) : void{
63 LE::writeSignedShort($out, $this->biome);
64 VarInt::writeSignedInt($out, $this->dimension);
65 VarInt::writeUnsignedInt($out, count($this->targetBiomes));
66 foreach($this->targetBiomes as $biome){
67 LE::writeSignedShort($out, $biome);
68 }
69 LE::writeFloat($out, $this->amount);
70 LE::writeUnsignedInt($out, $this->replacementIndex);
71 }
72}
__construct(private int $biome, private int $dimension, private array $targetBiomes, private float $amount, private int $replacementIndex)