mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 00:29:54 +00:00
Remove Tool <-> Block circular dependency in efficiency calculation
This commit is contained in:
parent
72233a509d
commit
d961b272c7
@ -325,7 +325,7 @@ class Block extends Position implements BlockIds, Metadatable{
|
|||||||
$base *= 5;
|
$base *= 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
$efficiency = $item->getMiningEfficiency($this);
|
$efficiency = $item->getMiningEfficiency(($this->getToolType() & $item->getBlockToolType()) !== 0);
|
||||||
if($efficiency <= 0){
|
if($efficiency <= 0){
|
||||||
throw new \InvalidArgumentException(get_class($item) . " has invalid mining efficiency: expected >= 0, got $efficiency");
|
throw new \InvalidArgumentException(get_class($item) . " has invalid mining efficiency: expected >= 0, got $efficiency");
|
||||||
}
|
}
|
||||||
|
@ -726,7 +726,7 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMiningEfficiency(Block $block) : float{
|
public function getMiningEfficiency(bool $isCorrectTool) : float{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ class Sword extends TieredTool{
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMiningEfficiency(Block $block) : float{
|
public function getMiningEfficiency(bool $isCorrectTool) : float{
|
||||||
return parent::getMiningEfficiency($block) * 1.5; //swords break any block 1.5x faster than hand
|
return parent::getMiningEfficiency($isCorrectTool) * 1.5; //swords break any block 1.5x faster than hand
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getBaseMiningEfficiency() : float{
|
protected function getBaseMiningEfficiency() : float{
|
||||||
|
@ -23,7 +23,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\item;
|
namespace pocketmine\item;
|
||||||
|
|
||||||
use pocketmine\block\Block;
|
|
||||||
use pocketmine\item\enchantment\Enchantment;
|
use pocketmine\item\enchantment\Enchantment;
|
||||||
|
|
||||||
abstract class Tool extends Durable{
|
abstract class Tool extends Durable{
|
||||||
@ -32,9 +31,9 @@ abstract class Tool extends Durable{
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMiningEfficiency(Block $block) : float{
|
public function getMiningEfficiency(bool $isCorrectTool) : float{
|
||||||
$efficiency = 1;
|
$efficiency = 1;
|
||||||
if(($block->getToolType() & $this->getBlockToolType()) !== 0){
|
if($isCorrectTool){
|
||||||
$efficiency = $this->getBaseMiningEfficiency();
|
$efficiency = $this->getBaseMiningEfficiency();
|
||||||
if(($enchantmentLevel = $this->getEnchantmentLevel(Enchantment::EFFICIENCY())) > 0){
|
if(($enchantmentLevel = $this->getEnchantmentLevel(Enchantment::EFFICIENCY())) > 0){
|
||||||
$efficiency += ($enchantmentLevel ** 2 + 1);
|
$efficiency += ($enchantmentLevel ** 2 + 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user