mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-20 07:39:42 +00:00
Place/Breaking/Activation logic separated from BlockAPI
This commit is contained in:
@@ -26,24 +26,70 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
*/
|
||||
|
||||
class Item{
|
||||
protected $block = false;
|
||||
protected $id;
|
||||
protected $meta;
|
||||
protected $count;
|
||||
protected $maxStackSize = 64;
|
||||
protected $durability = 0;
|
||||
protected $name = "Unknown";
|
||||
|
||||
public function __construct($id, $meta = 0){
|
||||
public function __construct($id, $meta = 0, $count = 1){
|
||||
$this->id = (int) $id;
|
||||
$this->meta = (int) $meta;
|
||||
$this->count = (int) $count;
|
||||
if(isset(BlockAPI::$class[$this->id])){
|
||||
$this->block = BlockAPI::get($this->id, $this->meta);
|
||||
$this->name = $this->block->getName();
|
||||
}
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function isPlaceable(){
|
||||
return (($this->block instanceof Block) and $this->block->isPlaceable === true);
|
||||
}
|
||||
|
||||
public function getBlock(){
|
||||
if($this->block instanceof Block){
|
||||
return $this->block;
|
||||
}else{
|
||||
return BlockAPI::get(AIR);
|
||||
}
|
||||
}
|
||||
|
||||
public function getID(){
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getMetadata(){
|
||||
return $this->meta;
|
||||
}
|
||||
|
||||
public function getMaxStackSize(){
|
||||
return $this->maxStackSize;
|
||||
}
|
||||
|
||||
public function getDestroySpeed(Item $item, Player $player){
|
||||
public function isPickaxe(){ //Returns false or level of the pickaxe
|
||||
switch($this->id){
|
||||
case IRON_PICKAXE:
|
||||
return 3;
|
||||
case 270: //Wood
|
||||
return 1;
|
||||
case 274: //Stone
|
||||
return 2;
|
||||
case 278: //Diamond
|
||||
return 4;
|
||||
case 285: //Gold
|
||||
return 3;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDestroySpeed(Block $block, Player $player){
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user