execute as @s run execute at @s run execute at @e[tag=!SaveMe,limit=1,distance=..5,nbt={Item:{id:"minecraft:diamond",Count:1b}}] run scoreboard players add @s ArmorToughStuff 50
execute at @s[scores={ArmorToughStuff=..501}] run kill @e[limit=1,type=item,distance=..5,nbt={Item:{id:"minecraft:diamond",Count:1b}},tag=!SaveMe]
execute as @s[scores={ArmorToughStuff=499..}] run scoreboard players set @s ArmorToughStuff 500
execute store result entity @s[tag=FoundArmorToughnessTag0] Item.tag.AttributeModifiers[0].Amount double 0.01 run scoreboard players get @s[tag=FoundArmorToughnessTag0,scores={ArmorToughStuff=1..}] ArmorToughStuff
execute store result entity @s[tag=FoundArmorToughnessTag1] Item.tag.AttributeModifiers[1].Amount double 0.01 run scoreboard players get @s[tag=FoundArmorToughnessTag1,scores={ArmorToughStuff=1..}] ArmorToughStuff
execute store result entity @s[tag=FoundArmorToughnessTag2] Item.tag.AttributeModifiers[2].Amount double 0.01 run scoreboard players get @s[tag=FoundArmorToughnessTag2,scores={ArmorToughStuff=1..}] ArmorToughStuff
execute store result entity @s[tag=FoundArmorToughnessTag3] Item.tag.AttributeModifiers[3].Amount double 0.01 run scoreboard players get @s[tag=FoundArmorToughnessTag3,scores={ArmorToughStuff=1..}] ArmorToughStuff
execute store result entity @s[tag=FoundArmorToughnessTag4] Item.tag.AttributeModifiers[4].Amount double 0.01 run scoreboard players get @s[tag=FoundArmorToughnessTag4,scores={ArmorToughStuff=1..}] ArmorToughStuff
execute store result entity @s[tag=FoundArmorToughnessTag5] Item.tag.AttributeModifiers[5].Amount double 0.01 run scoreboard players get @s[tag=FoundArmorToughnessTag5,scores={ArmorToughStuff=1..}] ArmorToughStuff
execute store result entity @s[tag=FoundArmorToughnessTag6] Item.tag.AttributeModifiers[6].Amount double 0.01 run scoreboard players get @s[tag=FoundArmorToughnessTag6,scores={ArmorToughStuff=1..}] ArmorToughStuff
execute store result entity @s[tag=FoundArmorToughnessTag7] Item.tag.AttributeModifiers[7].Amount double 0.01 run scoreboard players get @s[tag=FoundArmorToughnessTag7,scores={ArmorToughStuff=1..}] ArmorToughStuff
execute as @s[scores={ArmorToughStuff=501..}] run execute at @s run tag @e[distance=..5,nbt={Item:{id:"minecraft:diamond",Count:1b}}] add SaveMe
execute as @s run execute at @s run tag @e[distance=..5,nbt={Item:{id:"minecraft:diamond"}}] add DoMultiplesText
execute as @s run execute at @s run tag @e[distance=..5,nbt={Item:{id:"minecraft:diamond",Count:1b}}] remove DoMultiplesText
execute as @s[scores={ArmorToughStuff=499..501},nbt=!{Item:{tag:{maxtoughness:1b}}}] run tag @s add PlusQuarterArmor
execute as @s[tag=!NoMultiplesText] run execute at @s run execute if entity @e[distance=..5,type=item,tag=DoMultiplesText] run execute at @e[name=CadeyrnCrafting,sort=nearest,limit=1] run tellraw @a[distance=..10] ["",{"text":"In order to upgrade armor toughness, the diamonds must be placed in individual slots, one at a time!","color":"red","italic":true}]
execute as @s[scores={ArmorToughStuff=499..501},tag=!NoMoreToughText] run execute at @e[name=CadeyrnCrafting,sort=nearest,limit=1] run tellraw @a[distance=..10] ["",{"text":"Your diamond armor has hit 5 armor toughness, and cannot be upgraded further!","color":"gray","italic":true}]
execute as @s[scores={ArmorToughStuff=499..501}] run tag @s add NoMoreToughText
execute as @s[scores={ArmorToughStuff=499..501},nbt=!{Item:{tag:{maxtoughness:1b}}}] run function zzzzdonotuse:modifyarmor/addarmor
data modify entity @s[scores={ArmorToughStuff=499..},nbt=!{Item:{tag:{maxtoughness:1b}}}] Item.tag merge value {maxtoughness:1b}
tag @s add NoMultiplesText