Fixed tiles not being sent with chunks

This commit is contained in:
Dylan K. Taylor 2021-11-30 22:19:28 +00:00
parent d5f81fe261
commit baeac2eb07
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 16 additions and 2 deletions

View File

@ -846,7 +846,7 @@ class Chunk{
/**
* Serializes the chunk for sending to players
*/
public function networkSerialize() : string{
public function networkSerialize(?string $networkSerializedTiles) : string{
$result = "";
$subChunkCount = $this->getSubChunkSendCount();
@ -866,6 +866,17 @@ class Chunk{
$result .= chr(0); //border block array count
//Border block entry format: 1 byte (4 bits X, 4 bits Z). These are however useless since they crash the regular client.
$result .= $networkSerializedTiles ?? $this->networkSerializeTiles();
return $result;
}
/**
* Serializes all tiles in network format for chunk sending. This is necessary because fastSerialize() doesn't
* include tiles; they have to be encoded on the main thread.
*/
public function networkSerializeTiles() : string{
$result = "";
foreach($this->tiles as $tile){
if($tile instanceof Spawnable){
$result .= $tile->getSerializedSpawnCompound();

View File

@ -39,6 +39,7 @@ class ChunkRequestTask extends AsyncTask{
/** @var string */
protected $chunk;
private string $tiles;
/** @var int */
protected $chunkX;
/** @var int */
@ -52,13 +53,15 @@ class ChunkRequestTask extends AsyncTask{
$this->compressionLevel = $level->getServer()->networkCompressionLevel;
$this->chunk = $chunk->fastSerialize();
$this->tiles = $chunk->networkSerializeTiles();
$this->chunkX = $chunkX;
$this->chunkZ = $chunkZ;
}
public function onRun(){
$chunk = Chunk::fastDeserialize($this->chunk);
$pk = LevelChunkPacket::withoutCache($this->chunkX, $this->chunkZ, $chunk->getSubChunkSendCount() + 4, $chunk->networkSerialize());
$pk = LevelChunkPacket::withoutCache($this->chunkX, $this->chunkZ, $chunk->getSubChunkSendCount() + 4, $chunk->networkSerialize($this->tiles));
$batch = new BatchPacket();
$batch->addPacket($pk);