Reduce code width when tool tiers are given to BlockBreakInfo

this is the majority of uses of harvest level
This commit is contained in:
Dylan K. Taylor
2022-07-23 17:56:08 +01:00
parent 102406ee79
commit 91e91b1d9f
2 changed files with 74 additions and 69 deletions

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ToolTier;
use function get_class;
class BlockBreakInfo{
@ -52,6 +53,10 @@ class BlockBreakInfo{
$this->blastResistance = $blastResistance ?? $hardness * 5;
}
public static function tier(float $hardness, int $toolType, ToolTier $toolTier, ?float $blastResistance = null) : self{
return new self($hardness, $toolType, $toolTier->getHarvestLevel(), $blastResistance);
}
public static function instant(int $toolType = BlockToolType::NONE, int $toolHarvestLevel = 0) : self{
return new self(0.0, $toolType, $toolHarvestLevel, 0.0);
}