mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
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:
@ -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{
|
||||
|
@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user