# Store Attribute Modifiers # 
    # Quality Loot Table #
        # Attack Damage # [0] 
execute store result score InputDamage 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
        # Attack 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
    # Copy of tool # 
        # Attack Damage # [0] 
execute store result score OutputDamage nl.Quality run data get entity @e[tag=nl_CopyTool,limit=1,type=minecraft:item,distance=..1] Item.tag.AttributeModifiers.[0].Amount 100
        # Attack Speed # [1] 
execute store result score OutputSpeed nl.Quality run data get entity @e[tag=nl_CopyTool,limit=1,type=minecraft:item,distance=..1] Item.tag.AttributeModifiers.[1].Amount 100

# Set Scores to equal Attribute changes # 
scoreboard players operation OutputDamage nl.Quality += InputDamage nl.Quality
scoreboard players operation OutputSpeed nl.Quality += InputSpeed nl.Quality

# Store Result of Attribute changes back in copy of tool # 
execute store result entity @e[type=item,limit=1,distance=..1,sort=nearest,tag=nl_CopyTool] Item.tag.AttributeModifiers.[0].Amount double .01 run scoreboard players get OutputDamage nl.Quality
execute store result entity @e[type=item,limit=1,distance=..1,sort=nearest,tag=nl_CopyTool] Item.tag.AttributeModifiers.[1].Amount double .01 run scoreboard players get OutputSpeed nl.Quality

# Find air for sign to write Lore # 
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 to be written # 
function next_level:quality/find_amount_tool

# Write new Attribute change to sign #
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_QualityTool,limit=1]","color":"blue","italic":false}]',Text3:'["",{"text":" "}]',Text4:'["",{"text":"  ⚔ Minecraft:Next Level ⚔  ","color":"dark_gray","italic":false}]'}

# Modify Lore from sign # 
data remove entity @e[tag=nl_CopyTool,limit=1,type=minecraft:item,distance=..1] Item.tag.display.Lore[-1]
execute at @s as @e[tag=nl_CopyTool,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_CopyTool,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_CopyTool,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_CopyTool,limit=1,sort=nearest] at @e[tag=nl_FindAir] run data modify entity @s Item.tag.display.Lore append from block ~ ~-1 ~ Text4

# Reset Stored Modifiers #
scoreboard players set OutputDamage nl.Quality 0
scoreboard players set OutputSpeed nl.Quality 0
scoreboard players set InputDamage nl.Quality 0
scoreboard players set InputSpeed nl.Quality 0

# Re-add Stored Enchantments and Custom Name#
execute as @e[tag=nl_StoreEnchant,limit=1,sort=nearest] run data modify entity @e[tag=nl_CopyTool,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_CopyTool,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

# Add check to stop re-processing #
data merge entity @e[tag=nl_CopyTool,type=minecraft:item,limit=1] {Item:{tag:{nl_QualityCheck:1b}}}

# Set item in shulker box to replace player Selected Item # 
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_CopyTool,limit=1] Item
execute at @e[tag=nl_FindAir] run loot replace entity @s weapon.mainhand 1 mine ~ ~-1 ~ minecraft:stick{nl_contents:1b}

# Clear sign, entities etc. # 
execute at @e[tag=nl_FindAir] run setblock ~ ~-1 ~ air
kill @e[tag=nl_FindAir]
kill @e[tag=nl_QualityTool]
kill @e[tag=nl_QualityName]
kill @e[tag=nl_CopyTool]
kill @e[nbt={Item:{tag:{nl_Quality:1b}}}]
kill @e[tag=nl_StoreEnchant]
