mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 10:53:05 +00:00
Implement armor damage protection enchantments (#1839)
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user