
# store modifer numbers # 

# Max Health # [0] 
execute store result score InputHealth nl.Quality run data get entity @e[limit=1,type=minecraft:item,sort=nearest,nbt={Item:{tag:{nl_Quality:1b}}}] Item.tag.AttributeModifiers.[0].Amount 100

# Movement Speed # [1] 
execute store result score InputSpeed nl.Quality run data get entity @e[limit=1,type=minecraft:item,sort=nearest,nbt={Item:{tag:{nl_Quality:1b}}}] Item.tag.AttributeModifiers.[1].Amount 100

# Armor # [2]
execute store result score InputArmor nl.Quality run data get entity @e[limit=1,type=minecraft:item,sort=nearest,nbt={Item:{tag:{nl_Quality:1b}}}] Item.tag.AttributeModifiers.[2].Amount 100

# Mana # [3]
execute store result score InputMana nl.Quality run data get entity @e[limit=1,type=minecraft:item,sort=nearest,nbt={Item:{tag:{nl_Quality:1b}}}] Item.tag.AttributeModifiers.[3].Amount 100

    # Copy Armor # 
# Max Health # [0] 
execute store result score OutputHealth nl.Quality run data get entity @e[tag=nl_CopyArmor,limit=1,type=minecraft:item,distance=..1] Item.tag.AttributeModifiers.[0].Amount 100

# Movement Speed # [1] 
execute store result score OutputSpeed nl.Quality run data get entity @e[tag=nl_CopyArmor,limit=1,type=minecraft:item,distance=..1] Item.tag.AttributeModifiers.[1].Amount 100

# Armor # [2]
execute store result score OutputArmor nl.Quality run data get entity @e[tag=nl_CopyArmor,limit=1,type=minecraft:item,distance=..1] Item.tag.AttributeModifiers.[2].Amount 100

# Mana # [3]
execute store result score OutputMana nl.Quality run data get entity @e[tag=nl_CopyArmor,limit=1,type=minecraft:item,distance=..1] Item.tag.AttributeModifiers.[3].Amount 100

# add Debuff #

scoreboard players operation OutputHealth nl.Quality += InputHealth nl.Quality
scoreboard players operation OutputSpeed nl.Quality += InputSpeed nl.Quality
scoreboard players operation OutputArmor nl.Quality += InputArmor nl.Quality
scoreboard players operation OutputMana nl.Quality += InputMana nl.Quality

execute store result entity @e[type=item,limit=1,distance=..1,sort=nearest,tag=nl_CopyArmor] Item.tag.AttributeModifiers.[0].Amount double .01 run scoreboard players get OutputHealth nl.Quality
execute store result entity @e[type=item,limit=1,distance=..1,sort=nearest,tag=nl_CopyArmor] Item.tag.AttributeModifiers.[1].Amount double .01 run scoreboard players get OutputSpeed nl.Quality
execute store result entity @e[type=item,limit=1,distance=..1,sort=nearest,tag=nl_CopyArmor] Item.tag.AttributeModifiers.[2].Amount double .01 run scoreboard players get OutputArmor nl.Quality
execute store result entity @e[type=item,limit=1,distance=..1,sort=nearest,tag=nl_CopyArmor] Item.tag.AttributeModifiers.[3].Amount double .01 run scoreboard players get OutputMana nl.Quality

execute at @s run summon minecraft:area_effect_cloud ~ 250 ~ {NoGravity:1,Tags:["nl_FindAir"]}
execute as @e[tag=nl_FindAir] at @s run function next_level:quality/find_air

# Correct the Bonus Amount # 
function next_level:quality/find_amount_armor

# Write Debuff #
execute at @s run summon minecraft:armor_stand ~ ~ ~ {Small:1b,Marker:1b,Invisible:1b,Tags:["nl_QualityName"],CustomName:'{"text":" ","color":"blue","italic":false}'}
data modify entity @e[limit=1,tag=nl_QualityName] CustomName set from entity @e[limit=1,nbt={Item:{tag:{nl_Quality:1b}}}] Item.tag.display.Name
execute as @e[nbt={Item:{tag:{nl_Quality:1b}}}] at @e[tag=nl_FindAir] run setblock ~ ~-1 ~ minecraft:oak_sign{Text1:'["",{"text":"Quality: [","color":"dark_aqua","italic":false},{"selector":"@e[limit=1,tag=nl_QualityName]","color":"blue","italic":false},{"text":"]","color":"dark_aqua","italic":false}]',Text2:'["",{"text":" +","color":"blue","italic":false},{"score":{"name":"Whole","objective":"nl.Quality"},"color":"blue","italic":false},{"text":".","color":"blue","italic":false},{"score":{"name":"Decimal","objective":"nl.Quality"},"color":"blue","italic":false},{"selector":"@e[tag=nl_QualityArmor,limit=1]","color":"blue","italic":false}]',Text3:'["",{"text":" "}]',Text4:'["",{"text":"  ⚔ Minecraft:Next Level ⚔  ","color":"dark_gray","italic":false}]'}

data remove entity @e[tag=nl_CopyArmor,limit=1,type=minecraft:item,distance=..1] Item.tag.display.Lore[-1]
execute at @s as @e[tag=nl_CopyArmor,limit=1,sort=nearest] at @e[tag=nl_FindAir] run data modify entity @s Item.tag.display.Lore append from block ~ ~-1 ~ Text1
execute at @s as @e[tag=nl_CopyArmor,limit=1,sort=nearest] at @e[tag=nl_FindAir] run data modify entity @s Item.tag.display.Lore append from block ~ ~-1 ~ Text2
execute at @s as @e[tag=nl_CopyArmor,limit=1,sort=nearest] at @e[tag=nl_FindAir] run data modify entity @s Item.tag.display.Lore append from block ~ ~-1 ~ Text3
execute at @s as @e[tag=nl_CopyArmor,limit=1,sort=nearest] at @e[tag=nl_FindAir] run data modify entity @s Item.tag.display.Lore append from block ~ ~-1 ~ Text4

scoreboard players set OutputHealth nl.Quality 0
scoreboard players set OutputSpeed nl.Quality 0
scoreboard players set OutputArmor nl.Quality 0
scoreboard players set OutputMana nl.Quality 0
scoreboard players set InputHealth nl.Quality 0
scoreboard players set InputSpeed nl.Quality 0
scoreboard players set InputArmor nl.Quality 0
scoreboard players set InputMana nl.Quality 0

execute as @e[tag=nl_StoreEnchant,limit=1,sort=nearest] run data modify entity @e[tag=nl_CopyArmor,type=minecraft:item,limit=1] Item.tag.Enchantments set from entity @e[tag=nl_StoreEnchant,limit=1] HandItems.[0].tag.Enchantments
execute as @e[tag=nl_StoreEnchant,limit=1,sort=nearest] run data modify entity @e[tag=nl_CopyArmor,type=minecraft:item,limit=1] Item.tag.display.Name[0] insert 0 from entity @e[tag=nl_StoreEnchant,limit=1] HandItems.[0].tag.display.Name

data merge entity @e[tag=nl_CopyArmor,type=minecraft:item,limit=1] {Item:{tag:{nl_QualityCheck:1b}}}

execute at @e[tag=nl_FindAir] run setblock ~ ~-1 ~ minecraft:brown_shulker_box replace
execute at @e[tag=nl_FindAir] run data modify block ~ ~-1 ~ Items insert 0 from entity @e[type=item,tag=nl_CopyArmor,limit=1] Item
execute as @s[tag=nl_HandSlot] at @e[tag=nl_FindAir] run loot replace entity @s weapon.mainhand 1 mine ~ ~-1 ~ minecraft:stick{nl_contents:1b}
execute as @s[tag=nl_HeadSlot] at @e[tag=nl_FindAir] run loot replace entity @s armor.head 1 mine ~ ~-1 ~ minecraft:stick{nl_contents:1b}
execute as @s[tag=nl_ChestSlot] at @e[tag=nl_FindAir] run loot replace entity @s armor.chest 1 mine ~ ~-1 ~ minecraft:stick{nl_contents:1b}
execute as @s[tag=nl_LegsSlot] at @e[tag=nl_FindAir] run loot replace entity @s armor.legs 1 mine ~ ~-1 ~ minecraft:stick{nl_contents:1b}
execute as @s[tag=nl_FeetSlot] at @e[tag=nl_FindAir] run loot replace entity @s armor.feet 1 mine ~ ~-1 ~ minecraft:stick{nl_contents:1b}

execute at @e[tag=nl_FindAir] run setblock ~ ~-1 ~ air

tag @s remove nl_HeadSlot
tag @s remove nl_HandSlot
tag @s remove nl_ChestSlot
tag @s remove nl_LegsSlot
tag @s remove nl_FeetSlot
tag @s remove nl_SlotCheck

kill @e[tag=nl_FindAir]
kill @e[tag=nl_QualityArmor]
kill @e[tag=nl_QualityName]
kill @e[tag=nl_CopyArmor]
kill @e[nbt={Item:{tag:{nl_Quality:1b}}}]
kill @e[tag=nl_StoreEnchant]

