mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-26 05:14:05 +00:00
Item: skip a step when decoding PC itemstacks
This commit is contained in:
parent
279abb871d
commit
9b52af62b6
@ -658,13 +658,12 @@ class Item implements \JsonSerializable{
|
||||
if($idTag instanceof ShortTag){
|
||||
$item = ItemFactory::getInstance()->get($idTag->getValue(), $meta, $count);
|
||||
}elseif($idTag instanceof StringTag){ //PC item save format
|
||||
try{
|
||||
$item = LegacyStringToItemParser::getInstance()->parse($idTag->getValue() . ":$meta");
|
||||
}catch(\InvalidArgumentException $e){
|
||||
//TODO: improve error handling
|
||||
//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){
|
||||
return ItemFactory::air();
|
||||
}
|
||||
$item->setCount($count);
|
||||
$item = ItemFactory::getInstance()->get($id, $meta, $count);
|
||||
}else{
|
||||
throw new \InvalidArgumentException("Item CompoundTag ID must be an instance of StringTag or ShortTag, " . get_class($idTag) . " given");
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ 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;
|
||||
@ -78,6 +79,10 @@ 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