41 public const TAG_CUSTOM_COLOR =
"customColor";
45 protected ?
Color $customColor =
null;
51 parent::__construct($identifier, $name, $enchantmentTags);
52 $this->armorInfo = $info;
60 return $this->armorInfo->getDefensePoints();
67 return $this->armorInfo->getArmorSlot();
75 return $this->armorInfo->isFireProof();
79 return $this->armorInfo->getMaterial();
83 return $this->armorInfo->getMaterial()->getEnchantability();
90 return $this->customColor;
99 $this->customColor = $color;
105 $this->customColor = null;
117 $type = $enchantment->getType();
119 $epf += $type->getProtectionFactor($enchantment->getLevel());
126 protected function getUnbreakingDamageReduction(
int $amount) : int{
127 if(($unbreakingLevel = $this->getEnchantmentLevel(VanillaEnchantments::UNBREAKING())) > 0){
130 $chance = 1 / ($unbreakingLevel + 1);
131 for($i = 0; $i < $amount; ++$i){
132 if(mt_rand(1, 100) > 60 && lcg_value() > $chance){
144 $existing = $player->getArmorInventory()->getItem($this->getArmorSlot());
145 $thisCopy = clone $this;
146 $new = $thisCopy->pop();
147 $player->getArmorInventory()->setItem($this->getArmorSlot(), $new);
148 $player->getInventory()->setItemInHand($existing);
149 $sound = $new->getMaterial()->getEquipSound();
153 if(!$thisCopy->isNull()){
155 $returnedItems[] = $thisCopy;
157 return ItemUseResult::SUCCESS;
161 parent::deserializeCompoundTag($tag);
162 if(($colorTag = $tag->
getTag(self::TAG_CUSTOM_COLOR)) instanceof
IntTag){
163 $this->customColor = Color::fromARGB(Binary::unsignInt($colorTag->getValue()));
165 $this->customColor = null;
169 protected function serializeCompoundTag(
CompoundTag $tag) : void{
170 parent::serializeCompoundTag($tag);
171 $this->customColor !==
null ?
172 $tag->
setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($this->customColor->toARGB())) :