World: do not apply fake state properties from tile if the block doesn't expect this tile type

This was causing a variety of crashes due to incorrect tiles, presumably from PM3 worlds.
This commit is contained in:
Dylan K. Taylor 2023-10-20 10:28:46 +01:00
parent 7dd3a70d2e
commit 8fa5c7cdab
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -1102,19 +1102,22 @@ class World implements ChunkManager{
$blockPosition = BlockPosition::fromVector3($b);
$tile = $this->getTileAt($b->x, $b->y, $b->z);
if($tile instanceof Spawnable && count($fakeStateProperties = $tile->getRenderUpdateBugWorkaroundStateProperties($fullBlock)) > 0){
$originalStateData = $blockTranslator->internalIdToNetworkStateData($fullBlock->getStateId());
$fakeStateData = new BlockStateData(
$originalStateData->getName(),
array_merge($originalStateData->getStates(), $fakeStateProperties),
$originalStateData->getVersion()
);
$packets[] = UpdateBlockPacket::create(
$blockPosition,
$blockTranslator->getBlockStateDictionary()->lookupStateIdFromData($fakeStateData) ?? throw new AssumptionFailedError("Unmapped fake blockstate data: " . $fakeStateData->toNbt()),
UpdateBlockPacket::FLAG_NETWORK,
UpdateBlockPacket::DATA_LAYER_NORMAL
);
if($tile instanceof Spawnable){
$expectedClass = $fullBlock->getIdInfo()->getTileClass();
if($expectedClass !== null && $tile instanceof $expectedClass && count($fakeStateProperties = $tile->getRenderUpdateBugWorkaroundStateProperties($fullBlock)) > 0){
$originalStateData = $blockTranslator->internalIdToNetworkStateData($fullBlock->getStateId());
$fakeStateData = new BlockStateData(
$originalStateData->getName(),
array_merge($originalStateData->getStates(), $fakeStateProperties),
$originalStateData->getVersion()
);
$packets[] = UpdateBlockPacket::create(
$blockPosition,
$blockTranslator->getBlockStateDictionary()->lookupStateIdFromData($fakeStateData) ?? throw new AssumptionFailedError("Unmapped fake blockstate data: " . $fakeStateData->toNbt()),
UpdateBlockPacket::FLAG_NETWORK,
UpdateBlockPacket::DATA_LAYER_NORMAL
);
}
}
$packets[] = UpdateBlockPacket::create(
$blockPosition,