## Run by ldz:magic_barrier
## Runs from animation.magic_barrier.duplication_check

#scoreboard objectives setdisplay sidebar MagicBarrier

execute as @s[family=portal_room_barrier] run scoreboard players add @e[family=portal_room_barrier] MagicBarrier 0
execute as @s[family=beast_hub_barrier] run scoreboard players add @e[family=beast_hub_barrier] MagicBarrier 0
execute as @s[family=mystic_hub_barrier] run scoreboard players add @e[family=mystic_hub_barrier] MagicBarrier 0
execute as @s[family=scourge_hub_barrier] run scoreboard players add @e[family=scourge_hub_barrier] MagicBarrier 0
execute as @s[family=wraith_hub_barrier] run scoreboard players add @e[family=wraith_hub_barrier] MagicBarrier 0
execute as @s[family=beast_dungeon_barrier] run scoreboard players add @e[family=beast_dungeon_barrier] MagicBarrierDB 0
execute as @s[family=mystic_dungeon_barrier] run scoreboard players add @e[family=mystic_dungeon_barrier] MagicBarrierDM 0
execute as @s[family=scourge_dungeon_barrier] run scoreboard players add @e[family=scourge_dungeon_barrier] MagicBarrierDS 0
execute as @s[family=wraith_dungeon_barrier] run scoreboard players add @e[family=wraith_dungeon_barrier] MagicBarrierDW 0

execute as @e[type=ldz:magic_barrier,scores={MagicBarrier=0}] run event entity @s despawn
execute as @e[type=ldz:magic_barrier,scores={MagicBarrierDB=0}] run event entity @s despawn
execute as @e[type=ldz:magic_barrier,scores={MagicBarrierDM=0}] run event entity @s despawn
execute as @e[type=ldz:magic_barrier,scores={MagicBarrierDS=0}] run event entity @s despawn
execute as @e[type=ldz:magic_barrier,scores={MagicBarrierDW=0}] run event entity @s despawn

scoreboard players add @s[scores={MagicBarrier=1..}] MagicBarrier 1
scoreboard players add @s[scores={MagicBarrierDB=1..}] MagicBarrierDB 1
scoreboard players add @s[scores={MagicBarrierDM=1..}] MagicBarrierDM 1
scoreboard players add @s[scores={MagicBarrierDS=1..}] MagicBarrierDS 1
scoreboard players add @s[scores={MagicBarrierDW=1..}] MagicBarrierDW 1

execute as @s[scores={MagicBarrier=3..}] run event entity @s remove_duplication_check_toggle
execute as @s[scores={MagicBarrierDB=3..}] run event entity @s remove_duplication_check_toggle
execute as @s[scores={MagicBarrierDM=3..}] run event entity @s remove_duplication_check_toggle
execute as @s[scores={MagicBarrierDS=3..}] run event entity @s remove_duplication_check_toggle
execute as @s[scores={MagicBarrierDW=3..}] run event entity @s remove_duplication_check_toggle

execute at @s[family=portal_room_barrier] run fill ~-1 ~ ~ ~1 ~2 ~ ldz:tinted_barrier_z
execute at @s[family=beast_hub_barrier] run fill ~-1 ~ ~ ~1 ~2 ~ ldz:tinted_barrier_neg_z
execute at @s[family=mystic_hub_barrier] run fill ~ ~ ~-1 ~ ~2 ~1 ldz:tinted_barrier_neg_x
execute at @s[family=scourge_hub_barrier] run fill ~-1 ~ ~ ~1 ~2 ~ ldz:tinted_barrier_pos_z
execute at @s[family=wraith_hub_barrier] run fill ~ ~ ~-1 ~ ~2 ~1 ldz:tinted_barrier_pos_x

execute at @s[family=beast_dungeon_barrier] run fill ~-1 ~ ~ ~1 ~2 ~ ldz:tinted_barrier_z
execute at @s[family=mystic_dungeon_barrier] run fill ~ ~ ~-1 ~ ~2 ~1 ldz:tinted_barrier_x
execute at @s[family=scourge_dungeon_barrier] run fill ~ ~ ~-1 ~ ~2 ~1 ldz:tinted_barrier_x
execute at @s[family=wraith_dungeon_barrier] run fill ~ ~ ~-1 ~ ~2 ~1 ldz:tinted_barrier_x