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