Get Item Lists from BlockAPI::fromString() method

This commit is contained in:
Shoghi Cervantes Pueyo 2013-03-06 16:43:25 +01:00
parent 6c4900cd32
commit e8c2662258
2 changed files with 22 additions and 14 deletions

View File

@ -38,23 +38,31 @@ define("BLOCK_UPDATE_WEAK", 3);
class BlockAPI{
private $server;
public static function fromString($str){
$b = explode(":", str_replace(" ", "_", trim($str)));
if(!isset($b[1])){
$meta = 0;
public static function fromString($str, $multiple = false){
if($multiple === true){
$blocks = array();
foreach(explode(",",$str) as $b){
$blocks[] = BlockAPI::fromString($b, false);
}
return $blocks;
}else{
$meta = ((int) $b[1]) & 0xFFFF;
}
if(defined(strtoupper($b[0]))){
$item = BlockAPI::getItem(constant(strtoupper($b[0])), $meta);
if($item->getID() === AIR and strtoupper($b[0]) !== "AIR"){
$b = explode(":", str_replace(" ", "_", trim($str)));
if(!isset($b[1])){
$meta = 0;
}else{
$meta = ((int) $b[1]) & 0xFFFF;
}
if(defined(strtoupper($b[0]))){
$item = BlockAPI::getItem(constant(strtoupper($b[0])), $meta);
if($item->getID() === AIR and strtoupper($b[0]) !== "AIR"){
$item = BlockAPI::getItem(((int) $b[0]) & 0xFFFF, $meta);
}
}else{
$item = BlockAPI::getItem(((int) $b[0]) & 0xFFFF, $meta);
}
}else{
$item = BlockAPI::getItem(((int) $b[0]) & 0xFFFF, $meta);
return $item;
}
return $item;
}
public static function get($id, $meta = 0, $v = false){

View File

@ -47,5 +47,5 @@ define("MAJOR_VERSION", "Alpha_1.3dev");
define("CURRENT_STRUCTURE", 5);
define("CURRENT_PROTOCOL", 9);
define("CURRENT_MINECRAFT_VERSION", "v0.6.1 alpha");
define("CURRENT_API_VERSION", 3);
define("CURRENT_API_VERSION", 4);
define("CURRENT_PHP_VERSION", "5.4.12");