mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-11 16:29:40 +00:00
ItemFactory: Get rid of $multiple crap
this is required in a specialized format, which doesn't make any sense. Plugins with multiple packed item formats should parse them themselves.
This commit is contained in:
parent
cf20f0e23a
commit
f64cef7eb6
@ -93,17 +93,17 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to parse the specified string into Item ID/meta identifiers, and returns Item instances it created.
|
* Tries to parse the specified string into Item types.
|
||||||
*
|
*
|
||||||
* This function redirects to {@link ItemFactory#fromString}.
|
* This function redirects to {@link ItemFactory#fromString}.
|
||||||
*
|
*
|
||||||
* @param string $str
|
* @param string $str
|
||||||
* @param bool $multiple
|
|
||||||
*
|
*
|
||||||
* @return Item[]|Item
|
* @return Item
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public static function fromString(string $str, bool $multiple = false){
|
public static function fromString(string $str) : Item{
|
||||||
return ItemFactory::fromString($str, $multiple);
|
return ItemFactory::fromString($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -360,32 +360,20 @@ class ItemFactory{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to parse the specified string into Item ID/meta identifiers, and returns Item instances it created.
|
* Tries to parse the specified string into Item types.
|
||||||
*
|
*
|
||||||
* Example accepted formats:
|
* Example accepted formats:
|
||||||
* - `diamond_pickaxe:5`
|
* - `diamond_pickaxe:5`
|
||||||
* - `minecraft:string`
|
* - `minecraft:string`
|
||||||
* - `351:4 (lapis lazuli ID:meta)`
|
* - `351:4 (lapis lazuli ID:meta)`
|
||||||
*
|
*
|
||||||
* If multiple item instances are to be created, their identifiers must be comma-separated, for example:
|
|
||||||
* `diamond_pickaxe,wooden_shovel:18,iron_ingot`
|
|
||||||
*
|
|
||||||
* @param string $str
|
* @param string $str
|
||||||
* @param bool $multiple
|
|
||||||
*
|
*
|
||||||
* @return Item[]|Item
|
* @return Item
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException if the given string cannot be parsed as an item identifier
|
* @throws \InvalidArgumentException if the given string cannot be parsed as an item identifier
|
||||||
*/
|
*/
|
||||||
public static function fromString(string $str, bool $multiple = false){
|
public static function fromString(string $str) : Item{
|
||||||
if($multiple){
|
|
||||||
$blocks = [];
|
|
||||||
foreach(explode(",", $str) as $b){
|
|
||||||
$blocks[] = self::fromString($b, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $blocks;
|
|
||||||
}else{
|
|
||||||
$b = explode(":", str_replace([" ", "minecraft:"], ["_", ""], trim($str)));
|
$b = explode(":", str_replace([" ", "minecraft:"], ["_", ""], trim($str)));
|
||||||
if(!isset($b[1])){
|
if(!isset($b[1])){
|
||||||
$meta = 0;
|
$meta = 0;
|
||||||
@ -405,7 +393,6 @@ class ItemFactory{
|
|||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the specified item ID is already registered in the item factory.
|
* Returns whether the specified item ID is already registered in the item factory.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user