Documentation

LegacyStringToItemParser
in package
Uses SingletonTrait

Tags
deprecated
see
StringToItemParser

This class replaces the functionality that used to be provided by ItemFactory::fromString(), but in a more dynamic way. Avoid using this wherever possible. Unless you need to parse item strings containing meta (e.g. "dye:4", "351:4") or item IDs (e.g. "351"), you should prefer the newer StringToItemParser, which is much more user-friendly, more flexible, and also supports registering custom aliases for any item in any state.

Table of Contents

$instance  : self|null
$itemFactory  : ItemFactory
$map  : array<string|int, int>
__construct()  : mixed
addMapping()  : void
getInstance()  : self
getMappings()  : array<string|int, int>
parse()  : Item
Tries to parse the specified string into Item types.
reset()  : void
setInstance()  : void
reprocess()  : string
make()  : self

Properties

Methods

addMapping()

public addMapping(string $alias, int $id) : void
Parameters
$alias : string
$id : int
Return values
void

getInstance()

public static getInstance() : self
Return values
self

getMappings()

public getMappings() : array<string|int, int>
Tags
phpstan-return

array<string, int>

Return values
array<string|int, int>

parse()

Tries to parse the specified string into Item types.

public parse(string $input) : Item

Example accepted formats:

  • diamond_pickaxe:5
  • minecraft:string
  • 351:4 (lapis lazuli ID:meta)
Parameters
$input : string
Tags
throws
LegacyStringToItemParserException

if the given string cannot be parsed as an item identifier

Return values
Item

setInstance()

public static setInstance(self $instance) : void
Parameters
$instance : self
Return values
void

reprocess()

protected reprocess(string $input) : string
Parameters
$input : string
Return values
string

Search results