Require ext-chunkutils ^0.3.0

This commit is contained in:
Dylan K. Taylor
2021-09-07 22:53:50 +01:00
parent c605b54591
commit 11d2e1ef08
5 changed files with 26 additions and 8 deletions

View File

@ -32,8 +32,10 @@ use pocketmine\network\mcpe\protocol\serializer\PacketSerializerContext;
use pocketmine\utils\Binary;
use pocketmine\utils\BinaryStream;
use pocketmine\world\format\Chunk;
use pocketmine\world\format\PalettedBlockArray;
use pocketmine\world\format\SubChunk;
use function count;
use function str_repeat;
final class ChunkSerializer{
@ -81,8 +83,17 @@ final class ChunkSerializer{
$stream->putByte(count($layers));
foreach($layers as $blocks){
$stream->putByte(($blocks->getBitsPerBlock() << 1) | ($persistentBlockStates ? 0 : 1));
$stream->put($blocks->getWordArray());
if($blocks->getBitsPerBlock() === 0){
//TODO: we use these in memory, but the game doesn't support them yet
//polyfill them with 1-bpb instead
$bitsPerBlock = 1;
$words = str_repeat("\x00", PalettedBlockArray::getExpectedWordArraySize(1));
}else{
$bitsPerBlock = $blocks->getBitsPerBlock();
$words = $blocks->getWordArray();
}
$stream->putByte(($bitsPerBlock << 1) | ($persistentBlockStates ? 0 : 1));
$stream->put($words);
$palette = $blocks->getPalette();
//these LSHIFT by 1 uvarints are optimizations: the client expects zigzag varints here