Separate block legacy data upgrading from block deserialization

this commit provides a central place where all block data can go to be upgraded to the latest version (currently 1.19), irrespective of how old it is.

Previously I had issues during debugging, because it wasn't possible to just upgrade a block without deserializing it into a Block object, which isn't currently supported for many blocks.
This commit solves that problem by separating the upgrading from the deserialization.
This commit is contained in:
Dylan K. Taylor
2022-06-23 16:45:02 +01:00
parent 301b0aba82
commit 1533fcf8f6
6 changed files with 38 additions and 96 deletions

View File

@ -56,11 +56,11 @@ abstract class BaseWorldProvider implements WorldProvider{
//TODO: this should be dependency-injected so it can be replaced, but that would break BC
//also, we want it to be lazy-loaded ...
$legacyBlockStateMapper = GlobalBlockStateHandlers::getLegacyBlockStateMapper();
$blockDataUpgrader = GlobalBlockStateHandlers::getUpgrader();
$blockStateDeserializer = GlobalBlockStateHandlers::getDeserializer();
$newPalette = [];
foreach($palette as $k => $legacyIdMeta){
$newStateData = $legacyBlockStateMapper->fromIntIdMeta($legacyIdMeta >> 4, $legacyIdMeta & 0xf);
$newStateData = $blockDataUpgrader->upgradeIntIdMeta($legacyIdMeta >> 4, $legacyIdMeta & 0xf);
if($newStateData === null){
//TODO: remember data for unknown states so we can implement them later
$newStateData = new BlockStateData(BlockTypeNames::INFO_UPDATE, CompoundTag::create(), BlockStateData::CURRENT_VERSION);