72 $itemData = $this->itemSerializer->serializeType($item);
74 $numericId = $this->itemTypeDictionary->fromStringId($itemData->getName());
75 $blockStateData = $itemData->getBlock();
77 if($blockStateData !==
null){
78 $blockRuntimeId = $this->blockStateDictionary->lookupStateIdFromData($blockStateData);
79 if($blockRuntimeId === null){
80 throw new AssumptionFailedError(
"Unmapped blockstate returned by blockstate serializer: " . $blockStateData->toNbt());
83 $blockRuntimeId =
null;
86 return [$numericId, $itemData->getMeta(), $blockRuntimeId];
102 public function fromNetworkId(
int $networkId,
int $networkMeta,
int $networkBlockRuntimeId) :
Item{
104 $stringId = $this->itemTypeDictionary->fromIntId($networkId);
105 }
catch(\InvalidArgumentException $e){
107 throw TypeConversionException::wrap($e,
"Invalid network itemstack ID $networkId");
110 $blockStateData =
null;
111 if($this->blockItemIdMap->lookupBlockId($stringId) !==
null){
112 $blockStateData = $this->blockStateDictionary->generateDataFromStateId($networkBlockRuntimeId);
113 if($blockStateData === null){
114 throw new TypeConversionException(
"Blockstate runtimeID $networkBlockRuntimeId does not correspond to any known blockstate");
116 }elseif($networkBlockRuntimeId !== self::NO_BLOCK_RUNTIME_ID){
117 throw new TypeConversionException(
"Item $stringId is not a blockitem, but runtime ID $networkBlockRuntimeId was provided");
121 return $this->itemDeserializer->deserializeType(
new SavedItemData($stringId, $networkMeta, $blockStateData));
122 }
catch(ItemTypeDeserializeException $e){
123 throw TypeConversionException::wrap($e,
"Invalid network itemstack data");