mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Change block tool types to bitflags
This allows specification of multiple tool types for a block, such as cobwebs.
This commit is contained in:
parent
db31d13f96
commit
58327d0514
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user