Remove biome colours and fix biome id arrays

This commit is contained in:
Dylan K. Taylor
2016-12-04 14:04:36 +00:00
parent 4d121f7d84
commit aafe0c4f69
9 changed files with 58 additions and 140 deletions

View File

@ -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[]
*/

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}