# ---- Create marker -----
summon marker ^ ^ ^.5 {Tags:["ec_check","obj","unspellable","mrcd_bullet","mrcd_entity_targeted"]}

# Save speed and direction
execute as @e[type=marker,tag=ec_check,limit=1] store result score @s mrcd_x0 run data get entity @s Pos[0] 1000
execute as @e[type=marker,tag=ec_check,limit=1] store result score @s mrcd_y0 run data get entity @s Pos[1] 1000
execute as @e[type=marker,tag=ec_check,limit=1] store result score @s mrcd_z0 run data get entity @s Pos[2] 1000

execute store result score #var0 mrcd_system run data get entity @s Pos[0] 1000
execute store result score #var1 mrcd_system run data get entity @s Pos[1] 1000
execute store result score #var2 mrcd_system run data get entity @s Pos[2] 1000

scoreboard players operation @e[type=marker,tag=ec_check,limit=1] mrcd_x0 -= #var0 mrcd_system
scoreboard players operation @e[type=marker,tag=ec_check,limit=1] mrcd_y0 -= #var1 mrcd_system
scoreboard players operation @e[type=marker,tag=ec_check,limit=1] mrcd_z0 -= #var2 mrcd_system

execute at @s anchored eyes positioned ^ ^ ^ run tp @e[type=marker,tag=ec_check,limit=1] ~ ~ ~ ~ ~


# ---- Check -----
scoreboard players operation pos ec_calc = range ec_calc
execute as @e[type=marker,tag=ec_check,limit=1] at @s run function items:obj/electric_charge/electrocute/check
execute at @s anchored eyes run tp @s ~ ~ ~ ~ ~-4


# ---- Loop -----
scoreboard players remove rot_times ec_calc 1
execute if score rot_times ec_calc matches 1.. if entity @e[tag=mrcd_target,tag=!mrcd_target_entity,limit=1] at @s run function items:obj/electric_charge/electrocute/check_loop
