mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Declare tool harvest level as a property
This commit is contained in:
parent
45983acc0d
commit
dbc180315e
@ -195,14 +195,26 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getToolType() : int{
|
||||
return BlockToolType::TYPE_NONE;
|
||||
}
|
||||
|
||||
public function getToolHarvestLevel() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function canBeBrokenWith(Item $item) : bool{
|
||||
if($this->getHardness() < 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
$toolType = $this->getToolType();
|
||||
return $toolType === BlockToolType::TYPE_NONE or ($toolType & $item->getBlockToolType()) !== 0;
|
||||
//TODO: check tool harvest level (tier)
|
||||
$harvestLevel = $this->getToolHarvestLevel();
|
||||
return $toolType === BlockToolType::TYPE_NONE or $harvestLevel === 0 or (
|
||||
($toolType & $item->getBlockToolType()) !== 0 and $item->getBlockToolHarvestLevel() >= $harvestLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -319,13 +331,6 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
return $this->getHardness() * 5;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getToolType() : int{
|
||||
return BlockToolType::TYPE_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
|
@ -35,6 +35,10 @@ class Axe extends TieredTool{
|
||||
return BlockToolType::TYPE_AXE;
|
||||
}
|
||||
|
||||
public function getBlockToolHarvestLevel() : int{
|
||||
return $this->tier;
|
||||
}
|
||||
|
||||
public function getAttackPoints() : int{
|
||||
return self::getBaseDamageFromTier($this->tier) - 1;
|
||||
}
|
||||
|
@ -752,6 +752,10 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
return BlockToolType::TYPE_NONE;
|
||||
}
|
||||
|
||||
public function getBlockToolHarvestLevel() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of damage this item can take before it breaks.
|
||||
*
|
||||
|
@ -35,6 +35,10 @@ class Pickaxe extends TieredTool{
|
||||
return BlockToolType::TYPE_PICKAXE;
|
||||
}
|
||||
|
||||
public function getBlockToolHarvestLevel() : int{
|
||||
return $this->tier;
|
||||
}
|
||||
|
||||
public function getAttackPoints() : int{
|
||||
return self::getBaseDamageFromTier($this->tier) - 2;
|
||||
}
|
||||
|
@ -42,4 +42,8 @@ class Shears extends Tool{
|
||||
public function getBlockToolType() : int{
|
||||
return BlockToolType::TYPE_SHEARS;
|
||||
}
|
||||
|
||||
public function getBlockToolHarvestLevel() : int{
|
||||
return 1;
|
||||
}
|
||||
}
|
@ -35,6 +35,10 @@ class Shovel extends TieredTool{
|
||||
return BlockToolType::TYPE_SHOVEL;
|
||||
}
|
||||
|
||||
public function getBlockToolHarvestLevel() : int{
|
||||
return $this->tier;
|
||||
}
|
||||
|
||||
public function getAttackPoints() : int{
|
||||
return self::getBaseDamageFromTier($this->tier) - 3;
|
||||
}
|
||||
|
@ -39,4 +39,7 @@ class Sword extends TieredTool{
|
||||
return self::getBaseDamageFromTier($this->tier);
|
||||
}
|
||||
|
||||
public function getBlockToolHarvestLevel() : int{
|
||||
return 1;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user