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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine\world\format\io;
use pocketmine\data\bedrock\item\BlockItemIdMap;
use pocketmine\data\bedrock\item\ItemDeserializer;
use pocketmine\data\bedrock\item\ItemSerializer;
use pocketmine\data\bedrock\item\upgrade\ItemDataUpgrader;
@ -30,6 +31,7 @@ use pocketmine\data\bedrock\item\upgrade\ItemIdMetaUpgrader;
use pocketmine\data\bedrock\item\upgrade\ItemIdMetaUpgradeSchemaUtils;
use pocketmine\data\bedrock\item\upgrade\LegacyItemIdToStringIdMap;
use pocketmine\data\bedrock\item\upgrade\R12ItemIdToBlockIdMap;
use pocketmine\network\mcpe\convert\TypeConverter;
use Symfony\Component\Filesystem\Path;
use const PHP_INT_MAX;
use const pocketmine\BEDROCK_ITEM_UPGRADE_SCHEMA_PATH;
@ -54,7 +56,9 @@ final class GlobalItemDataHandlers{
new ItemIdMetaUpgrader(ItemIdMetaUpgradeSchemaUtils::loadSchemas(Path::join(BEDROCK_ITEM_UPGRADE_SCHEMA_PATH, 'id_meta_upgrade_schema'), PHP_INT_MAX)),
LegacyItemIdToStringIdMap::getInstance(),
R12ItemIdToBlockIdMap::getInstance(),
GlobalBlockStateHandlers::getUpgrader()
GlobalBlockStateHandlers::getUpgrader(),
BlockItemIdMap::getInstance(),
TypeConverter::getInstance()->getBlockTranslator()->getBlockStateDictionary()
);
}
}

View File

@ -51,12 +51,12 @@ use function time;
class BedrockWorldData extends BaseNbtWorldData{
public const CURRENT_STORAGE_VERSION = 10;
public const CURRENT_STORAGE_NETWORK_VERSION = 729;
public const CURRENT_STORAGE_NETWORK_VERSION = 748;
public const CURRENT_CLIENT_VERSION_TARGET = [
1, //major
21, //minor
30, //patch
3, //revision
40, //patch
1, //revision
0 //is beta
];

View File

@ -71,4 +71,5 @@ final class ChunkVersion{
public const v1_18_0_24_unused = 38;
public const v1_18_0_25_beta = 39;
public const v1_18_30 = 40;
public const v1_21_40 = 41;
}

View File

@ -78,7 +78,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
protected const ENTRY_FLAT_WORLD_LAYERS = "game_flatworldlayers";
protected const CURRENT_LEVEL_CHUNK_VERSION = ChunkVersion::v1_18_30;
protected const CURRENT_LEVEL_CHUNK_VERSION = ChunkVersion::v1_21_40;
protected const CURRENT_LEVEL_SUBCHUNK_VERSION = SubChunkVersion::PALETTED_MULTI;
private const CAVES_CLIFFS_EXPERIMENTAL_SUBCHUNK_KEY_OFFSET = 4;
@ -654,6 +654,8 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
$hasBeenUpgraded = $chunkVersion < self::CURRENT_LEVEL_CHUNK_VERSION;
switch($chunkVersion){
case ChunkVersion::v1_21_40:
//TODO: BiomeStates became shorts instead of bytes
case ChunkVersion::v1_18_30:
case ChunkVersion::v1_18_0_25_beta:
case ChunkVersion::v1_18_0_24_unused: