mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
Implemented armor durability
This commit is contained in:
@ -25,12 +25,13 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\item\enchantment\Enchantment;
|
||||
use pocketmine\item\enchantment\ProtectionEnchantment;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\Color;
|
||||
|
||||
abstract class Armor extends Item{
|
||||
abstract class Armor extends Durable{
|
||||
|
||||
public const TAG_CUSTOM_COLOR = "customColor"; //TAG_Int
|
||||
|
||||
@ -78,4 +79,21 @@ abstract class Armor extends Item{
|
||||
|
||||
return $epf;
|
||||
}
|
||||
|
||||
protected function getUnbreakingDamageReduction(int $amount) : int{
|
||||
if(($unbreakingLevel = $this->getEnchantmentLevel(Enchantment::UNBREAKING)) > 0){
|
||||
$negated = 0;
|
||||
|
||||
$chance = 1 / ($unbreakingLevel + 1);
|
||||
for($i = 0; $i < $amount; ++$i){
|
||||
if(mt_rand(1, 100) > 60 and lcg_value() > $chance){ //unbreaking only applies to armor 40% of the time at best
|
||||
$negated++;
|
||||
}
|
||||
}
|
||||
|
||||
return $negated;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user