mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 07:39:57 +00:00
ChunkSerializer: support writing 0 bpb palettes on the wire
these are now supported as of 1.17.30.
This commit is contained in:
parent
eb80515e99
commit
8e2d06a880
@ -32,10 +32,8 @@ use pocketmine\network\mcpe\protocol\serializer\PacketSerializerContext;
|
|||||||
use pocketmine\utils\Binary;
|
use pocketmine\utils\Binary;
|
||||||
use pocketmine\utils\BinaryStream;
|
use pocketmine\utils\BinaryStream;
|
||||||
use pocketmine\world\format\Chunk;
|
use pocketmine\world\format\Chunk;
|
||||||
use pocketmine\world\format\PalettedBlockArray;
|
|
||||||
use pocketmine\world\format\SubChunk;
|
use pocketmine\world\format\SubChunk;
|
||||||
use function count;
|
use function count;
|
||||||
use function str_repeat;
|
|
||||||
|
|
||||||
final class ChunkSerializer{
|
final class ChunkSerializer{
|
||||||
|
|
||||||
@ -83,23 +81,18 @@ final class ChunkSerializer{
|
|||||||
$stream->putByte(count($layers));
|
$stream->putByte(count($layers));
|
||||||
|
|
||||||
foreach($layers as $blocks){
|
foreach($layers as $blocks){
|
||||||
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();
|
$bitsPerBlock = $blocks->getBitsPerBlock();
|
||||||
$words = $blocks->getWordArray();
|
$words = $blocks->getWordArray();
|
||||||
}
|
|
||||||
$stream->putByte(($bitsPerBlock << 1) | ($persistentBlockStates ? 0 : 1));
|
$stream->putByte(($bitsPerBlock << 1) | ($persistentBlockStates ? 0 : 1));
|
||||||
$stream->put($words);
|
$stream->put($words);
|
||||||
$palette = $blocks->getPalette();
|
$palette = $blocks->getPalette();
|
||||||
|
|
||||||
|
if($bitsPerBlock !== 0){
|
||||||
//these LSHIFT by 1 uvarints are optimizations: the client expects zigzag varints here
|
//these LSHIFT by 1 uvarints are optimizations: the client expects zigzag varints here
|
||||||
//but since we know they are always unsigned, we can avoid the extra fcall overhead of
|
//but since we know they are always unsigned, we can avoid the extra fcall overhead of
|
||||||
//zigzag and just shift directly.
|
//zigzag and just shift directly.
|
||||||
$stream->putUnsignedVarInt(count($palette) << 1); //yes, this is intentionally zigzag
|
$stream->putUnsignedVarInt(count($palette) << 1); //yes, this is intentionally zigzag
|
||||||
|
}
|
||||||
if($persistentBlockStates){
|
if($persistentBlockStates){
|
||||||
$nbtSerializer = new NetworkNbtSerializer();
|
$nbtSerializer = new NetworkNbtSerializer();
|
||||||
foreach($palette as $p){
|
foreach($palette as $p){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user