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

@ -46,11 +46,13 @@ class FlowerPot extends Spawnable{
public function readSaveData(CompoundTag $nbt) : void{
$blockStateData = null;
$blockDataUpgrader = GlobalBlockStateHandlers::getUpgrader();
if(($itemIdTag = $nbt->getTag(self::TAG_ITEM)) instanceof ShortTag && ($itemMetaTag = $nbt->getTag(self::TAG_ITEM_DATA)) instanceof IntTag){
$blockStateData = GlobalBlockStateHandlers::getLegacyBlockStateMapper()->fromIntIdMeta($itemIdTag->getValue(), $itemMetaTag->getValue());
$blockStateData = $blockDataUpgrader->upgradeIntIdMeta($itemIdTag->getValue(), $itemMetaTag->getValue());
}elseif(($plantBlockTag = $nbt->getCompoundTag(self::TAG_PLANT_BLOCK)) !== null){
try{
$blockStateData = GlobalBlockStateHandlers::nbtToBlockStateData($plantBlockTag);
$blockStateData = $blockDataUpgrader->upgradeBlockStateNbt($plantBlockTag);
}catch(BlockStateDeserializeException $e){
throw new SavedDataLoadingException("Error loading " . self::TAG_PLANT_BLOCK . " tag for flower pot: " . $e->getMessage(), 0, $e);
}