Implement armor damage protection enchantments (#1839)

This commit is contained in:
Dylan K. Taylor
2018-01-24 10:13:24 +00:00
committed by GitHub
parent 6543d96910
commit 0df2064802
5 changed files with 162 additions and 4 deletions

View File

@ -24,6 +24,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\enchantment\ProtectionEnchantment;
use pocketmine\nbt\tag\IntTag;
use pocketmine\utils\Binary;
use pocketmine\utils\Color;
@ -55,4 +57,25 @@ abstract class Armor extends Item{
public function setCustomColor(Color $color) : void{
$this->setNamedTagEntry(new IntTag(self::TAG_CUSTOM_COLOR, Binary::signInt($color->toARGB())));
}
/**
* Returns the total enchantment protection factor this armour piece offers from all applicable protection
* enchantments on the item.
*
* @param EntityDamageEvent $event
*
* @return int
*/
public function getEnchantmentProtectionFactor(EntityDamageEvent $event) : int{
$epf = 0;
foreach($this->getEnchantments() as $enchantment){
$type = $enchantment->getType();
if($type instanceof ProtectionEnchantment and $type->isApplicable($event)){
$epf += $type->getProtectionFactor($enchantment->getLevel());
}
}
return $epf;
}
}