Refactored tool efficiency handling

This fixes lots of bugs with things like wool, cobwebs, swords.
This commit is contained in:
Dylan K. Taylor
2017-12-12 12:42:33 +00:00
parent 99fe63b2a3
commit b903161a5d
7 changed files with 61 additions and 25 deletions

View File

@ -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;
}

View File

@ -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;
}
}