Expand height range to include -64 to 320

This commit is contained in:
Dylan K. Taylor 2022-04-15 19:10:24 +01:00
parent c1c3475e5a
commit eafbc3a468
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
5 changed files with 7 additions and 34 deletions

View File

@ -69,7 +69,7 @@ class ChunkRequestTask extends AsyncTask{
public function onRun() : void{
$chunk = FastChunkSerializer::deserializeTerrain($this->chunk);
$subCount = ChunkSerializer::getSubChunkCount($chunk) + ChunkSerializer::LOWER_PADDING_SIZE;
$subCount = ChunkSerializer::getSubChunkCount($chunk);
$encoderContext = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary());
$payload = ChunkSerializer::serializeFullChunk($chunk, RuntimeBlockMapping::getInstance(), $encoderContext, $this->tiles);
$this->setResult($this->compressor->compress(PacketBatch::fromPackets($encoderContext, LevelChunkPacket::create($this->chunkX, $this->chunkZ, $subCount, false, null, $payload))->getBuffer()));

View File

@ -41,8 +41,6 @@ use function count;
use function str_repeat;
final class ChunkSerializer{
public const LOWER_PADDING_SIZE = 4;
private function __construct(){
//NOOP
}
@ -65,12 +63,6 @@ final class ChunkSerializer{
public static function serializeFullChunk(Chunk $chunk, RuntimeBlockMapping $blockMapper, PacketSerializerContext $encoderContext, ?string $tiles = null) : string{
$stream = PacketSerializer::encoder($encoderContext);
//TODO: HACK! fill in fake subchunks to make up for the new negative space client-side
for($y = 0; $y < self::LOWER_PADDING_SIZE; $y++){
$stream->putByte(8); //subchunk version 8
$stream->putByte(0); //0 layers - client will treat this as all-air
}
$subChunkCount = self::getSubChunkCount($chunk);
for($y = Chunk::MIN_SUBCHUNK_INDEX, $writtenCount = 0; $writtenCount < $subChunkCount; ++$y, ++$writtenCount){
self::serializeSubChunk($chunk->getSubChunk($y), $blockMapper, $stream, false);

View File

@ -134,8 +134,8 @@ class World implements ChunkManager{
/** @var int */
private static $worldIdCounter = 1;
public const Y_MAX = 256;
public const Y_MIN = 0;
public const Y_MAX = 320;
public const Y_MIN = -64;
public const TIME_DAY = 1000;
public const TIME_NOON = 6000;

View File

@ -35,8 +35,8 @@ class Chunk{
public const DIRTY_FLAG_BLOCKS = 1 << 0;
public const DIRTY_FLAG_BIOMES = 1 << 3;
public const MIN_SUBCHUNK_INDEX = 0;
public const MAX_SUBCHUNK_INDEX = 15;
public const MIN_SUBCHUNK_INDEX = -4;
public const MAX_SUBCHUNK_INDEX = 19;
public const MAX_SUBCHUNKS = self::MAX_SUBCHUNK_INDEX - self::MIN_SUBCHUNK_INDEX + 1;
public const EDGE_LENGTH = SubChunk::EDGE_LENGTH;

View File

@ -123,11 +123,11 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
}
public function getWorldMinY() : int{
return 0;
return -64;
}
public function getWorldMaxY() : int{
return 256;
return 320;
}
public static function isValid(string $path) : bool{
@ -514,25 +514,6 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
$chunk = $chunkData->getChunk();
//TODO: This ensures that negative subchunks don't get destroyed in newer worlds for as long as we don't yet
//support negative height. Since we don't save with a shift, if the old save had the subchunks shifted, we need
//to shift them to their correct positions to avoid destroying data.
//This can be removed once we support the full height.
if($previousVersion !== null && self::hasOffsetCavesAndCliffsSubChunks($previousVersion)){
$subChunks = $chunk->getSubChunks();
for($y = -4; $y <= 20; $y++){
$key = $index . ChunkDataKey::SUBCHUNK . chr($y + self::CAVES_CLIFFS_EXPERIMENTAL_SUBCHUNK_KEY_OFFSET);
if(
(!isset($subChunks[$y]) || !$chunk->getTerrainDirtyFlag(Chunk::DIRTY_FLAG_BLOCKS)) &&
($subChunkData = $this->db->get($key)) !== false
){
$write->delete($key);
$write->put($index . ChunkDataKey::SUBCHUNK . chr($y & 0xff), $subChunkData);
}
}
}
if($chunk->getTerrainDirtyFlag(Chunk::DIRTY_FLAG_BLOCKS)){
$subChunks = $chunk->getSubChunks();