Skip to content

Commit

Permalink
Temporary resolve loading old skulls from storage (pmmp#6476)
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c authored Oct 27, 2024
1 parent e7d8d99 commit 8ef5e73
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/data/bedrock/item/upgrade/ItemDataUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

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;
Expand All @@ -35,6 +36,7 @@
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;

Expand All @@ -46,6 +48,8 @@ public function __construct(
private LegacyItemIdToStringIdMap $legacyIntToStringIdMap,
private R12ItemIdToBlockIdMap $r12ItemIdToBlockIdMap,
private BlockDataUpgrader $blockDataUpgrader,
private BlockItemIdMap $blockItemIdMap,
private BlockStateDictionary $blockStateDictionary
){}

/**
Expand Down Expand Up @@ -148,6 +152,17 @@ private function upgradeItemTypeNbt(CompoundTag $tag) : ?SavedItemData{

[$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

Expand Down
6 changes: 5 additions & 1 deletion src/world/format/io/GlobalItemDataHandlers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@

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;
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;
Expand All @@ -54,7 +56,9 @@ public static function getUpgrader() : ItemDataUpgrader{
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()
);
}
}
6 changes: 3 additions & 3 deletions src/world/format/io/data/BedrockWorldData.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
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
];

Expand Down
1 change: 1 addition & 0 deletions src/world/format/io/leveldb/ChunkVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ private function __construct(){
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;
}
4 changes: 3 additions & 1 deletion src/world/format/io/leveldb/LevelDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -654,6 +654,8 @@ public function loadChunk(int $chunkX, int $chunkZ) : ?LoadedChunkData{
$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:
Expand Down

0 comments on commit 8ef5e73

Please sign in to comment.