Implemented armor durability

This commit is contained in:
Dylan K. Taylor
2018-03-09 13:21:05 +00:00
parent 74cff89df3
commit e06b78b0ee
22 changed files with 123 additions and 1 deletions

View File

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