mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 16:59:44 +00:00
SubChunk: remove BlockLegacyIds dependency, allow parameterising default block
This commit is contained in:
parent
4e2f430f06
commit
007aee72f8
@ -644,7 +644,7 @@ class Chunk{
|
||||
if($y < 0 or $y >= $this->height){
|
||||
return $this->emptySubChunk;
|
||||
}elseif($generateNew and $this->subChunks[$y] instanceof EmptySubChunk){
|
||||
$this->subChunks[$y] = new SubChunk([new PalettedBlockArray(BlockLegacyIds::AIR << 4)]);
|
||||
$this->subChunks[$y] = new SubChunk(BlockLegacyIds::AIR << 4, []);
|
||||
}
|
||||
|
||||
return $this->subChunks[$y];
|
||||
|
@ -23,10 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\format;
|
||||
|
||||
use pocketmine\block\BlockLegacyIds;
|
||||
use function array_values;
|
||||
|
||||
class SubChunk implements SubChunkInterface{
|
||||
/** @var int */
|
||||
private $defaultBlock;
|
||||
/** @var PalettedBlockArray[] */
|
||||
private $blockLayers;
|
||||
|
||||
@ -38,11 +39,13 @@ class SubChunk implements SubChunkInterface{
|
||||
/**
|
||||
* SubChunk constructor.
|
||||
*
|
||||
* @param int $default
|
||||
* @param PalettedBlockArray[] $blocks
|
||||
* @param LightArray|null $skyLight
|
||||
* @param LightArray|null $blockLight
|
||||
*/
|
||||
public function __construct(array $blocks, ?LightArray $skyLight = null, ?LightArray $blockLight = null){
|
||||
public function __construct(int $default, array $blocks, ?LightArray $skyLight = null, ?LightArray $blockLight = null){
|
||||
$this->defaultBlock = $default;
|
||||
$this->blockLayers = $blocks;
|
||||
|
||||
$this->skyLight = $skyLight ?? new LightArray(LightArray::FIFTEEN);
|
||||
@ -53,7 +56,7 @@ class SubChunk implements SubChunkInterface{
|
||||
foreach($this->blockLayers as $layer){
|
||||
$palette = $layer->getPalette();
|
||||
foreach($palette as $p){
|
||||
if($p !== (BlockLegacyIds::AIR << 4)){
|
||||
if($p !== $this->defaultBlock){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -68,14 +71,14 @@ class SubChunk implements SubChunkInterface{
|
||||
|
||||
public function getFullBlock(int $x, int $y, int $z) : int{
|
||||
if(empty($this->blockLayers)){
|
||||
return BlockLegacyIds::AIR << 4;
|
||||
return $this->defaultBlock;
|
||||
}
|
||||
return $this->blockLayers[0]->get($x, $y, $z);
|
||||
}
|
||||
|
||||
public function setFullBlock(int $x, int $y, int $z, int $block) : void{
|
||||
if(empty($this->blockLayers)){
|
||||
$this->blockLayers[] = new PalettedBlockArray(BlockLegacyIds::AIR << 4);
|
||||
$this->blockLayers[] = new PalettedBlockArray($this->defaultBlock);
|
||||
}
|
||||
$this->blockLayers[0]->set($x, $y, $z, $block);
|
||||
}
|
||||
@ -112,7 +115,7 @@ class SubChunk implements SubChunkInterface{
|
||||
return -1;
|
||||
}
|
||||
for($y = 15; $y >= 0; --$y){
|
||||
if($this->blockLayers[0]->get($x, $y, $z) !== (BlockLegacyIds::AIR << 4)){
|
||||
if($this->blockLayers[0]->get($x, $y, $z) !== $this->defaultBlock){
|
||||
return $y;
|
||||
}
|
||||
}
|
||||
@ -145,7 +148,7 @@ class SubChunk implements SubChunkInterface{
|
||||
$layer->collectGarbage();
|
||||
|
||||
foreach($layer->getPalette() as $p){
|
||||
if($p !== (BlockLegacyIds::AIR << 4)){
|
||||
if($p !== $this->defaultBlock){
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\format\io;
|
||||
|
||||
use pocketmine\block\BlockLegacyIds;
|
||||
use pocketmine\utils\BinaryStream;
|
||||
use pocketmine\world\format\Chunk;
|
||||
use pocketmine\world\format\EmptySubChunk;
|
||||
@ -135,7 +136,7 @@ final class FastChunkSerializer{
|
||||
$layers[] = PalettedBlockArray::fromData($bitsPerBlock, $words, $palette);
|
||||
}
|
||||
$subChunks[$y] = new SubChunk(
|
||||
$layers, $lightPopulated ? new LightArray($stream->get(2048)) : null, $lightPopulated ? new LightArray($stream->get(2048)) : null
|
||||
BlockLegacyIds::AIR << 4, $layers, $lightPopulated ? new LightArray($stream->get(2048)) : null, $lightPopulated ? new LightArray($stream->get(2048)) : null
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -303,14 +303,14 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
|
||||
$storages[] = $convertedLegacyExtraData[$y];
|
||||
}
|
||||
|
||||
$subChunks[$y] = new SubChunk($storages);
|
||||
$subChunks[$y] = new SubChunk(BlockLegacyIds::AIR << 4, $storages);
|
||||
break;
|
||||
case 1: //paletted v1, has a single blockstorage
|
||||
$storages = [$this->deserializePaletted($binaryStream)];
|
||||
if(isset($convertedLegacyExtraData[$y])){
|
||||
$storages[] = $convertedLegacyExtraData[$y];
|
||||
}
|
||||
$subChunks[$y] = new SubChunk($storages);
|
||||
$subChunks[$y] = new SubChunk(BlockLegacyIds::AIR << 4, $storages);
|
||||
break;
|
||||
case 8:
|
||||
//legacy extradata layers intentionally ignored because they aren't supposed to exist in v8
|
||||
@ -321,7 +321,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
|
||||
for($k = 0; $k < $storageCount; ++$k){
|
||||
$storages[] = $this->deserializePaletted($binaryStream);
|
||||
}
|
||||
$subChunks[$y] = new SubChunk($storages);
|
||||
$subChunks[$y] = new SubChunk(BlockLegacyIds::AIR << 4, $storages);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -365,7 +365,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
|
||||
if(isset($convertedLegacyExtraData[$yy])){
|
||||
$storages[] = $convertedLegacyExtraData[$yy];
|
||||
}
|
||||
$subChunks[$yy] = new SubChunk($storages);
|
||||
$subChunks[$yy] = new SubChunk(BlockLegacyIds::AIR << 4, $storages);
|
||||
}
|
||||
|
||||
try{
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\format\io\region;
|
||||
|
||||
use pocketmine\block\BlockLegacyIds;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\world\format\io\SubChunkConverter;
|
||||
use pocketmine\world\format\SubChunk;
|
||||
@ -35,7 +36,7 @@ class Anvil extends RegionWorldProvider{
|
||||
}
|
||||
|
||||
protected function deserializeSubChunk(CompoundTag $subChunk) : SubChunk{
|
||||
return new SubChunk([SubChunkConverter::convertSubChunkYZX($subChunk->getByteArray("Blocks"), $subChunk->getByteArray("Data"))]);
|
||||
return new SubChunk(BlockLegacyIds::AIR << 4, [SubChunkConverter::convertSubChunkYZX($subChunk->getByteArray("Blocks"), $subChunk->getByteArray("Data"))]);
|
||||
//ignore legacy light information
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\format\io\region;
|
||||
|
||||
use pocketmine\block\BlockLegacyIds;
|
||||
use pocketmine\nbt\BigEndianNbtSerializer;
|
||||
use pocketmine\nbt\NbtDataException;
|
||||
use pocketmine\nbt\tag\ByteArrayTag;
|
||||
@ -71,7 +72,7 @@ class McRegion extends RegionWorldProvider{
|
||||
$fullData = $chunk->hasTag("Data", ByteArrayTag::class) ? $chunk->getByteArray("Data") : str_repeat("\x00", 16384);
|
||||
|
||||
for($y = 0; $y < 8; ++$y){
|
||||
$subChunks[$y] = new SubChunk([SubChunkConverter::convertSubChunkFromLegacyColumn($fullIds, $fullData, $y)]);
|
||||
$subChunks[$y] = new SubChunk(BlockLegacyIds::AIR << 4, [SubChunkConverter::convertSubChunkFromLegacyColumn($fullIds, $fullData, $y)]);
|
||||
}
|
||||
|
||||
if($chunk->hasTag("BiomeColors", IntArrayTag::class)){
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\format\io\region;
|
||||
|
||||
use pocketmine\block\BlockLegacyIds;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\world\format\io\SubChunkConverter;
|
||||
use pocketmine\world\format\SubChunk;
|
||||
@ -35,7 +36,7 @@ class PMAnvil extends RegionWorldProvider{
|
||||
use LegacyAnvilChunkTrait;
|
||||
|
||||
protected function deserializeSubChunk(CompoundTag $subChunk) : SubChunk{
|
||||
return new SubChunk([SubChunkConverter::convertSubChunkXZY($subChunk->getByteArray("Blocks"), $subChunk->getByteArray("Data"))]);
|
||||
return new SubChunk(BlockLegacyIds::AIR << 4, [SubChunkConverter::convertSubChunkXZY($subChunk->getByteArray("Blocks"), $subChunk->getByteArray("Data"))]);
|
||||
}
|
||||
|
||||
protected static function getRegionFileExtension() : string{
|
||||
|
Loading…
x
Reference in New Issue
Block a user