From 8fa5c7cdab4ae09b2259ea062938593d871574a7 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Oct 2023 10:28:46 +0100 Subject: [PATCH] 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. --- src/world/World.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/world/World.php b/src/world/World.php index 903cc60e2b1..8265aa38418 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -1102,19 +1102,22 @@ public function createBlockUpdatePackets(array $blocks) : array{ $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,