mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-20 02:14:01 +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->canBeBrokenWith($item)){
|
||||||
if($this->getToolType() === BlockToolType::TYPE_SHEARS and $item->isShears()){
|
if($this->getToolType() === BlockToolType::TYPE_SHEARS and $item->isShears()){
|
||||||
$base /= 15;
|
$base /= 15;
|
||||||
}elseif(
|
}elseif($item instanceof TieredTool and ($this->getToolType() & $item->getBlockToolType()) !== 0){
|
||||||
($this->getToolType() === BlockToolType::TYPE_PICKAXE and ($tier = $item->isPickaxe()) !== false) or
|
switch($item->getTier()){
|
||||||
($this->getToolType() === BlockToolType::TYPE_AXE and ($tier = $item->isAxe()) !== false) or
|
|
||||||
($this->getToolType() === BlockToolType::TYPE_SHOVEL and ($tier = $item->isShovel()) !== false)
|
|
||||||
){
|
|
||||||
switch($tier){
|
|
||||||
case TieredTool::TIER_WOODEN:
|
case TieredTool::TIER_WOODEN:
|
||||||
$base /= 2;
|
$base /= 2;
|
||||||
break;
|
break;
|
||||||
|
@ -25,14 +25,15 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Types of tools that can be used to break blocks
|
* Types of tools that can be used to break blocks
|
||||||
|
* Blocks may allow multiple tool types by combining these bitflags
|
||||||
*/
|
*/
|
||||||
interface BlockToolType{
|
interface BlockToolType{
|
||||||
|
|
||||||
public const TYPE_NONE = 0;
|
public const TYPE_NONE = 0;
|
||||||
public const TYPE_SWORD = 1;
|
public const TYPE_SWORD = 1 << 0;
|
||||||
public const TYPE_SHOVEL = 2;
|
public const TYPE_SHOVEL = 1 << 1;
|
||||||
public const TYPE_PICKAXE = 3;
|
public const TYPE_PICKAXE = 1 << 2;
|
||||||
public const TYPE_AXE = 4;
|
public const TYPE_AXE = 1 << 3;
|
||||||
public const TYPE_SHEARS = 5;
|
public const TYPE_SHEARS = 1 << 4;
|
||||||
|
|
||||||
}
|
}
|
@ -24,7 +24,6 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\item;
|
namespace pocketmine\item;
|
||||||
|
|
||||||
use pocketmine\block\Block;
|
use pocketmine\block\Block;
|
||||||
use pocketmine\block\BlockToolType;
|
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
|
|
||||||
abstract class Tool extends Durable{
|
abstract class Tool extends Durable{
|
||||||
@ -46,13 +45,7 @@ abstract class Tool extends Durable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($object instanceof Block){
|
if($object instanceof Block){
|
||||||
if(
|
if(($object->getToolType() & $this->getBlockToolType()) !== 0){
|
||||||
$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()
|
|
||||||
){
|
|
||||||
$this->applyDamage(1);
|
$this->applyDamage(1);
|
||||||
}elseif(!$this->isShears() and $object->getBreakTime($this) > 0){
|
}elseif(!$this->isShears() and $object->getBreakTime($this) > 0){
|
||||||
$this->applyDamage(2);
|
$this->applyDamage(2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user