scoreboard players add #global tickCounter 1
execute if score #global tickCounter matches 2 run scoreboard players set #global tickCounter 0

execute as @p at @s unless score @s particle_timeout matches 5.. run scoreboard players add @s particle_timeout 1
execute as @p at @s if score @s particle_timeout matches 5.. unless score @s hyperloop_timeout matches 40.. run scoreboard players set @s particle_timeout 0


execute as @p at @s unless score @s hyperloop_timeout matches 40.. run scoreboard players add @s hyperloop_timeout 1


# execute as @p at @s run function magnetism:get_player_motion
# execute as @p at @s run function magnetism:particles/particle_to_motion



execute as @e[type=minecraft:lightning_bolt,nbt=!{Tags:["processed"]}] run function magnetism:magnetick_magnetite



execute as @e[type=marker,tag=magnite] at @s unless block ~ ~ ~ minecraft:lodestone run function magnetism:magnite_block/break
execute as @e[type=marker,tag=antimagnite] at @s unless block ~ ~ ~ minecraft:lodestone run function magnetism:anti-magnite_block/break


execute as @p at @s if score @s particle_timeout matches -1..0 run function magnetism:get_player_motion
execute as @p at @s if score @s particle_timeout matches -1..0 unless score @s total_motion matches ..20000 run function magnetism:particles/particle_to_motion

execute unless score #global tickCounter matches 0 run return fail
# Считаем магниты
scoreboard players set @a magnets_count 0

# Перебираем магниты

# Технические работы


execute as @a at @s if score @s hyperloop_timeout matches 40.. as @e[type=marker,tag=magnite,distance=..32] at @s unless entity @e[type=marker, tag=hyperloop,distance=..32] run scoreboard players set @s magnet_id 1
execute as @a at @s if score @s hyperloop_timeout matches 40.. as @e[type=marker,tag=antimagnite,distance=..32] at @s unless entity @e[type=marker, tag=hyperloop,distance=..32] run scoreboard players set @s magnet_id 1
execute as @a at @s if score @s hyperloop_timeout matches 40.. as @e[type=marker,tag=hyperloop,distance=..32] at @s run scoreboard players set @s magnet_id 1


execute as @a at @s if entity @e[type=marker,tag=magnite,distance=..32,scores={magnet_id=1}] run scoreboard players add @s magnets_count 1
execute as @a at @s if entity @e[type=marker,tag=antimagnite,distance=..32,scores={magnet_id=1}] run scoreboard players add @s magnets_count 1
execute as @a at @s if entity @e[type=marker,tag=hyperloop,distance=..32,scores={magnet_id=1}] run scoreboard players add @s magnets_count 1

# Перебираем магниты
execute as @a at @s if score @s magnets_count matches 1.. run function magnetism:armor_check
execute as @a at @s as @e[type=marker,tag=magnite,distance=..32,scores={magnet_id=1}] run execute as @a at @s run function magnetism:pull_players
execute as @a at @s as @e[type=marker,tag=antimagnite,distance=..32,scores={magnet_id=1}] run execute as @a at @s run function magnetism:anti_pull_players
execute as @a at @s as @e[type=marker,tag=hyperloop,distance=..32,scores={magnet_id=1}] run execute as @a at @s run function magnetism:hyperloop_detect

# После всех — проверяем, было ли что-то
execute as @a at @s if score @s magnets_count matches 1.. run function magnetism:force_apply