
execute unless data entity @n[tag=upgrader_item] item.components."minecraft:custom_data"{cap_lvl:5} 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 if score @s loops_til_upgrade matches ..0 store result score #temp_cap loops_til_upgrade run data get entity @n[tag=upgrader_item] item.components."minecraft:custom_data".cap_lvl
execute if score #temp_cap loops_til_upgrade matches 5 run return run function fjam:map/game/upgrader/capacity/say_maxed

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 3
execute if score @s loops_til_upgrade matches ..0 store result entity @n[tag=upgrader_item] item.components."minecraft:custom_data".cap_lvl int 1 run scoreboard players add #temp_cap loops_til_upgrade 1

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
data modify storage jm:temp upgrader.cap_lvl set from entity @n[tag=upgrader_item] item.components."minecraft:custom_data".cap_lvl

execute if score @s loops_til_upgrade matches ..0 run function fjam:map/game/upgrader/capacity/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/capacity/set_name with storage jm:temp upgrader
