42 private float $blastResistance;
48 private float $hardness,
49 private int $toolType = BlockToolType::NONE,
50 private int $toolHarvestLevel = 0,
51 ?
float $blastResistance =
null
53 $this->blastResistance = $blastResistance ?? $hardness * 5;
56 public static function tier(
float $hardness,
int $toolType,
ToolTier $toolTier, ?
float $blastResistance =
null) : self{
57 return new self($hardness, $toolType, $toolTier->getHarvestLevel(), $blastResistance);
60 public static function pickaxe(
float $hardness, ?
ToolTier $toolTier =
null, ?
float $blastResistance =
null) : self{
61 return new self($hardness, BlockToolType::PICKAXE, $toolTier?->getHarvestLevel() ?? 0, $blastResistance);
64 public static function shovel(
float $hardness, ?ToolTier $toolTier =
null, ?
float $blastResistance =
null) : self{
65 return new self($hardness, BlockToolType::SHOVEL, $toolTier?->getHarvestLevel() ?? 0, $blastResistance);
68 public static function axe(
float $hardness, ?ToolTier $toolTier =
null, ?
float $blastResistance =
null) : self{
69 return new self($hardness, BlockToolType::AXE, $toolTier?->getHarvestLevel() ?? 0, $blastResistance);
72 public static function instant(
int $toolType = BlockToolType::NONE,
int $toolHarvestLevel = 0) : self{
73 return new self(0.0, $toolType, $toolHarvestLevel, 0.0);
76 public static function indestructible(
float $blastResistance = 18000000.0) : self{
77 return new self(-1.0, BlockToolType::NONE, 0, $blastResistance);
84 return $this->hardness;
91 return $this->hardness >= 0;
98 return $this->hardness == 0.0;
105 return $this->blastResistance;
108 public function getToolType() : int{
109 return $this->toolType;
123 return $this->toolHarvestLevel;
134 if($this->hardness < 0){
138 return $this->toolType === BlockToolType::NONE || $this->toolHarvestLevel === 0 || (
139 ($this->toolType & $tool->getBlockToolType()) !== 0 && $tool->getBlockToolHarvestLevel() >= $this->toolHarvestLevel);
148 $base = $this->hardness;
149 if($this->isToolCompatible($item)){
150 $base *= self::COMPATIBLE_TOOL_MULTIPLIER;
152 $base *= self::INCOMPATIBLE_TOOL_MULTIPLIER;
155 $efficiency = $item->getMiningEfficiency(($this->toolType & $item->
getBlockToolType()) !== 0);
156 if($efficiency <= 0){
157 throw new \InvalidArgumentException(get_class($item) .
" has invalid mining efficiency: expected >= 0, got $efficiency");
160 $base /= $efficiency;