diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index d493d9aa8..5190c6646 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -56,7 +56,7 @@ class BlockAPI{ $id = (int) $id; if(isset(Item::$class[$id])){ $classname = Item::$class[$id]; - $i = new $classname($meta); + $i = new $classname($meta, $count); }else{ $i = new Item($id, $meta, $count); } diff --git a/src/classes/Player.php b/src/classes/Player.php index 0ecfdfbc2..e7e8c727a 100644 --- a/src/classes/Player.php +++ b/src/classes/Player.php @@ -59,9 +59,9 @@ class Player{ $this->timeout = microtime(true) + 20; $this->inventory = array_fill(0, 36, array(AIR, 0, 0)); if($this->server->gamemode === 0 or $this->server->gamemode === 2){ - $this->equipment = new Item(AIR); + $this->equipment = BlockAPI::getItem(AIR); }else{ - $this->equipment = new Item(STONE); + $this->equipment = BlockAPI::getItem(STONE); } $this->evid[] = $this->server->event("server.tick", array($this, "onTick")); $this->evid[] = $this->server->event("server.close", array($this, "close")); @@ -136,7 +136,7 @@ class Player{ while($count > 0){ $add = 0; foreach($this->inventory as $s => $data){ - if($data[0] === 0){ + if($data[0] === AIR){ $add = min(64, $count); $this->inventory[$s] = array($type, $damage, $add); break; @@ -180,7 +180,7 @@ class Player{ } public function hasItem($type, $damage = false){ - if($type === 0){ + if($type === AIR){ return true; } foreach($this->inventory as $s => $data){ @@ -552,7 +552,7 @@ class Player{ case MC_PLAYER_EQUIPMENT: $data["eid"] = $this->eid; if($this->server->handle("player.equipment.change", $data) !== false){ - $this->equipment = new Item($data["block"], $data["meta"]); + $this->equipment = BlockAPI::getItem($data["block"], $data["meta"]); console("[DEBUG] Player ".$this->username." has now ".$this->equipment->getName()." (".$this->equipment->getID().":".$this->equipment->getMetadata().") in their hands!", true, true, 2); } break; diff --git a/src/classes/material/IDs.php b/src/classes/material/IDs.php index 27c8bf51c..d63af7c8a 100644 --- a/src/classes/material/IDs.php +++ b/src/classes/material/IDs.php @@ -237,6 +237,7 @@ define("LEATHER", 334); define("BRICK", 336); define("CLAY", 337); +define("SUGARCANE", 338); define("SUGAR_CANE", 338); define("SUGAR_CANES", 338); define("PAPER", 339); diff --git a/src/classes/material/Item.php b/src/classes/material/Item.php index 71148aba8..16d4fbe32 100644 --- a/src/classes/material/Item.php +++ b/src/classes/material/Item.php @@ -29,8 +29,7 @@ require_once("classes/material/IDs.php"); class Item{ public static $class = array( - - + SUGARCANE => "SugarcaneItem", ); protected $block; protected $id; diff --git a/src/classes/material/block/plant/Sugarcane.php b/src/classes/material/block/plant/Sugarcane.php index 6fd559eb9..5e7327e8f 100644 --- a/src/classes/material/block/plant/Sugarcane.php +++ b/src/classes/material/block/plant/Sugarcane.php @@ -30,4 +30,10 @@ class SugarcaneBlock extends TransparentBlock{ parent::__construct(SUGARCANE_BLOCK, 0, "Sugarcane"); } + public function getDrops(Item $item, Player $player){ + return array( + array(SUGARCANE, 0, 1), + ); + } + } \ No newline at end of file diff --git a/src/classes/material/item/generic/Sugarcane.php b/src/classes/material/item/generic/Sugarcane.php new file mode 100644 index 000000000..dde4616b8 --- /dev/null +++ b/src/classes/material/item/generic/Sugarcane.php @@ -0,0 +1,33 @@ +block = BlockAPI::get(SUGARCANE_BLOCK); + parent::__construct(SUGARCANE, 0, $count, "Sugar Cane"); + } +} \ No newline at end of file