mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-04 17:06:16 +00:00
Refactored tool efficiency handling
This fixes lots of bugs with things like wool, cobwebs, swords.
This commit is contained in:
@ -245,31 +245,12 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
$base *= 5;
|
||||
}
|
||||
|
||||
if($this->getToolType() === BlockToolType::TYPE_SHEARS and $item->isShears()){
|
||||
$base /= 15;
|
||||
}elseif($item instanceof TieredTool and ($this->getToolType() & $item->getBlockToolType()) !== 0){
|
||||
switch($item->getTier()){
|
||||
case TieredTool::TIER_WOODEN:
|
||||
$base /= 2;
|
||||
break;
|
||||
case TieredTool::TIER_STONE:
|
||||
$base /= 4;
|
||||
break;
|
||||
case TieredTool::TIER_IRON:
|
||||
$base /= 6;
|
||||
break;
|
||||
case TieredTool::TIER_DIAMOND:
|
||||
$base /= 8;
|
||||
break;
|
||||
case TieredTool::TIER_GOLD:
|
||||
$base /= 12;
|
||||
break;
|
||||
}
|
||||
$efficiency = $item->getMiningEfficiency($this);
|
||||
if($efficiency <= 0){
|
||||
throw new \RuntimeException("Item efficiency is invalid");
|
||||
}
|
||||
|
||||
if($item->isSword()){
|
||||
$base /= 1.5;
|
||||
}
|
||||
$base /= $efficiency;
|
||||
|
||||
return $base;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\ColorBlockMetaHelper;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Wool extends Solid{
|
||||
|
||||
@ -45,4 +46,12 @@ class Wool extends Solid{
|
||||
return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Wool";
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item) : float{
|
||||
$time = parent::getBreakTime($item);
|
||||
if($item->getBlockToolType() === BlockToolType::TYPE_SHEARS){
|
||||
$time *= 3; //shears break compatible blocks 15x faster, but wool 5x
|
||||
}
|
||||
|
||||
return $time;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user