scoreboard players set @s spell_cost_current 400
scoreboard players operation @s spell_cost_current /= @s mana_efficiency
execute if score @s magus_mana_bar < @s spell_cost_current run function kiwi2:upgrades/classes/magus/spells/not_enough_mana_warning

execute unless score @s magus_mana_bar < @s spell_cost_current run summon item_display ^ ^2 ^ {Tags:["magus_homing_spell","lightning_ball","lightning_ball_init","deviate_homing_speed"],teleport_duration:1,transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[-0.38f,-0.15f,0f,0.91f],translation:[0f,0f,0f],scale:[1.5f,1.5f,1.5f]},item:{id:"minecraft:player_head",count:1,components:{"minecraft:profile":{properties:[{name:"textures",value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjI1YmU4ZWZjYjFjNTAzODc5MTJhZTQ4ZTBiZGQwMGNjOWU3YzdjNWZkMjAwNzJkODI4ZTBlOTk5ZTQ4Zjg3ZSJ9fX0="}]}}}}

execute unless score @s magus_mana_bar < @s spell_cost_current run scoreboard players set @e[type=item_display,sort=nearest,tag=lightning_ball_init,limit=1] magus_homing_scoreboard 100
execute unless score @s magus_mana_bar < @s spell_cost_current run tp @e[type=item_display,sort=nearest,tag=lightning_ball_init,limit=1] ^ ^ ^-7 facing entity @s eyes
execute unless score @s magus_mana_bar < @s spell_cost_current run tp @e[type=item_display,sort=nearest,tag=lightning_ball_init,limit=1] ^ ^1 ^1
execute unless score @s magus_mana_bar < @s spell_cost_current run title @s actionbar [{"text": "[LIGHTNING BALL]","color": "#3bfff8","bold": true},{"text": " -","bold": false,"color": "red"},{"score": {"name": "@s","objective": "spell_cost_current"},"bold": false,"color": "red"},{"text": " Mana","bold": false,"color": "red"}]
execute unless score @s magus_mana_bar < @s spell_cost_current run tag @e[type=item_display,sort=nearest,tag=lightning_ball_init,limit=1] remove lightning_ball_init
execute unless score @s magus_mana_bar < @s spell_cost_current run function kiwi2:upgrades/classes/magus/spells/wand_stability
execute unless score @s magus_mana_bar < @s spell_cost_current run playsound minecraft:block.trial_spawner.spawn_item master @a[distance=..12] ~ ~ ~ 1 1
execute unless score @s magus_mana_bar < @s spell_cost_current run function kiwi2:upgrades/classes/magus/spells/magus_homing_spells_tick
execute unless score @s magus_mana_bar < @s spell_cost_current run scoreboard players operation @s magus_mana_bar -= @s spell_cost_current