mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Refactored tool efficiency handling
This fixes lots of bugs with things like wool, cobwebs, swords.
This commit is contained in:
parent
99fe63b2a3
commit
b903161a5d
@ -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;
|
||||
}
|
||||
}
|
@ -789,7 +789,7 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDestroySpeed(Block $block, Player $player){
|
||||
public function getMiningEfficiency(Block $block) : float{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
|
||||
use pocketmine\block\BlockToolType;
|
||||
|
||||
class Shears extends Tool{
|
||||
@ -46,4 +45,8 @@ class Shears extends Tool{
|
||||
public function getBlockToolHarvestLevel() : int{
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected function getBaseMiningEfficiency() : float{
|
||||
return 15;
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockToolType;
|
||||
|
||||
class Sword extends TieredTool{
|
||||
@ -42,4 +43,12 @@ class Sword extends TieredTool{
|
||||
public function getBlockToolHarvestLevel() : int{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function getMiningEfficiency(Block $block) : float{
|
||||
return parent::getMiningEfficiency($block) * 1.5; //swords break any block 1.5x faster than hand
|
||||
}
|
||||
|
||||
protected function getBaseMiningEfficiency() : float{
|
||||
return 10;
|
||||
}
|
||||
}
|
@ -77,4 +77,24 @@ abstract class TieredTool extends Tool{
|
||||
|
||||
return $levels[$tier];
|
||||
}
|
||||
|
||||
public static function getBaseMiningEfficiencyFromTier(int $tier) : float{
|
||||
static $levels = [
|
||||
self::TIER_WOODEN => 2,
|
||||
self::TIER_STONE => 4,
|
||||
self::TIER_IRON => 6,
|
||||
self::TIER_DIAMOND => 8,
|
||||
self::TIER_GOLD => 12
|
||||
];
|
||||
|
||||
if(!isset($levels[$tier])){
|
||||
throw new \InvalidArgumentException("Unknown tier '$tier'");
|
||||
}
|
||||
|
||||
return $levels[$tier];
|
||||
}
|
||||
|
||||
protected function getBaseMiningEfficiency() : float{
|
||||
return self::getBaseMiningEfficiencyFromTier($this->tier);
|
||||
}
|
||||
}
|
@ -66,4 +66,18 @@ abstract class Tool extends Durable{
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getMiningEfficiency(Block $block) : float{
|
||||
$efficiency = 1;
|
||||
if(($block->getToolType() & $this->getBlockToolType()) !== 0){
|
||||
$efficiency = $this->getBaseMiningEfficiency();
|
||||
//TODO: check Efficiency enchantment
|
||||
}
|
||||
|
||||
return $efficiency;
|
||||
}
|
||||
|
||||
protected function getBaseMiningEfficiency() : float{
|
||||
return 1;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user