execute if entity @s[nbt={SelectedItem:{id:"minecraft:leather",components:{"minecraft:custom_data":{necromancer_leather_set_upgrade:1b}}}}] run function kiwi2:upgrades/classes/necromancer/summon_upgrades/armor/leather_armor
execute if entity @s[nbt={SelectedItem:{id:"minecraft:chain",components:{"minecraft:custom_data":{necromancer_chainmail_set_upgrade:1b}}}}] run function kiwi2:upgrades/classes/necromancer/summon_upgrades/armor/chainmail_armor
execute if entity @s[nbt={SelectedItem:{id:"minecraft:iron_ingot",components:{"minecraft:custom_data":{necromancer_iron_set_upgrade:1b}}}}] run function kiwi2:upgrades/classes/necromancer/summon_upgrades/armor/iron_armor
execute if entity @s[nbt={SelectedItem:{id:"minecraft:gold_ingot",components:{"minecraft:custom_data":{necromancer_golden_set_upgrade:1b}}}}] run function kiwi2:upgrades/classes/necromancer/summon_upgrades/armor/golden_armor
execute if entity @s[nbt={SelectedItem:{id:"minecraft:diamond",components:{"minecraft:custom_data":{necromancer_diamond_set_upgrade:1b}}}}] run function kiwi2:upgrades/classes/necromancer/summon_upgrades/armor/diamond_armor
execute if entity @s[nbt={SelectedItem:{id:"minecraft:netherite_ingot",components:{"minecraft:custom_data":{necromancer_netherite_set_upgrade:1b}}}}] run function kiwi2:upgrades/classes/necromancer/summon_upgrades/armor/netherite_armor

execute at @n[distance=..3,limit=1,tag=necromancer_summon,tag=!necromancer_summon_unwieldy] run particle crit ~ ~1 ~ 0.3 0.8 0.3 0.3 50
execute at @n[distance=..3,limit=1,tag=necromancer_summon,tag=!necromancer_summon_unwieldy] run particle end_rod ~ ~1 ~ 0.3 0.8 0.3 0.1 15

execute unless entity @n[distance=..3,limit=1,tag=necromancer_summon,tag=!necromancer_summon_unwieldy] run title @s actionbar {"color":"red", "text": "No valid summons nearby!"}
execute unless entity @n[distance=..3,limit=1,tag=necromancer_summon,tag=!necromancer_summon_unwieldy] run playsound entity.arrow.hit_player master @s ~ ~ ~ 1 0.5

execute if entity @s[nbt={SelectedItem:{id:"minecraft:leather",components:{"minecraft:custom_data":{necromancer_leather_set_upgrade:1b}}}}] unless entity @n[distance=..3,limit=1,tag=necromancer_summon] run give @s minecraft:leather[minecraft:custom_name='{"italic":false,"text":"[ Leather Set Upgrade ]"}',minecraft:lore=['{"color":"gray","italic":false,"text":"[","extra":[{"color":"dark_green","bold":false,"italic":false,"keybind":"key.use"},{"color":"gray","italic":false,"text":"] on a summon to equip it with an leather armor set."}]}','{"text":""}','{"color":"#d79e2b","italic":false,"text":"[ STAT ] ","extra":[{"color":"white","bold":false,"italic":false,"text":"+7 Armor"}]}','{"text":""}','{"color":"gray","italic":false,"text":"Overrides any existing worn armor."}'],minecraft:rarity=uncommon,minecraft:enchantment_glint_override=true,minecraft:custom_data={necromancer_leather_set_upgrade:1b,necromancer_armor_upgrade:1b},minecraft:consumable={consume_seconds:0,animation:none,sound:"minecraft:item.armor.equip_leather",has_consume_particles:false}] 1
execute if entity @s[nbt={SelectedItem:{id:"minecraft:chain",components:{"minecraft:custom_data":{necromancer_chainmail_set_upgrade:1b}}}}] unless entity @n[distance=..3,limit=1,tag=necromancer_summon] run give @s minecraft:chain[minecraft:custom_name='{"italic":false,"text":"[ Chainmail Set Upgrade ]"}',minecraft:lore=['{"color":"gray","italic":false,"text":"[","extra":[{"color":"dark_green","bold":false,"italic":false,"keybind":"key.use"},{"color":"gray","italic":false,"text":"] on a summon to equip it with an chainmail armor set."}]}','{"text":""}','{"color":"#d79e2b","italic":false,"text":"[ STAT ] ","extra":[{"color":"white","bold":false,"italic":false,"text":"+12 Armor"}]}','{"text":""}','{"color":"gray","italic":false,"text":"Overrides any existing worn armor."}'],minecraft:rarity=uncommon,minecraft:enchantment_glint_override=true,minecraft:custom_data={necromancer_chainmail_set_upgrade:1b,necromancer_armor_upgrade:1b},minecraft:consumable={consume_seconds:0,animation:none,sound:"minecraft:item.armor.equip_chain",has_consume_particles:false}] 1
execute if entity @s[nbt={SelectedItem:{id:"minecraft:iron_ingot",components:{"minecraft:custom_data":{necromancer_iron_set_upgrade:1b}}}}] unless entity @n[distance=..3,limit=1,tag=necromancer_summon] run give @s minecraft:iron_ingot[minecraft:custom_name='{"italic":false,"text":"[ Iron Set Upgrade ]"}',minecraft:lore=['{"color":"gray","italic":false,"text":"[","extra":[{"color":"dark_green","bold":false,"italic":false,"keybind":"key.use"},{"color":"gray","italic":false,"text":"] on a summon to equip it with an iron armor set."}]}','{"text":""}','{"color":"#d79e2b","italic":false,"text":"[ STAT ] ","extra":[{"color":"white","bold":false,"italic":false,"text":"+15 Armor"}]}','{"text":""}','{"color":"gray","italic":false,"text":"Overrides any existing worn armor."}'],minecraft:rarity=uncommon,minecraft:enchantment_glint_override=true,minecraft:custom_data={necromancer_iron_set_upgrade:1b,necromancer_armor_upgrade:1b},minecraft:consumable={consume_seconds:0,animation:none,sound:"minecraft:item.armor.equip_iron",has_consume_particles:false}] 1
execute if entity @s[nbt={SelectedItem:{id:"minecraft:gold_ingot",components:{"minecraft:custom_data":{necromancer_golden_set_upgrade:1b}}}}] unless entity @n[distance=..3,limit=1,tag=necromancer_summon] run give @s minecraft:gold_ingot[minecraft:custom_name='{"italic":false,"text":"[ Golden Set Upgrade ]"}',minecraft:lore=['{"color":"gray","italic":false,"text":"[","extra":[{"color":"dark_green","bold":false,"italic":false,"keybind":"key.use"},{"color":"gray","italic":false,"text":"] on a summon to equip it with an golden armor set."}]}','{"text":""}','{"color":"#d79e2b","italic":false,"text":"[ STAT ] ","extra":[{"color":"white","bold":false,"italic":false,"text":"+11 Armor"}]}','{"text":""}','{"color":"gray","italic":false,"text":"Overrides any existing worn armor."}'],minecraft:rarity=uncommon,minecraft:enchantment_glint_override=true,minecraft:custom_data={necromancer_golden_set_upgrade:1b,necromancer_armor_upgrade:1b},minecraft:consumable={consume_seconds:0,animation:none,sound:"minecraft:item.armor.equip_gold",has_consume_particles:false}] 1
execute if entity @s[nbt={SelectedItem:{id:"minecraft:diamond",components:{"minecraft:custom_data":{necromancer_diamond_set_upgrade:1b}}}}] unless entity @n[distance=..3,limit=1,tag=necromancer_summon] run give @s minecraft:diamond[minecraft:custom_name='{"italic":false,"text":"[ Diamond Set Upgrade ]"}',minecraft:lore=['{"color":"gray","italic":false,"text":"[","extra":[{"color":"dark_green","bold":false,"italic":false,"keybind":"key.use"},{"color":"gray","italic":false,"text":"] on a summon to equip it with an diamond armor set."}]}','{"text":""}','{"color":"#d79e2b","italic":false,"text":"[ STAT ] ","extra":[{"color":"white","bold":false,"italic":false,"text":"+20 Armor"}]}','{"color":"#d79e2b","italic":false,"text":"[ STAT ] ","extra":[{"color":"dark_gray","bold":false,"italic":false,"text":"+8 Armor Toughness"}]}','{"text":""}','{"color":"gray","italic":false,"text":"Overrides any existing worn armor."}'],minecraft:rarity=rare,minecraft:enchantment_glint_override=true,minecraft:custom_data={necromancer_diamond_set_upgrade:1b,necromancer_armor_upgrade:1b},minecraft:consumable={consume_seconds:0,animation:none,sound:"minecraft:item.armor.equip_diamond",has_consume_particles:false}] 1
execute if entity @s[nbt={SelectedItem:{id:"minecraft:netherite_ingot",components:{"minecraft:custom_data":{necromancer_netherite_set_upgrade:1b}}}}] unless entity @n[distance=..3,limit=1,tag=necromancer_summon] run give @s minecraft:netherite_ingot[minecraft:custom_name='{"italic":false,"text":"[ Netherite Set Upgrade ]"}',minecraft:lore=['{"color":"gray","italic":false,"text":"[","extra":[{"color":"dark_green","bold":false,"italic":false,"keybind":"key.use"},{"color":"gray","italic":false,"text":"] on a summon to equip it with an netherite armor set."}]}','{"text":""}','{"color":"#d79e2b","italic":false,"text":"[ STAT ] ","extra":[{"color":"white","bold":false,"italic":false,"text":"+20 Armor"}]}','{"color":"#d79e2b","italic":false,"text":"[ STAT ] ","extra":[{"color":"dark_gray","bold":false,"italic":false,"text":"+12 Armor Toughness"}]}','{"color":"#d79e2b","italic":false,"text":"[ STAT ] ","extra":[{"color":"gray","bold":false,"italic":false,"text":"+0.4 Knockback Resistance"}]}','{"text":""}','{"color":"gray","italic":false,"text":"Overrides any existing worn armor."}'],minecraft:rarity=epic,minecraft:enchantment_glint_override=true,minecraft:custom_data={necromancer_netherite_set_upgrade:1b,necromancer_armor_upgrade:1b},minecraft:consumable={consume_seconds:0,animation:none,sound:"minecraft:item.armor.equip_netherite",has_consume_particles:false}] 1

advancement revoke @s only kiwi2:necromancer_upgrades_armor