Temporary resolve loading old skulls from storage (#6476)

This commit is contained in:
Dries C
2024-10-27 02:29:34 +02:00
committed by GitHub
parent e7d8d99ca6
commit 8ef5e737de
5 changed files with 27 additions and 5 deletions

View File

@ -25,6 +25,7 @@ namespace pocketmine\data\bedrock\item\upgrade;
use pocketmine\data\bedrock\block\BlockStateDeserializeException;
use pocketmine\data\bedrock\block\upgrade\BlockDataUpgrader;
use pocketmine\data\bedrock\item\BlockItemIdMap;
use pocketmine\data\bedrock\item\SavedItemData;
use pocketmine\data\bedrock\item\SavedItemStackData;
use pocketmine\data\SavedDataLoadingException;
@ -35,6 +36,7 @@ use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\convert\BlockStateDictionary;
use pocketmine\utils\Binary;
use function assert;
@ -46,6 +48,8 @@ final class ItemDataUpgrader{
private LegacyItemIdToStringIdMap $legacyIntToStringIdMap,
private R12ItemIdToBlockIdMap $r12ItemIdToBlockIdMap,
private BlockDataUpgrader $blockDataUpgrader,
private BlockItemIdMap $blockItemIdMap,
private BlockStateDictionary $blockStateDictionary
){}
/**
@ -148,6 +152,17 @@ final class ItemDataUpgrader{
[$newNameId, $newMeta] = $this->idMetaUpgrader->upgrade($rawNameId, $meta);
//TODO: Dirty hack to load old skulls from disk: Put this into item upgrade schema's before Mojang makes something with a non 0 default state
if($blockStateData === null && ($blockId = $this->blockItemIdMap->lookupBlockId($newNameId)) !== null){
$networkRuntimeId = $this->blockStateDictionary->lookupStateIdFromIdMeta($blockId, 0);
if($networkRuntimeId === null){
throw new SavedDataLoadingException("Failed to find blockstate for blockitem $newNameId");
}
$blockStateData = $this->blockStateDictionary->generateDataFromStateId($networkRuntimeId);
}
//TODO: this won't account for spawn eggs from before 1.16.100 - perhaps we're lucky and they just left the meta in there anyway?
//TODO: read version from VersionInfo::TAG_WORLD_DATA_VERSION - we may need it to fix up old items