mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Remove biome colours and fix biome id arrays
This commit is contained in:
parent
4d121f7d84
commit
aafe0c4f69
@ -2048,16 +2048,6 @@ class Level implements ChunkManager, Metadatable{
|
||||
return $this->getChunk($x >> 4, $z >> 4, true)->getBiomeId($x & 0x0f, $z & 0x0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $x
|
||||
* @param int $z
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function getBiomeColor(int $x, int $z) : array{
|
||||
return $this->getChunk($x >> 4, $z >> 4, true)->getBiomeColor($x & 0x0f, $z & 0x0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $x
|
||||
* @param int $z
|
||||
@ -2077,17 +2067,6 @@ class Level implements ChunkManager, Metadatable{
|
||||
$this->getChunk($x >> 4, $z >> 4, true)->setBiomeId($x & 0x0f, $z & 0x0f, $biomeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $x
|
||||
* @param int $z
|
||||
* @param int $R
|
||||
* @param int $G
|
||||
* @param int $B
|
||||
*/
|
||||
public function setBiomeColor(int $x, int $z, int $R, int $G, int $B){
|
||||
$this->getChunk($x >> 4, $z >> 4, true)->setBiomeColor($x & 0x0f, $z & 0x0f, $R, $G, $B);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $x
|
||||
* @param int $z
|
||||
|
@ -210,23 +210,6 @@ interface Chunk{
|
||||
*/
|
||||
public function setBiomeId(int $x, int $z, int $biomeId);
|
||||
|
||||
/**
|
||||
* @param int $x
|
||||
* @param int $z
|
||||
*
|
||||
* @return int[] RGB bytes
|
||||
*/
|
||||
public function getBiomeColor(int $x, int $z) : int;
|
||||
|
||||
/**
|
||||
* @param int $x 0-15
|
||||
* @param int $z 0-15
|
||||
* @param int $R 0-255
|
||||
* @param int $G 0-255
|
||||
* @param int $B 0-255
|
||||
*/
|
||||
public function setBiomeColor(int $x, int $z, int $R, int $G, int $B);
|
||||
|
||||
public function getBlockIdColumn(int $x, int $z) : string;
|
||||
|
||||
public function getBlockDataColumn(int $x, int $z) : string;
|
||||
@ -313,11 +296,6 @@ interface Chunk{
|
||||
*/
|
||||
public function getBiomeIdArray() : string;
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
public function getBiomeColorArray() : array;
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
|
@ -33,6 +33,7 @@ use pocketmine\Player;
|
||||
use pocketmine\tile\Spawnable;
|
||||
use pocketmine\utils\BinaryStream;
|
||||
use pocketmine\utils\ChunkException;
|
||||
use pocketmine\utils\MainLogger;
|
||||
|
||||
class Anvil extends McRegion{
|
||||
|
||||
@ -63,7 +64,7 @@ class Anvil extends McRegion{
|
||||
]);
|
||||
}
|
||||
|
||||
//$nbt->BiomeColors = new IntArrayTag("BiomeColors", $chunk->getBiomeColorArray());
|
||||
$nbt->Biomes = new ByteArrayTag("Biomes", $chunk->getBiomeIdArray());
|
||||
$nbt->HeightMap = new IntArrayTag("HeightMap", $chunk->getHeightMapArray());
|
||||
|
||||
$entities = [];
|
||||
@ -124,22 +125,30 @@ class Anvil extends McRegion{
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($chunk->BiomeColors)){
|
||||
$biomeIds = GenericChunk::convertBiomeColours($chunk->BiomeColors->getValue()); //Convert back to PC format (RIP colours D:)
|
||||
}elseif(isset($chunk->Biomes)){
|
||||
$biomeIds = $chunk->Biomes->getValue();
|
||||
}else{
|
||||
$biomeIds = "";
|
||||
}
|
||||
|
||||
$result = new GenericChunk(
|
||||
$provider,
|
||||
$chunk["xPos"],
|
||||
$chunk["zPos"],
|
||||
$subChunks,
|
||||
$chunk->Entities instanceof ListTag ? $chunk->Entities->getValue() : [],
|
||||
$chunk->TileEntities instanceof ListTag ? $chunk->TileEntities->getValue() : [],
|
||||
/*$chunk->BiomeColors instanceof IntArrayTag ? $chunk->BiomeColors->getValue() : */ [], //TODO: remove this and revert to the original PC Biomes array
|
||||
$chunk->HeightMap instanceof IntArrayTag ? $chunk->HeightMap->getValue() : []
|
||||
$chunk->Entities->getValue(),
|
||||
$chunk->TileEntities->getValue(),
|
||||
$biomeIds,
|
||||
$chunk->HeightMap->getValue()
|
||||
);
|
||||
$result->setLightPopulated($chunk->LightPopulated instanceof ByteTag ? ((bool) $chunk->LightPopulated->getValue()) : false);
|
||||
$result->setPopulated($chunk->TerrainPopulated instanceof ByteTag ? ((bool) $chunk->TerrainPopulated->getValue()) : false);
|
||||
$result->setLightPopulated(isset($chunk->LightPopulated) ? ((bool) $chunk->LightPopulated->getValue()) : false);
|
||||
$result->setPopulated(isset($chunk->TerrainPopulated) ? ((bool) $chunk->TerrainPopulated->getValue()) : false);
|
||||
$result->setGenerated(true);
|
||||
return $result;
|
||||
}catch(\Throwable $e){
|
||||
echo $e->getMessage();
|
||||
MainLogger::getLogger()->logException($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -67,8 +67,8 @@ class GenericChunk implements Chunk{
|
||||
/** @var int[256] */
|
||||
protected $heightMap = [];
|
||||
|
||||
/** @var int[256] */
|
||||
protected $biomeColors = [];
|
||||
/** @var string */
|
||||
protected $biomeIds;
|
||||
|
||||
protected $extraData = [];
|
||||
|
||||
@ -85,10 +85,10 @@ class GenericChunk implements Chunk{
|
||||
* @param SubChunk[] $subChunks
|
||||
* @param CompoundTag[] $entities
|
||||
* @param CompoundTag[] $tiles
|
||||
* @param int[256] $biomeColors
|
||||
* @param string $biomeIds
|
||||
* @param int[256] $heightMap
|
||||
*/
|
||||
public function __construct($provider, int $chunkX, int $chunkZ, array $subChunks = [], array $entities = [], array $tiles = [], array $biomeColors = [], array $heightMap = []){
|
||||
public function __construct($provider, int $chunkX, int $chunkZ, array $subChunks = [], array $entities = [], array $tiles = [], string $biomeIds = "", array $heightMap = []){
|
||||
$this->provider = $provider;
|
||||
$this->x = $chunkX;
|
||||
$this->z = $chunkZ;
|
||||
@ -120,11 +120,11 @@ class GenericChunk implements Chunk{
|
||||
$this->heightMap = array_fill(0, 256, 0);
|
||||
}
|
||||
|
||||
if(count($biomeColors) === 256){
|
||||
$this->biomeColors = $biomeColors;
|
||||
if(strlen($biomeIds) === 256){
|
||||
$this->biomeIds = $biomeIds;
|
||||
}else{
|
||||
assert(count($biomeColors) === 0, "Wrong HeightMap value count, expected 256, got " . count($biomeColors));
|
||||
$this->biomeColors = array_fill(0, 256, 0);
|
||||
assert(strlen($biomeIds) === 0, "Wrong BiomeIds value count, expected 256, got " . strlen($biomeIds));
|
||||
$this->biomeIds = str_repeat("\x00", 256);
|
||||
}
|
||||
|
||||
$this->NBTtiles = $tiles;
|
||||
@ -293,23 +293,12 @@ class GenericChunk implements Chunk{
|
||||
}
|
||||
|
||||
public function getBiomeId(int $x, int $z) : int{
|
||||
return ($this->biomeColors[($z << 4) | $x] & 0xFF000000) >> 24;
|
||||
return ord($this->biomeIds{($z << 4) | $x});
|
||||
}
|
||||
|
||||
public function setBiomeId(int $x, int $z, int $biomeId){
|
||||
$this->hasChanged = true;
|
||||
$this->biomeColors[($z << 4) | $x] = ($this->biomeColors[($z << 4) | $x] & 0xFFFFFF) | ($biomeId << 24);
|
||||
}
|
||||
|
||||
public function getBiomeColor(int $x, int $z) : int{
|
||||
$color = $this->biomeColors[($z << 4) | $x] & 0xFFFFFF;
|
||||
|
||||
return [$color >> 16, ($color >> 8) & 0xFF, $color & 0xFF];
|
||||
}
|
||||
|
||||
public function setBiomeColor(int $x, int $z, int $R, int $G, int $B){
|
||||
$this->hasChanged = true;
|
||||
$this->biomeColors[($z << 4) | $x] = ($this->biomeColors[($z << 4) | $x] & 0xFF000000) | (($R & 0xFF) << 16) | (($G & 0xFF) << 8) | ($B & 0xFF);
|
||||
$this->biomeIds{($z << 4) | $x} = chr($biomeId & 0xff);
|
||||
}
|
||||
|
||||
public function getBlockIdColumn(int $x, int $z) : string{
|
||||
@ -511,15 +500,7 @@ class GenericChunk implements Chunk{
|
||||
}
|
||||
|
||||
public function getBiomeIdArray() : string{
|
||||
$ids = str_repeat("\x00", 256);
|
||||
foreach($this->biomeColors as $i => $d){
|
||||
$ids{$i} = chr(($d & 0xFF000000) >> 24);
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
public function getBiomeColorArray() : array{
|
||||
return $this->biomeColors;
|
||||
return $this->biomeIds;
|
||||
}
|
||||
|
||||
public function getHeightMapArray() : array{
|
||||
@ -635,7 +616,8 @@ class GenericChunk implements Chunk{
|
||||
for($y = 0; $y < $subChunkCount; ++$y){
|
||||
$result .= $this->subChunks[$y]->networkSerialize();
|
||||
}
|
||||
|
||||
$result .= pack("v*", ...$this->heightMap)
|
||||
. $this->biomeIds;
|
||||
//TODO: heightmaps, tile data
|
||||
return $result;
|
||||
}
|
||||
@ -656,7 +638,7 @@ class GenericChunk implements Chunk{
|
||||
$stream->putByte($count);
|
||||
$stream->put($subChunks);
|
||||
$stream->put(pack("C*", ...$chunk->getHeightMapArray()) .
|
||||
pack("N*", ...$chunk->getBiomeColorArray()) .
|
||||
$chunk->getBiomeIdArray() .
|
||||
chr(($chunk->lightPopulated ? 1 << 2 : 0) | ($chunk->terrainPopulated ? 1 << 1 : 0) | ($chunk->terrainGenerated ? 1 : 0)));
|
||||
//TODO: tiles and entities
|
||||
return $stream->getBuffer();
|
||||
@ -680,9 +662,9 @@ class GenericChunk implements Chunk{
|
||||
);
|
||||
}
|
||||
$heightMap = array_values(unpack("C*", $stream->get(256)));
|
||||
$biomeColors = array_values(unpack("N*", $stream->get(1024))); //TODO: remove this
|
||||
$biomeIds = $stream->get(256);
|
||||
|
||||
$chunk = new GenericChunk($provider, $x, $z, $subChunks, $heightMap, $biomeColors);
|
||||
$chunk = new GenericChunk($provider, $x, $z, $subChunks, [], [], $biomeIds, $heightMap);
|
||||
$flags = $stream->getByte();
|
||||
$chunk->lightPopulated = (bool) ($flags & 4);
|
||||
$chunk->terrainPopulated = (bool) ($flags & 2);
|
||||
@ -745,4 +727,12 @@ class GenericChunk implements Chunk{
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function convertBiomeColours(array $array) : string{
|
||||
$result = str_repeat("\x00", 256);
|
||||
foreach($array as $i => $colour){
|
||||
$result{$i} = chr(($array[$i] >> 24) & 0xff);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
@ -32,6 +32,7 @@ use pocketmine\nbt\NBT;
|
||||
use pocketmine\nbt\tag\{ByteArrayTag, ByteTag, CompoundTag, IntArrayTag, IntTag, ListTag, LongTag, StringTag};
|
||||
use pocketmine\Player;
|
||||
use pocketmine\utils\ChunkException;
|
||||
use pocketmine\utils\MainLogger;
|
||||
|
||||
class McRegion extends BaseLevelProvider{
|
||||
|
||||
@ -67,7 +68,7 @@ class McRegion extends BaseLevelProvider{
|
||||
$nbt->SkyLight = new ByteArrayTag("SkyLight", $skyLight);
|
||||
$nbt->BlockLight = new ByteArrayTag("BlockLight", $blockLight);
|
||||
|
||||
//$nbt->BiomeColors = new IntArrayTag("BiomeColors", $chunk->getBiomeColorArray());
|
||||
$nbt->Biomes = new ByteArrayTag("Biomes", $chunk->getBiomeIdArray());
|
||||
$nbt->HeightMap = new IntArrayTag("HeightMap", $chunk->getHeightMapArray());
|
||||
|
||||
$entities = [];
|
||||
@ -146,23 +147,31 @@ class McRegion extends BaseLevelProvider{
|
||||
}
|
||||
$subChunks[] = new SubChunk($y, $ids, $data, $blockLight, $skyLight);
|
||||
}
|
||||
|
||||
if(isset($chunk->BiomeColors)){
|
||||
$biomeIds = GenericChunk::convertBiomeColours($chunk->BiomeColors->getValue()); //Convert back to PC format (RIP colours D:)
|
||||
}elseif(isset($chunk->Biomes)){
|
||||
$biomeIds = $chunk->Biomes->getValue();
|
||||
}else{
|
||||
$biomeIds = "";
|
||||
}
|
||||
|
||||
$result = new GenericChunk(
|
||||
$provider,
|
||||
$chunk["xPos"],
|
||||
$chunk["zPos"],
|
||||
$subChunks,
|
||||
$chunk->Entities instanceof ListTag ? $chunk->Entities->getValue() : [],
|
||||
$chunk->TileEntities instanceof ListTag ? $chunk->TileEntities->getValue() : [],
|
||||
/*$chunk->BiomeColors instanceof IntArrayTag ? $chunk->BiomeColors->getValue() :*/ [],
|
||||
$chunk->HeightMap instanceof IntArrayTag ? $chunk->HeightMap->getValue() : []
|
||||
$chunk->Entities->getValue(),
|
||||
$chunk->TileEntities->getValue(),
|
||||
$biomeIds,
|
||||
$chunk->HeightMap->getValue()
|
||||
);
|
||||
$result->setLightPopulated($chunk->LightPopulated instanceof ByteTag ? ((bool) $chunk->LightPopulated->getValue()) : false);
|
||||
$result->setPopulated($chunk->TerrainPopulated instanceof ByteTag ? ((bool) $chunk->TerrainPopulated->getValue()) : false);
|
||||
$result->setLightPopulated(isset($chunk->LightPopulated) ? ((bool) $chunk->LightPopulated->getValue()) : false);
|
||||
$result->setPopulated(isset($chunk->TerrainPopulated) ? ((bool) $chunk->TerrainPopulated->getValue()) : false);
|
||||
$result->setGenerated(true);
|
||||
return $result;
|
||||
}catch(\Throwable $e){
|
||||
echo $e->getMessage();
|
||||
MainLogger::getLogger()->logException($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -111,15 +111,10 @@ class Flat extends Generator{
|
||||
|
||||
$this->chunk = clone $this->level->getChunk($chunkX, $chunkZ);
|
||||
$this->chunk->setGenerated();
|
||||
$c = Biome::getBiome($biome)->getColor();
|
||||
$R = $c >> 16;
|
||||
$G = ($c >> 8) & 0xff;
|
||||
$B = $c & 0xff;
|
||||
|
||||
for($Z = 0; $Z < 16; ++$Z){
|
||||
for($X = 0; $X < 16; ++$X){
|
||||
$this->chunk->setBiomeId($X, $Z, $biome);
|
||||
$this->chunk->setBiomeColor($X, $Z, $R, $G, $B);
|
||||
for($y = 0; $y < 128; ++$y){
|
||||
$this->chunk->setBlock($X, $y, $Z, ...$this->structure[$y]);
|
||||
}
|
||||
|
@ -75,12 +75,10 @@ abstract class Biome{
|
||||
|
||||
protected $rainfall = 0.5;
|
||||
protected $temperature = 0.5;
|
||||
protected $grassColor = 0;
|
||||
|
||||
protected static function register($id, Biome $biome){
|
||||
self::$biomes[(int) $id] = $biome;
|
||||
$biome->setId((int) $id);
|
||||
$biome->grassColor = self::generateBiomeColor($biome->getTemperature(), $biome->getRainfall());
|
||||
}
|
||||
|
||||
public static function init(){
|
||||
@ -175,30 +173,4 @@ abstract class Biome{
|
||||
public function getRainfall(){
|
||||
return $this->rainfall;
|
||||
}
|
||||
|
||||
private static function generateBiomeColor($temperature, $rainfall){
|
||||
$x = (1 - $temperature) * 255;
|
||||
$z = (1 - $rainfall * $temperature) * 255;
|
||||
$c = self::interpolateColor(256, $x, $z, [0x47, 0xd0, 0x33], [0x6c, 0xb4, 0x93], [0xbf, 0xb6, 0x55], [0x80, 0xb4, 0x97]);
|
||||
return ((int) ($c[0] << 16)) | (int) (($c[1] << 8)) | (int) ($c[2]);
|
||||
}
|
||||
|
||||
|
||||
private static function interpolateColor($size, $x, $z, $c1, $c2, $c3, $c4){
|
||||
$l1 = self::lerpColor($c1, $c2, $x / $size);
|
||||
$l2 = self::lerpColor($c3, $c4, $x / $size);
|
||||
|
||||
return self::lerpColor($l1, $l2, $z / $size);
|
||||
}
|
||||
|
||||
private static function lerpColor($a, $b, $s){
|
||||
$invs = 1 - $s;
|
||||
return [$a[0] * $invs + $b[0] * $s, $a[1] * $invs + $b[1] * $s, $a[2] * $invs + $b[2] * $s];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int (Red|Green|Blue)
|
||||
*/
|
||||
abstract public function getColor();
|
||||
}
|
@ -120,13 +120,6 @@ class Nether extends Generator{
|
||||
|
||||
$biome = Biome::getBiome(Biome::HELL);
|
||||
$chunk->setBiomeId($x, $z, $biome->getId());
|
||||
$color = [0, 0, 0];
|
||||
$bColor = $biome->getColor();
|
||||
$color[0] += (($bColor >> 16) ** 2);
|
||||
$color[1] += ((($bColor >> 8) & 0xff) ** 2);
|
||||
$color[2] += (($bColor & 0xff) ** 2);
|
||||
|
||||
$chunk->setBiomeColor($x, $z, $color[0], $color[1], $color[2]);
|
||||
|
||||
for($y = 0; $y < 128; ++$y){
|
||||
if($y === 0 or $y === 127){
|
||||
|
@ -201,7 +201,6 @@ class Normal extends Generator{
|
||||
|
||||
$biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z);
|
||||
$chunk->setBiomeId($x, $z, $biome->getId());
|
||||
$color = [0, 0, 0];
|
||||
|
||||
for($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++$sx){
|
||||
for($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++$sz){
|
||||
@ -221,10 +220,6 @@ class Normal extends Generator{
|
||||
|
||||
$minSum += ($adjacent->getMinElevation() - 1) * $weight;
|
||||
$maxSum += $adjacent->getMaxElevation() * $weight;
|
||||
$bColor = $adjacent->getColor();
|
||||
$color[0] += (($bColor >> 16) ** 2) * $weight;
|
||||
$color[1] += ((($bColor >> 8) & 0xff) ** 2) * $weight;
|
||||
$color[2] += (($bColor & 0xff) ** 2) * $weight;
|
||||
|
||||
$weightSum += $weight;
|
||||
}
|
||||
@ -233,8 +228,6 @@ class Normal extends Generator{
|
||||
$minSum /= $weightSum;
|
||||
$maxSum /= $weightSum;
|
||||
|
||||
$chunk->setBiomeColor($x, $z, sqrt($color[0] / $weightSum), sqrt($color[1] / $weightSum), sqrt($color[2] / $weightSum));
|
||||
|
||||
$smoothHeight = ($maxSum - $minSum) / 2;
|
||||
|
||||
for($y = 0; $y < 128; ++$y){
|
||||
|
Loading…
x
Reference in New Issue
Block a user