mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
Revert "Item: skip a step when decoding PC itemstacks"
This reverts commit 9b52af62b6f469771f2355a964b35ecffa5117d9. We shouldn't assume that a string maps directly to a legacy ID, because we might want string aliases (e.g. dark_oak_boat) which refer to items that have a specific meta value in the MCPE system. Overall, I want to get rid of the reliance on IDs here and register all this stuff using closure callbacks on VanillaItems, so getting rid of this assumption also serves that goal.
This commit is contained in:
parent
2312511be6
commit
76a74b3931
@ -678,12 +678,13 @@ class Item implements \JsonSerializable{
|
||||
if($idTag instanceof ShortTag){
|
||||
$item = ItemFactory::getInstance()->get($idTag->getValue(), $meta, $count);
|
||||
}elseif($idTag instanceof StringTag){ //PC item save format
|
||||
//TODO: this isn't a very good mapping source, we need a dedicated mapping for PC
|
||||
$id = LegacyStringToItemParser::getInstance()->parseId($idTag->getValue());
|
||||
if($id === null){
|
||||
try{
|
||||
$item = LegacyStringToItemParser::getInstance()->parse($idTag->getValue() . ":$meta");
|
||||
}catch(\InvalidArgumentException $e){
|
||||
//TODO: improve error handling
|
||||
return ItemFactory::air();
|
||||
}
|
||||
$item = ItemFactory::getInstance()->get($id, $meta, $count);
|
||||
$item->setCount($count);
|
||||
}else{
|
||||
throw new \InvalidArgumentException("Item CompoundTag ID must be an instance of StringTag or ShortTag, " . get_class($idTag) . " given");
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ use function is_int;
|
||||
use function is_numeric;
|
||||
use function is_string;
|
||||
use function json_decode;
|
||||
use function mb_strtolower;
|
||||
use function str_replace;
|
||||
use function strtolower;
|
||||
use function trim;
|
||||
@ -80,10 +79,6 @@ final class LegacyStringToItemParser{
|
||||
$this->map[$alias] = $id;
|
||||
}
|
||||
|
||||
public function parseId(string $input) : ?int{
|
||||
return $this->map[mb_strtolower($this->reprocess($input))] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to parse the specified string into Item types.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user