mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Workaround items in blockentity NBT not being processed correctly in 1.19.10
closes #5154 this hack sends only the bare essential data to create the tiles in LevelChunkPacket, and then separately sending the full tile data using BlockActorDataPacket afterwards. This is necessary because the client doesn't handle items correctly in NBT when chunks are sent without using the SubChunkRequest system. In 4.6 this is observed with incorrect items shown in item frames; in 5.0 it's seen with items simply not showing up at all (difference due to modernization of the serialization format in 5.0).
This commit is contained in:
@ -24,8 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\network\mcpe\serializer;
|
||||
|
||||
use pocketmine\block\tile\Spawnable;
|
||||
use pocketmine\block\tile\Tile;
|
||||
use pocketmine\block\tile\TileFactory;
|
||||
use pocketmine\data\bedrock\BiomeIds;
|
||||
use pocketmine\data\bedrock\LegacyBiomeIdToStringIdMap;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\TreeRoot;
|
||||
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
|
||||
use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer;
|
||||
@ -38,6 +41,7 @@ use pocketmine\world\format\PalettedBlockArray;
|
||||
use pocketmine\world\format\SubChunk;
|
||||
use function chr;
|
||||
use function count;
|
||||
use function get_class;
|
||||
use function str_repeat;
|
||||
|
||||
final class ChunkSerializer{
|
||||
@ -125,9 +129,19 @@ final class ChunkSerializer{
|
||||
|
||||
public static function serializeTiles(Chunk $chunk) : string{
|
||||
$stream = new BinaryStream();
|
||||
$nbtSerializer = new NetworkNbtSerializer();
|
||||
foreach($chunk->getTiles() as $tile){
|
||||
if($tile instanceof Spawnable){
|
||||
$stream->put($tile->getSerializedSpawnCompound()->getEncodedNbt());
|
||||
//TODO: HACK! we send only the bare essentials to create a tile in the chunk itself, due to a bug in
|
||||
//1.19.10 which causes items in tiles (item frames, lecterns) to not load properly when they are sent in
|
||||
//a chunk via the classic chunk sending mechanism. We workaround this bug by sendingBlockActorDataPacket
|
||||
//in NetworkSession to set the actual tile properties after sending the LevelChunkPacket.
|
||||
$nbt = CompoundTag::create()
|
||||
->setString(Tile::TAG_ID, TileFactory::getInstance()->getSaveId(get_class($tile)))
|
||||
->setInt(Tile::TAG_X, $tile->getPosition()->getFloorX())
|
||||
->setInt(Tile::TAG_Y, $tile->getPosition()->getFloorY())
|
||||
->setInt(Tile::TAG_Z, $tile->getPosition()->getFloorZ());
|
||||
$stream->put($nbtSerializer->write(new TreeRoot($nbt)));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user