42 private float $blastResistance;
43 private bool $explosionHarvestable;
50 private float $hardness,
51 private int $toolType = BlockToolType::NONE,
52 private int $toolHarvestLevel = 0,
53 ?
float $blastResistance =
null,
54 ?
bool $explosionHarvestable =
null,
56 $this->blastResistance = $blastResistance ?? $hardness * 5;
57 $this->explosionHarvestable = $explosionHarvestable ?? ($this->toolType & BlockToolType::PICKAXE) !== 0;
60 public static function tier(
float $hardness,
int $toolType,
ToolTier $toolTier, ?
float $blastResistance =
null) : self{
61 return new self($hardness, $toolType, $toolTier->getHarvestLevel(), $blastResistance);
64 public static function pickaxe(
float $hardness, ?
ToolTier $toolTier =
null, ?
float $blastResistance =
null) : self{
65 return new self($hardness, BlockToolType::PICKAXE, $toolTier?->getHarvestLevel() ?? 0, $blastResistance);
68 public static function shovel(
float $hardness, ?ToolTier $toolTier =
null, ?
float $blastResistance =
null) : self{
69 return new self($hardness, BlockToolType::SHOVEL, $toolTier?->getHarvestLevel() ?? 0, $blastResistance);
72 public static function axe(
float $hardness, ?ToolTier $toolTier =
null, ?
float $blastResistance =
null) : self{
73 return new self($hardness, BlockToolType::AXE, $toolTier?->getHarvestLevel() ?? 0, $blastResistance);
76 public static function instant(
int $toolType = BlockToolType::NONE,
int $toolHarvestLevel = 0) : self{
77 return new self(0.0, $toolType, $toolHarvestLevel, 0.0);
80 public static function indestructible(
float $blastResistance = 18000003.75) : self{
81 return new self(-1.0, BlockToolType::NONE, 0, $blastResistance);
88 return $this->hardness;
95 return $this->hardness >= 0;
102 return $this->hardness === 0.0;
109 return $this->blastResistance;
112 public function getToolType() : int{
113 return $this->toolType;
127 return $this->toolHarvestLevel;
138 if($this->hardness < 0){
142 return $this->toolType === BlockToolType::NONE || $this->toolHarvestLevel === 0 || (
143 ($this->toolType & $tool->getBlockToolType()) !== 0 && $tool->getBlockToolHarvestLevel() >= $this->toolHarvestLevel);
152 $base = $this->hardness;
153 if($this->isToolCompatible($item)){
154 $base *= self::COMPATIBLE_TOOL_MULTIPLIER;
156 $base *= self::INCOMPATIBLE_TOOL_MULTIPLIER;
159 $efficiency = $item->getMiningEfficiency(($this->toolType & $item->
getBlockToolType()) !== 0);
160 if($efficiency <= 0){
161 throw new \InvalidArgumentException(get_class($item) .
" must have a positive mining efficiency, but got $efficiency");
164 $base /= $efficiency;
__construct(private float $hardness, private int $toolType=BlockToolType::NONE, private int $toolHarvestLevel=0, ?float $blastResistance=null, ?bool $explosionHarvestable=null,)