Added conversion between Items <==> Blocks

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-04 16:26:47 +01:00
parent d5aa898ffe
commit 213cda27aa
6 changed files with 47 additions and 8 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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);

View File

@ -29,8 +29,7 @@ require_once("classes/material/IDs.php");
class Item{
public static $class = array(
SUGARCANE => "SugarcaneItem",
);
protected $block;
protected $id;

View File

@ -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),
);
}
}

View File

@ -0,0 +1,33 @@
<?php
/*
-
/ \
/ \
/ PocketMine \
/ MP \
|\ @shoghicp /|
|. \ / .|
| .. \ / .. |
| .. | .. |
| .. | .. |
\ | /
\ | /
\ | /
\ | /
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
*/
class SugarcaneItem extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = BlockAPI::get(SUGARCANE_BLOCK);
parent::__construct(SUGARCANE, 0, $count, "Sugar Cane");
}
}