diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 07dcc69af..c84f0ca1f 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -195,14 +195,26 @@ class Block extends Position implements BlockIds, Metadatable{ return true; } + /** + * @return int + */ + public function getToolType() : int{ + return BlockToolType::TYPE_NONE; + } + + public function getToolHarvestLevel() : int{ + return 0; + } + public function canBeBrokenWith(Item $item) : bool{ if($this->getHardness() < 0){ return false; } $toolType = $this->getToolType(); - return $toolType === BlockToolType::TYPE_NONE or ($toolType & $item->getBlockToolType()) !== 0; - //TODO: check tool harvest level (tier) + $harvestLevel = $this->getToolHarvestLevel(); + return $toolType === BlockToolType::TYPE_NONE or $harvestLevel === 0 or ( + ($toolType & $item->getBlockToolType()) !== 0 and $item->getBlockToolHarvestLevel() >= $harvestLevel); } /** @@ -319,13 +331,6 @@ class Block extends Position implements BlockIds, Metadatable{ return $this->getHardness() * 5; } - /** - * @return int - */ - public function getToolType() : int{ - return BlockToolType::TYPE_NONE; - } - /** * @return float */ diff --git a/src/pocketmine/item/Axe.php b/src/pocketmine/item/Axe.php index 67efffb2e..f56a3c41b 100644 --- a/src/pocketmine/item/Axe.php +++ b/src/pocketmine/item/Axe.php @@ -35,6 +35,10 @@ class Axe extends TieredTool{ return BlockToolType::TYPE_AXE; } + public function getBlockToolHarvestLevel() : int{ + return $this->tier; + } + public function getAttackPoints() : int{ return self::getBaseDamageFromTier($this->tier) - 1; } diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 93e5c2a90..85361f444 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -752,6 +752,10 @@ class Item implements ItemIds, \JsonSerializable{ return BlockToolType::TYPE_NONE; } + public function getBlockToolHarvestLevel() : int{ + return 0; + } + /** * Returns the maximum amount of damage this item can take before it breaks. * diff --git a/src/pocketmine/item/Pickaxe.php b/src/pocketmine/item/Pickaxe.php index f78732d13..b0b9ff8c5 100644 --- a/src/pocketmine/item/Pickaxe.php +++ b/src/pocketmine/item/Pickaxe.php @@ -35,6 +35,10 @@ class Pickaxe extends TieredTool{ return BlockToolType::TYPE_PICKAXE; } + public function getBlockToolHarvestLevel() : int{ + return $this->tier; + } + public function getAttackPoints() : int{ return self::getBaseDamageFromTier($this->tier) - 2; } diff --git a/src/pocketmine/item/Shears.php b/src/pocketmine/item/Shears.php index fbfa3a575..87e7ca416 100644 --- a/src/pocketmine/item/Shears.php +++ b/src/pocketmine/item/Shears.php @@ -42,4 +42,8 @@ class Shears extends Tool{ public function getBlockToolType() : int{ return BlockToolType::TYPE_SHEARS; } + + public function getBlockToolHarvestLevel() : int{ + return 1; + } } \ No newline at end of file diff --git a/src/pocketmine/item/Shovel.php b/src/pocketmine/item/Shovel.php index 86ffd541d..355e5e49c 100644 --- a/src/pocketmine/item/Shovel.php +++ b/src/pocketmine/item/Shovel.php @@ -35,6 +35,10 @@ class Shovel extends TieredTool{ return BlockToolType::TYPE_SHOVEL; } + public function getBlockToolHarvestLevel() : int{ + return $this->tier; + } + public function getAttackPoints() : int{ return self::getBaseDamageFromTier($this->tier) - 3; } diff --git a/src/pocketmine/item/Sword.php b/src/pocketmine/item/Sword.php index 734fba274..8526fecff 100644 --- a/src/pocketmine/item/Sword.php +++ b/src/pocketmine/item/Sword.php @@ -39,4 +39,7 @@ class Sword extends TieredTool{ return self::getBaseDamageFromTier($this->tier); } + public function getBlockToolHarvestLevel() : int{ + return 1; + } } \ No newline at end of file