22declare(strict_types=1);
31use pocketmine\utils\SingletonTrait;
33use Symfony\Component\Filesystem\Path;
36use
function is_numeric;
37use
function is_string;
38use
function json_decode;
39use
function str_replace;
40use
function strtolower;
59 private static function make() :
self{
61 GlobalItemDataHandlers::getUpgrader(),
62 GlobalItemDataHandlers::getDeserializer()
67 $mappings = json_decode($mappingsRaw,
true);
70 foreach($mappings as $name => $id){
71 if(!is_string($id))
throw new AssumptionFailedError(
"Invalid mappings format, expected string values");
72 $result->addMapping((
string) $name, $id);
82 private array $map = [];
84 public function __construct(
89 public function addMapping(
string $alias,
string $id) :
void{
90 $this->map[$alias] = $id;
112 $key = $this->reprocess($input);
113 $b = explode(
":", $key);
117 }elseif(is_numeric($b[1])){
120 throw new LegacyStringToItemParserException(
"Unable to parse \"" . $b[1] .
"\" from \"" . $input .
"\" as a valid meta value");
123 $lower = strtolower($b[0]);
124 if($lower ===
"0" || $lower ===
"air"){
126 return VanillaItems::AIR();
129 $legacyId = $this->map[$lower] ??
null;
130 if($legacyId ===
null){
131 throw new LegacyStringToItemParserException(
"Unable to resolve \"" . $input .
"\" to a valid item");
133 $itemData = $this->itemDataUpgrader->upgradeItemTypeDataString($legacyId, $meta, 1,
null);
136 return $this->itemDeserializer->deserializeStack($itemData);
137 }
catch(ItemTypeDeserializeException $e){
138 throw new LegacyStringToItemParserException($e->getMessage(), 0, $e);
142 protected function reprocess(
string $input) : string{
143 return str_replace([
" ",
"minecraft:"], [
"_",
""], trim($input));
static fileGetContents(string $fileName, bool $useIncludePath=false, $context=null, int $offset=0, ?int $length=null)