Block breaking part 1

This commit is contained in:
Shoghi Cervantes
2015-05-17 19:33:41 +02:00
parent b14d14d3d5
commit f3c46b12c5
18 changed files with 155 additions and 38 deletions

View File

@ -22,6 +22,7 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
class AcaciaWoodStairs extends Stair{
@ -40,4 +41,16 @@ class AcaciaWoodStairs extends Stair{
[$this->id, 0, 1],
];
}
public function getHardness(){
return 2;
}
public function getResistance(){
return 15;
}
public function getToolType(){
return Tool::TYPE_AXE;
}
}

View File

@ -68,4 +68,12 @@ class Air extends Transparent{
return null;
}
public function getHardness(){
return -1;
}
public function getResistance(){
return 0;
}
}

View File

@ -40,7 +40,7 @@ class Bed extends Transparent{
}
public function getHardness(){
return 1;
return 0.2;
}
public function getName(){

View File

@ -36,6 +36,10 @@ class Bedrock extends Solid{
}
public function getHardness(){
return -1;
}
public function getResistance(){
return 18000000;
}

View File

@ -22,6 +22,7 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
class BirchWoodStairs extends Stair{
@ -40,4 +41,16 @@ class BirchWoodStairs extends Stair{
[$this->id, 0, 1],
];
}
public function getHardness(){
return 2;
}
public function getResistance(){
return 15;
}
public function getToolType(){
return Tool::TYPE_AXE;
}
}

View File

@ -29,6 +29,7 @@ use pocketmine\entity\Squid;
use pocketmine\entity\Villager;
use pocketmine\entity\Zombie;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\level\Level;
use pocketmine\level\MovingObjectPosition;
use pocketmine\level\Position;
@ -605,7 +606,14 @@ class Block extends Position implements Metadatable{
* @return int
*/
public function getResistance(){
return 1;
return $this->getHardness() * 5;
}
/**
* @return int
*/
public function getToolType(){
return Tool::TYPE_NONE;
}
/**
@ -747,7 +755,42 @@ class Block extends Position implements Metadatable{
* @return float
*/
public function getBreakTime(Item $item){
return 0.20;
$base = $this->getHardness() * 1.5;
if($this->canBeBrokenWith($item)){
if($this->getToolType() === Tool::TYPE_SHEARS and $item->isShears()){
$base /= 15;
}elseif(
($this->getToolType() === Tool::TYPE_PICKAXE and ($tier = $item->isPickaxe()) !== false) or
($this->getToolType() === Tool::TYPE_AXE and ($tier = $item->isAxe()) !== false) or
($this->getToolType() === Tool::TYPE_SHOVEL and ($tier = $item->isShovel()) !== false)
){
switch($tier){
case Tool::TIER_WOODEN:
$base /= 2;
break;
case Tool::TIER_STONE:
$base /= 4;
break;
case Tool::TIER_IRON:
$base /= 6;
break;
case Tool::TIER_DIAMOND:
$base /= 8;
break;
case Tool::TIER_GOLD:
$base /= 12;
break;
}
}
}else{
$base *= 3.33;
}
return $base;
}
public function canBeBrokenWith(Item $item){
return $this->getHardness() !== -1;
}
/**

View File

@ -22,6 +22,8 @@
namespace pocketmine\block;
use pocketmine\item\Tool;
class Bookshelf extends Solid{
protected $id = self::BOOKSHELF;
@ -35,7 +37,11 @@ class Bookshelf extends Solid{
}
public function getHardness(){
return 7.5;
return 1.5;
}
public function getToolType(){
return Tool::TYPE_AXE;
}
}

View File

@ -22,6 +22,8 @@
namespace pocketmine\block;
use pocketmine\item\Tool;
class BrickStairs extends Stair{
protected $id = self::BRICK_STAIRS;
@ -30,6 +32,18 @@ class BrickStairs extends Stair{
$this->meta = $meta;
}
public function getHardness(){
return 2;
}
public function getResistance(){
return 30;
}
public function getToolType(){
return Tool::TYPE_PICKAXE;
}
public function getName(){
return "Brick Stairs";
}

View File

@ -22,6 +22,7 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
class Bricks extends Solid{
@ -32,30 +33,21 @@ class Bricks extends Solid{
}
public function getHardness(){
return 2;
}
public function getResistance(){
return 30;
}
public function getToolType(){
return Tool::TYPE_PICKAXE;
}
public function getName(){
return "Bricks";
}
public function getBreakTime(Item $item){
switch($item->isPickaxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
}
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return [

View File

@ -22,6 +22,7 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Enum;
@ -48,7 +49,11 @@ class BurningFurnace extends Solid{
}
public function getHardness(){
return 17.5;
return 3.5;
}
public function getToolType(){
return Tool::TYPE_PICKAXE;
}
public function getLightLevel(){

View File

@ -41,7 +41,7 @@ class Cactus extends Transparent{
}
public function getHardness(){
return 2;
return 0.4;
}
public function hasEntityCollision(){

View File

@ -22,6 +22,7 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\Player;
class Dirt extends Solid{
@ -37,7 +38,11 @@ class Dirt extends Solid{
}
public function getHardness(){
return 2.5;
return 0.5;
}
public function getToolType(){
return Tool::TYPE_SHOVEL;
}
public function getName(){

View File

@ -30,7 +30,11 @@ abstract class Flowable extends Transparent{
return true;
}
public function getBreakTime(Item $item){
public function getHardness(){
return 0;
}
public function getResistance(){
return 0;
}
@ -41,8 +45,4 @@ abstract class Flowable extends Transparent{
public function getBoundingBox(){
return null;
}
public function getHardness(){
return 0;
}
}

View File

@ -23,6 +23,7 @@ namespace pocketmine\block;
use pocketmine\event\block\BlockSpreadEvent;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\level\generator\object\TallGrass as TallGrassObject;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
@ -47,7 +48,11 @@ class Grass extends Solid{
}
public function getHardness(){
return 3;
return 0.6;
}
public function getToolType(){
return Tool::TYPE_SHOVEL;
}
public function getDrops(Item $item){

View File

@ -27,10 +27,6 @@ use pocketmine\Player;
abstract class Stair extends Transparent{
public function getHardness(){
return 30;
}
/*
public function collidesWithBB(AxisAlignedBB $bb, &$list = []){
$damage = $this->getDamage();