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){
|
if($idTag instanceof ShortTag){
|
||||||
$item = ItemFactory::getInstance()->get($idTag->getValue(), $meta, $count);
|
$item = ItemFactory::getInstance()->get($idTag->getValue(), $meta, $count);
|
||||||
}elseif($idTag instanceof StringTag){ //PC item save format
|
}elseif($idTag instanceof StringTag){ //PC item save format
|
||||||
try{
|
//TODO: this isn't a very good mapping source, we need a dedicated mapping for PC
|
||||||
$item = LegacyStringToItemParser::getInstance()->parse($idTag->getValue() . ":$meta");
|
$id = LegacyStringToItemParser::getInstance()->parseId($idTag->getValue());
|
||||||
}catch(\InvalidArgumentException $e){
|
if($id === null){
|
||||||
//TODO: improve error handling
|
|
||||||
return ItemFactory::air();
|
return ItemFactory::air();
|
||||||
}
|
}
|
||||||
$item->setCount($count);
|
$item = ItemFactory::getInstance()->get($id, $meta, $count);
|
||||||
}else{
|
}else{
|
||||||
throw new \InvalidArgumentException("Item CompoundTag ID must be an instance of StringTag or ShortTag, " . get_class($idTag) . " given");
|
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_numeric;
|
||||||
use function is_string;
|
use function is_string;
|
||||||
use function json_decode;
|
use function json_decode;
|
||||||
|
use function mb_strtolower;
|
||||||
use function str_replace;
|
use function str_replace;
|
||||||
use function strtolower;
|
use function strtolower;
|
||||||
use function trim;
|
use function trim;
|
||||||
@ -78,6 +79,10 @@ final class LegacyStringToItemParser{
|
|||||||
$this->map[$alias] = $id;
|
$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.
|
* Tries to parse the specified string into Item types.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user