armorInfo = $info; } public function getMaxDurability() : int{ return $this->armorInfo->getMaxDurability(); } public function getDefensePoints() : int{ return $this->armorInfo->getDefensePoints(); } /** * @see ArmorInventory * @return int */ abstract public function getArmorSlot() : int; public function getMaxStackSize() : int{ return 1; } /** * Returns the dyed colour of this armour piece. This generally only applies to leather armour. * @return Color|null */ public function getCustomColor() : ?Color{ if($this->getNamedTag()->hasTag(self::TAG_CUSTOM_COLOR, IntTag::class)){ return Color::fromARGB(Binary::unsignInt($this->getNamedTag()->getInt(self::TAG_CUSTOM_COLOR))); } return null; } /** * Sets the dyed colour of this armour piece. This generally only applies to leather armour. * * @param Color $color * * @return $this */ public function setCustomColor(Color $color) : self{ $this->getNamedTag()->setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($color->toARGB())); return $this; } /** * 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; } 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; } public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : ItemUseResult{ $existing = $player->getArmorInventory()->getItem($this->getArmorSlot()); if(!$existing->isNull()){ return ItemUseResult::FAIL(); } $player->getArmorInventory()->setItem($this->getArmorSlot(), $this->pop()); return ItemUseResult::SUCCESS(); } }