PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
BiomeDefinitionData.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;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
20use pmmp\encoding\VarInt;
24use function count;
25
27
32 public function __construct(
33 private int $nameIndex,
34 private int $id,
35 private float $temperature,
36 private float $downfall,
37 private float $foliageSnow,
38 private float $depth,
39 private float $scale,
40 private Color $mapWaterColor,
41 private bool $rain,
42 private ?array $tagIndexes,
43 private ?BiomeDefinitionChunkGenData $chunkGenData = null
44 ){}
45
46 public function getNameIndex() : int{ return $this->nameIndex; }
47
48 public function getId() : int{ return $this->id; }
49
50 public function getTemperature() : float{ return $this->temperature; }
51
52 public function getDownfall() : float{ return $this->downfall; }
53
54 public function getFoliageSnow() : float{ return $this->foliageSnow; }
55
56 public function getDepth() : float{ return $this->depth; }
57
58 public function getScale() : float{ return $this->scale; }
59
60 public function getMapWaterColor() : Color{ return $this->mapWaterColor; }
61
62 public function hasRain() : bool{ return $this->rain; }
63
68 public function getTagIndexes() : ?array{ return $this->tagIndexes; }
69
70 public function getChunkGenData() : ?BiomeDefinitionChunkGenData{ return $this->chunkGenData; }
71
72 public static function read(ByteBufferReader $in) : self{
73 $nameIndex = LE::readUnsignedShort($in);
74 $id = LE::readUnsignedShort($in);
75 $temperature = LE::readFloat($in);
76 $downfall = LE::readFloat($in);
77 $foliageSnow = LE::readFloat($in);
78 $depth = LE::readFloat($in);
79 $scale = LE::readFloat($in);
80 $mapWaterColor = Color::fromARGB(LE::readUnsignedInt($in));
81 $rain = CommonTypes::getBool($in);
82 $tags = CommonTypes::readOptional($in, function() use ($in) : array{
83 $tagIndexes = [];
84
85 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
86 $tagIndexes[] = LE::readUnsignedShort($in);
87 }
88
89 return $tagIndexes;
90 });
91 $chunkGenData = CommonTypes::readOptional($in, fn() => BiomeDefinitionChunkGenData::read($in));
92
93 return new self(
94 $nameIndex,
95 $id,
96 $temperature,
97 $downfall,
98 $foliageSnow,
99 $depth,
100 $scale,
101 $mapWaterColor,
102 $rain,
103 $tags,
104 $chunkGenData
105 );
106 }
107
108 public function write(ByteBufferWriter $out) : void{
109 LE::writeUnsignedShort($out, $this->nameIndex);
110 LE::writeUnsignedShort($out, $this->id);
111 LE::writeFloat($out, $this->temperature);
112 LE::writeFloat($out, $this->downfall);
113 LE::writeFloat($out, $this->foliageSnow);
114 LE::writeFloat($out, $this->depth);
115 LE::writeFloat($out, $this->scale);
116 LE::writeUnsignedInt($out, $this->mapWaterColor->toARGB());
117 CommonTypes::putBool($out, $this->rain);
118 CommonTypes::writeOptional($out, $this->tagIndexes, function(ByteBufferWriter $out, array $tagIndexes) : void{
119 VarInt::writeUnsignedInt($out, count($tagIndexes));
120 foreach($tagIndexes as $tag){
121 LE::writeUnsignedShort($out, $tag);
122 }
123 });
124 CommonTypes::writeOptional($out, $this->chunkGenData, fn(ByteBufferWriter $out, BiomeDefinitionChunkGenData $v) => $v->write($out));
125 }
126}
__construct(private int $nameIndex, private int $id, private float $temperature, private float $downfall, private float $foliageSnow, private float $depth, private float $scale, private Color $mapWaterColor, private bool $rain, private ?array $tagIndexes, private ?BiomeDefinitionChunkGenData $chunkGenData=null)