diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 6f7169246..9df9aa6da 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -224,12 +224,8 @@ class Block extends Position implements BlockIds, Metadatable{ if($this->canBeBrokenWith($item)){ if($this->getToolType() === BlockToolType::TYPE_SHEARS and $item->isShears()){ $base /= 15; - }elseif( - ($this->getToolType() === BlockToolType::TYPE_PICKAXE and ($tier = $item->isPickaxe()) !== false) or - ($this->getToolType() === BlockToolType::TYPE_AXE and ($tier = $item->isAxe()) !== false) or - ($this->getToolType() === BlockToolType::TYPE_SHOVEL and ($tier = $item->isShovel()) !== false) - ){ - switch($tier){ + }elseif($item instanceof TieredTool and ($this->getToolType() & $item->getBlockToolType()) !== 0){ + switch($item->getTier()){ case TieredTool::TIER_WOODEN: $base /= 2; break; diff --git a/src/pocketmine/block/BlockToolType.php b/src/pocketmine/block/BlockToolType.php index bc7a4ec77..0239c6a02 100644 --- a/src/pocketmine/block/BlockToolType.php +++ b/src/pocketmine/block/BlockToolType.php @@ -25,14 +25,15 @@ namespace pocketmine\block; /** * Types of tools that can be used to break blocks + * Blocks may allow multiple tool types by combining these bitflags */ interface BlockToolType{ public const TYPE_NONE = 0; - public const TYPE_SWORD = 1; - public const TYPE_SHOVEL = 2; - public const TYPE_PICKAXE = 3; - public const TYPE_AXE = 4; - public const TYPE_SHEARS = 5; + public const TYPE_SWORD = 1 << 0; + public const TYPE_SHOVEL = 1 << 1; + public const TYPE_PICKAXE = 1 << 2; + public const TYPE_AXE = 1 << 3; + public const TYPE_SHEARS = 1 << 4; } \ No newline at end of file diff --git a/src/pocketmine/item/Tool.php b/src/pocketmine/item/Tool.php index 73848d800..67191c02a 100644 --- a/src/pocketmine/item/Tool.php +++ b/src/pocketmine/item/Tool.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace pocketmine\item; use pocketmine\block\Block; -use pocketmine\block\BlockToolType; use pocketmine\entity\Entity; abstract class Tool extends Durable{ @@ -46,13 +45,7 @@ abstract class Tool extends Durable{ } if($object instanceof Block){ - if( - $object->getToolType() === BlockToolType::TYPE_PICKAXE and $this->isPickaxe() or - $object->getToolType() === BlockToolType::TYPE_SHOVEL and $this->isShovel() or - $object->getToolType() === BlockToolType::TYPE_AXE and $this->isAxe() or - $object->getToolType() === BlockToolType::TYPE_SWORD and $this->isSword() or - $object->getToolType() === BlockToolType::TYPE_SHEARS and $this->isShears() - ){ + if(($object->getToolType() & $this->getBlockToolType()) !== 0){ $this->applyDamage(1); }elseif(!$this->isShears() and $object->getBreakTime($this) > 0){ $this->applyDamage(2);