
execute as @p[distance=..10,tag=interact_temp] run function fjam:map/game/upgrader/use_chip

execute if entity @n[nbt={item:{id:"minecraft:barrier",count:1}},tag=upgrader_item,distance=..2] run return 0

execute unless score #energy_core game_ matches 1.. run return run function fjam:map/game/upgrader/not_enough_energy_cores
scoreboard players remove #energy_core game_ 1
data merge entity @n[tag=energy_vault_text_num] {text:[{"bold":true,"color":"yellow","italic":false,"text":"Cores: "},{"score":{"name":"#energy_core","objective":"game_"}}]}

execute store result score @s loops_til_upgrade run data get entity @n[tag=upgrader_item] item.components."minecraft:custom_data".ltu
execute store result entity @n[tag=upgrader_item] item.components."minecraft:custom_data".ltu int 1 run scoreboard players remove @s loops_til_upgrade 1

execute if score @s loops_til_upgrade matches ..0 store result score #temp loops_til_upgrade run data get entity @n[tag=upgrader_item] item.components."minecraft:custom_data".lvl
execute if score @s loops_til_upgrade matches ..0 store result entity @n[tag=upgrader_item] item.components."minecraft:custom_data".lvl int 1 run scoreboard players add #temp loops_til_upgrade 5


data modify storage jm:temp upgrader.name set from entity @n[tag=upgrader_item] item.components."minecraft:custom_data".name
data modify storage jm:temp upgrader.lvl set from entity @n[tag=upgrader_item] item.components."minecraft:custom_data".lvl
data modify storage jm:temp upgrader.mltu set from entity @n[tag=upgrader_item] item.components."minecraft:custom_data".mltu
data modify storage jm:temp upgrader.ltu set from entity @n[tag=upgrader_item] item.components."minecraft:custom_data".ltu


execute if score @s loops_til_upgrade matches ..0 run function fjam:map/game/upgrader/power/tell_upgrade with storage jm:temp upgrader

execute if score @s loops_til_upgrade matches ..0 store result score #max_ltu loops_til_upgrade run data get entity @n[tag=upgrader_item] item.components."minecraft:custom_data".mltu
execute if score @s loops_til_upgrade matches ..0 store result entity @n[tag=upgrader_item] item.components."minecraft:custom_data".ltu int 1 run scoreboard players get #max_ltu loops_til_upgrade
execute if score @s loops_til_upgrade matches ..0 store result storage jm:temp upgrader.ltu int 1 run scoreboard players get #max_ltu loops_til_upgrade

function fjam:map/game/upgrader/power/set_name with storage jm:temp upgrader
