Burn meta wildcards from Item, allow more dynamic recipe inputs

this was an obstacle for getting rid of legacy item IDs.
This commit is contained in:
Dylan K. Taylor
2022-06-27 13:33:26 +01:00
parent bc5a600d59
commit 55cb68e5b5
20 changed files with 473 additions and 127 deletions

View File

@ -72,9 +72,6 @@ final class ItemSerializer{
* @phpstan-param \Closure(TItemType) : Data $serializer
*/
public function map(Item $item, \Closure $serializer) : void{
if($item->hasAnyDamageValue()){
throw new \InvalidArgumentException("Cannot serialize a recipe wildcard");
}
$index = $item->getTypeId();
if(isset($this->itemSerializers[$index])){
//TODO: REMOVE ME
@ -106,9 +103,6 @@ final class ItemSerializer{
if($item->isNull()){
throw new \InvalidArgumentException("Cannot serialize a null itemstack");
}
if($item->hasAnyDamageValue()){
throw new \InvalidArgumentException("Cannot serialize a recipe input as a saved itemstack");
}
if($item instanceof ItemBlock){
$data = $this->serializeBlockItem($item->getBlock());
}else{

View File

@ -70,6 +70,47 @@ final class ItemDataUpgrader{
ksort($this->idMetaUpgradeSchemas, SORT_NUMERIC);
}
/**
* This function replaces the legacy ItemFactory::get().
*
* Unlike ItemFactory::get(), it returns a SavedItemStackData which you can do with as you please.
* If you want to deserialize it into a PocketMine-MP itemstack, pass it to the ItemDeserializer.
*
* @see ItemDataUpgrader::upgradeItemTypeDataInt()
*/
public function upgradeItemTypeDataString(string $rawNameId, int $meta, int $count, ?CompoundTag $nbt) : SavedItemStackData{
if(($r12BlockId = $this->r12ItemIdToBlockIdMap->itemIdToBlockId($rawNameId)) !== null){
$blockStateData = $this->blockDataUpgrader->upgradeStringIdMeta($r12BlockId, $meta);
}else{
//probably a standard item
$blockStateData = null;
}
[$newNameId, $newMeta] = $this->upgradeItemStringIdMeta($rawNameId, $meta);
//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?
return new SavedItemStackData(
new SavedItemData($newNameId, $newMeta, $blockStateData, $nbt),
$count,
null,
null,
[],
[]
);
}
/**
* This function replaces the legacy ItemFactory::get().
*/
public function upgradeItemTypeDataInt(int $legacyNumericId, int $meta, int $count, ?CompoundTag $nbt) : SavedItemStackData{
$rawNameId = $this->legacyIntToStringIdMap->legacyToString($legacyNumericId);
if($rawNameId === null){
throw new SavedDataLoadingException("Unmapped legacy item ID $legacyNumericId");
}
return $this->upgradeItemTypeDataString($rawNameId, $meta, $count, $nbt);
}
/**
* @throws SavedDataLoadingException
*/