Change block tool types to bitflags

This allows specification of multiple tool types for a block, such as cobwebs.
This commit is contained in:
Dylan K. Taylor 2017-12-11 12:16:37 +00:00
parent db31d13f96
commit 58327d0514
3 changed files with 9 additions and 19 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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);