PocketMine-MP 5.28.1 git-88cdc2eb67c40075559c3ef51418b418cd5488e9
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
20use function count;
21
23
28 public function __construct(
29 private int $nameIndex,
30 private ?int $id,
31 private float $temperature,
32 private float $downfall,
33 private float $redSporeDensity,
34 private float $blueSporeDensity,
35 private float $ashDensity,
36 private float $whiteAshDensity,
37 private float $depth,
38 private float $scale,
39 private Color $mapWaterColor,
40 private bool $rain,
41 private ?array $tagIndexes,
42 private ?BiomeDefinitionChunkGenData $chunkGenData = null
43 ){}
44
45 public function getNameIndex() : int{ return $this->nameIndex; }
46
47 public function getId() : ?int{ return $this->id; }
48
49 public function getTemperature() : float{ return $this->temperature; }
50
51 public function getDownfall() : float{ return $this->downfall; }
52
53 public function getRedSporeDensity() : float{ return $this->redSporeDensity; }
54
55 public function getBlueSporeDensity() : float{ return $this->blueSporeDensity; }
56
57 public function getAshDensity() : float{ return $this->ashDensity; }
58
59 public function getWhiteAshDensity() : float{ return $this->whiteAshDensity; }
60
61 public function getDepth() : float{ return $this->depth; }
62
63 public function getScale() : float{ return $this->scale; }
64
65 public function getMapWaterColor() : Color{ return $this->mapWaterColor; }
66
67 public function hasRain() : bool{ return $this->rain; }
68
73 public function getTagIndexes() : ?array{ return $this->tagIndexes; }
74
75 public function getChunkGenData() : ?BiomeDefinitionChunkGenData{ return $this->chunkGenData; }
76
77 public static function read(PacketSerializer $in) : self{
78 $nameIndex = $in->getLShort();
79 $id = $in->readOptional($in->getLShort(...));
80 $temperature = $in->getLFloat();
81 $downfall = $in->getLFloat();
82 $redSporeDensity = $in->getLFloat();
83 $blueSporeDensity = $in->getLFloat();
84 $ashDensity = $in->getLFloat();
85 $whiteAshDensity = $in->getLFloat();
86 $depth = $in->getLFloat();
87 $scale = $in->getLFloat();
88 $mapWaterColor = Color::fromARGB($in->getLInt());
89 $rain = $in->getBool();
90 $tags = $in->readOptional(function() use ($in) : array{
91 $tagIndexes = [];
92
93 for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
94 $tagIndexes[] = $in->getLShort();
95 }
96
97 return $tagIndexes;
98 });
99 $chunkGenData = $in->readOptional(fn() => BiomeDefinitionChunkGenData::read($in));
100
101 return new self(
102 $nameIndex,
103 $id,
104 $temperature,
105 $downfall,
106 $redSporeDensity,
107 $blueSporeDensity,
108 $ashDensity,
109 $whiteAshDensity,
110 $depth,
111 $scale,
112 $mapWaterColor,
113 $rain,
114 $tags,
115 $chunkGenData
116 );
117 }
118
119 public function write(PacketSerializer $out) : void{
120 $out->putLShort($this->nameIndex);
121 $out->writeOptional($this->id, $out->putLShort(...));
122 $out->putLFloat($this->temperature);
123 $out->putLFloat($this->downfall);
124 $out->putLFloat($this->redSporeDensity);
125 $out->putLFloat($this->blueSporeDensity);
126 $out->putLFloat($this->ashDensity);
127 $out->putLFloat($this->whiteAshDensity);
128 $out->putLFloat($this->depth);
129 $out->putLFloat($this->scale);
130 $out->putLInt($this->mapWaterColor->toARGB());
131 $out->putBool($this->rain);
132 $out->writeOptional($this->tagIndexes, function(array $tagIndexes) use ($out) : void{
133 $out->putUnsignedVarInt(count($tagIndexes));
134 foreach($tagIndexes as $tag){
135 $out->putLShort($tag);
136 }
137 });
138 $out->writeOptional($this->chunkGenData, fn(BiomeDefinitionChunkGenData $chunkGenData) => $chunkGenData->write($out));
139 }
140}
__construct(private int $nameIndex, private ?int $id, private float $temperature, private float $downfall, private float $redSporeDensity, private float $blueSporeDensity, private float $ashDensity, private float $whiteAshDensity, private float $depth, private float $scale, private Color $mapWaterColor, private bool $rain, private ?array $tagIndexes, private ?BiomeDefinitionChunkGenData $chunkGenData=null)