42    private const TAG_LEGACY_ID = 
"id"; 
 
   44    public function __construct(
 
   62        if(($r12BlockId = $this->r12ItemIdToBlockIdMap->itemIdToBlockId($rawNameId)) !== null){
 
   64                $blockStateData = $this->blockDataUpgrader->upgradeStringIdMeta($r12BlockId, $meta);
 
   70            $blockStateData = 
null;
 
   73        [$newNameId, $newMeta] = $this->idMetaUpgrader->upgrade($rawNameId, $meta);
 
   78            new SavedItemData($newNameId, $newMeta, $blockStateData, $nbt),
 
 
   95        $rawNameId = $this->legacyIntToStringIdMap->legacyToString($legacyNumericId);
 
   96        if($rawNameId === 
null){
 
   99        return $this->upgradeItemTypeDataString($rawNameId, $meta, $count, $nbt);
 
 
  109            $rawNameId = $nameIdTag->getValue();
 
  110        }elseif(($idTag = $tag->
getTag(self::TAG_LEGACY_ID)) instanceof ShortTag){
 
  113            if($idTag->getValue() === 0){
 
  118            $rawNameId = $this->legacyIntToStringIdMap->legacyToString($idTag->getValue());
 
  119            if($rawNameId === 
null){
 
  122        }elseif($idTag instanceof StringTag){
 
  125            $rawNameId = $idTag->getValue();
 
  127            throw new SavedDataLoadingException(
"Item stack data should have either a name ID or a legacy ID");
 
  130        $meta = $tag->getShort(SavedItemData::TAG_DAMAGE, 0);
 
  133        if($blockStateNbt !== 
null){
 
  135                $blockStateData = $this->blockDataUpgrader->upgradeBlockStateNbt($blockStateNbt);
 
  136            }
catch(BlockStateDeserializeException $e){
 
  137                throw new SavedDataLoadingException(
"Failed to deserialize blockstate for blockitem: " . $e->getMessage(), 0, $e);
 
  139        }elseif(($r12BlockId = $this->r12ItemIdToBlockIdMap->itemIdToBlockId($rawNameId)) !== 
null){
 
  142                $blockStateData = $this->blockDataUpgrader->upgradeStringIdMeta($r12BlockId, $meta);
 
  143            }
catch(BlockStateDeserializeException $e){
 
  144                throw new SavedDataLoadingException(
"Failed to deserialize blockstate for legacy blockitem: " . $e->getMessage(), 0, $e);
 
  148            $blockStateData = 
null;
 
  151        [$newNameId, $newMeta] = $this->idMetaUpgrader->upgrade($rawNameId, $meta);
 
  154        if($blockStateData === 
null && ($blockId = $this->blockItemIdMap->lookupBlockId($newNameId)) !== 
null){
 
  155            $networkRuntimeId = $this->blockStateDictionary->lookupStateIdFromIdMeta($blockId, 0);
 
  157            if($networkRuntimeId === 
null){
 
  158                throw new SavedDataLoadingException(
"Failed to find blockstate for blockitem $newNameId");
 
  161            $blockStateData = $this->blockStateDictionary->generateDataFromStateId($networkRuntimeId);
 
  167        return new SavedItemData($newNameId, $newMeta, $blockStateData, $tag->
getCompoundTag(SavedItemData::TAG_TAG));
 
  174        $savedItemData = $this->upgradeItemTypeNbt($tag);
 
  175        if($savedItemData === 
null){
 
  181            $count = Binary::unsignByte($tag->getByte(SavedItemStackData::TAG_COUNT));
 
  184            $slot = ($slotTag = $tag->
getTag(SavedItemStackData::TAG_SLOT)) instanceof 
ByteTag ? Binary::unsignByte($slotTag->getValue()) : null;
 
  185            $wasPickedUp = ($wasPickedUpTag = $tag->
getTag(SavedItemStackData::TAG_WAS_PICKED_UP)) instanceof 
ByteTag ? $wasPickedUpTag->
getValue() : 
null;
 
  186            $canPlaceOnList = $tag->
getListTag(SavedItemStackData::TAG_CAN_PLACE_ON, StringTag::class);
 
  187            $canDestroyList = $tag->
getListTag(SavedItemStackData::TAG_CAN_DESTROY, StringTag::class);
 
  192        return new SavedItemStackData(
 
  197            $canPlaceOnList === 
null ? [] : array_map(fn(StringTag $t) => $t->getValue(), $canPlaceOnList->getValue()),
 
  198            $canDestroyList === 
null ? [] : array_map(fn(StringTag $t) => $t->getValue(), $canDestroyList->getValue())
 
 
  202    public function getIdMetaUpgrader() : ItemIdMetaUpgrader{ return $this->idMetaUpgrader; }