diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index 1c81b20e7..1b84dd6c7 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -111,7 +111,7 @@ class Anvil extends Fallable{ } public function getDrops(Item $item) : array{ - if($this->canBeBrokenWith($item)){ + if($this->isCompatibleWithTool($item)){ return [ ItemFactory::get($this->getItemId(), $this->getDamage() & 0x0c, 1) ]; diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 1c3a29434..54cd30511 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -218,7 +218,18 @@ class Block extends Position implements BlockIds, Metadatable{ return 0; } - public function canBeBrokenWith(Item $item) : bool{ + /** + * Returns whether the specified item is the proper tool to use for breaking this block. This checks tool type and + * harvest level requirement. + * + * In most cases this is also used to determine whether block drops should be created or not, except in some + * special cases such as vines. + * + * @param Item $tool + * + * @return bool + */ + public function isCompatibleWithTool(Item $tool) : bool{ if($this->getHardness() < 0){ return false; } @@ -226,7 +237,7 @@ class Block extends Position implements BlockIds, Metadatable{ $toolType = $this->getToolType(); $harvestLevel = $this->getToolHarvestLevel(); return $toolType === BlockToolType::TYPE_NONE or $harvestLevel === 0 or ( - ($toolType & $item->getBlockToolType()) !== 0 and $item->getBlockToolHarvestLevel() >= $harvestLevel); + ($toolType & $tool->getBlockToolType()) !== 0 and $tool->getBlockToolHarvestLevel() >= $harvestLevel); } /** @@ -251,7 +262,7 @@ class Block extends Position implements BlockIds, Metadatable{ */ public function getBreakTime(Item $item) : float{ $base = $this->getHardness(); - if($this->canBeBrokenWith($item)){ + if($this->isCompatibleWithTool($item)){ $base *= 1.5; }else{ $base *= 5; @@ -422,7 +433,7 @@ class Block extends Position implements BlockIds, Metadatable{ * @return Item[] */ public function getDrops(Item $item) : array{ - if($this->canBeBrokenWith($item)){ + if($this->isCompatibleWithTool($item)){ return [ ItemFactory::get($this->getItemId(), $this->getVariant(), 1) ]; diff --git a/src/pocketmine/block/CoalOre.php b/src/pocketmine/block/CoalOre.php index e965a2786..902ab6c0d 100644 --- a/src/pocketmine/block/CoalOre.php +++ b/src/pocketmine/block/CoalOre.php @@ -52,7 +52,7 @@ class CoalOre extends Solid{ } public function getDrops(Item $item) : array{ - if($this->canBeBrokenWith($item)){ + if($this->isCompatibleWithTool($item)){ return [ ItemFactory::get(Item::COAL, 0, 1) ]; diff --git a/src/pocketmine/block/DiamondOre.php b/src/pocketmine/block/DiamondOre.php index 68c863e56..730d5810a 100644 --- a/src/pocketmine/block/DiamondOre.php +++ b/src/pocketmine/block/DiamondOre.php @@ -52,7 +52,7 @@ class DiamondOre extends Solid{ } public function getDrops(Item $item) : array{ - if($this->canBeBrokenWith($item)){ + if($this->isCompatibleWithTool($item)){ return [ ItemFactory::get(Item::DIAMOND, 0, 1) ]; diff --git a/src/pocketmine/block/EmeraldOre.php b/src/pocketmine/block/EmeraldOre.php index 33a8367ba..36c102942 100644 --- a/src/pocketmine/block/EmeraldOre.php +++ b/src/pocketmine/block/EmeraldOre.php @@ -52,7 +52,7 @@ class EmeraldOre extends Solid{ } public function getDrops(Item $item) : array{ - if($this->canBeBrokenWith($item)){ + if($this->isCompatibleWithTool($item)){ return [ ItemFactory::get(Item::EMERALD, 0, 1) ]; diff --git a/src/pocketmine/block/EnderChest.php b/src/pocketmine/block/EnderChest.php index 6e7acaffd..a56e1fa14 100644 --- a/src/pocketmine/block/EnderChest.php +++ b/src/pocketmine/block/EnderChest.php @@ -102,7 +102,7 @@ class EnderChest extends Chest{ } public function getDrops(Item $item) : array{ - if($this->canBeBrokenWith($item)){ + if($this->isCompatibleWithTool($item)){ return [ ItemFactory::get(Item::OBSIDIAN, 0, 8) ]; diff --git a/src/pocketmine/block/LapisOre.php b/src/pocketmine/block/LapisOre.php index 0bc499509..9baf17706 100644 --- a/src/pocketmine/block/LapisOre.php +++ b/src/pocketmine/block/LapisOre.php @@ -52,7 +52,7 @@ class LapisOre extends Solid{ } public function getDrops(Item $item) : array{ - if($this->canBeBrokenWith($item)){ + if($this->isCompatibleWithTool($item)){ return [ ItemFactory::get(Item::DYE, 4, mt_rand(4, 8)) ]; diff --git a/src/pocketmine/block/NetherQuartzOre.php b/src/pocketmine/block/NetherQuartzOre.php index b0d1b5610..b9033f661 100644 --- a/src/pocketmine/block/NetherQuartzOre.php +++ b/src/pocketmine/block/NetherQuartzOre.php @@ -52,7 +52,7 @@ class NetherQuartzOre extends Solid{ } public function getDrops(Item $item) : array{ - if($this->canBeBrokenWith($item)){ + if($this->isCompatibleWithTool($item)){ return [ ItemFactory::get(Item::QUARTZ, 0, 1) ]; diff --git a/src/pocketmine/block/NetherReactor.php b/src/pocketmine/block/NetherReactor.php index 6fdc4684b..3bd16fb57 100644 --- a/src/pocketmine/block/NetherReactor.php +++ b/src/pocketmine/block/NetherReactor.php @@ -56,7 +56,7 @@ class NetherReactor extends Solid{ } public function getDrops(Item $item) : array{ - if($this->canBeBrokenWith($item)){ + if($this->isCompatibleWithTool($item)){ return [ ItemFactory::get(Item::IRON_INGOT, 0, 6), ItemFactory::get(Item::DIAMOND, 0, 3) diff --git a/src/pocketmine/block/RedstoneOre.php b/src/pocketmine/block/RedstoneOre.php index e2211954b..864f95ec9 100644 --- a/src/pocketmine/block/RedstoneOre.php +++ b/src/pocketmine/block/RedstoneOre.php @@ -69,7 +69,7 @@ class RedstoneOre extends Solid{ } public function getDrops(Item $item) : array{ - if($this->canBeBrokenWith($item)){ + if($this->isCompatibleWithTool($item)){ return [ ItemFactory::get(Item::REDSTONE_DUST, 0, mt_rand(4, 5)) ]; diff --git a/src/pocketmine/block/Stone.php b/src/pocketmine/block/Stone.php index adb91d7ec..a495798f9 100644 --- a/src/pocketmine/block/Stone.php +++ b/src/pocketmine/block/Stone.php @@ -68,7 +68,7 @@ class Stone extends Solid{ } public function getDrops(Item $item) : array{ - if($this->canBeBrokenWith($item)){ + if($this->isCompatibleWithTool($item)){ if($this->getDamage() === self::NORMAL){ return [ ItemFactory::get(Item::COBBLESTONE, $this->getDamage(), 1)