## Runs from 'animation.player.enderman_spawn_clock' on loop for entirety of game
## @s = player

scoreboard objectives add MainIslandClock dummy
scoreboard objectives add BeastClock dummy
scoreboard objectives add MysticClock dummy
scoreboard objectives add ScourgeClock dummy
scoreboard objectives add WraithClock dummy
scoreboard objectives add WorldSpawnClock dummy

scoreboard players add @s MainIslandClock 1
scoreboard players add @s BeastClock 1
scoreboard players add @s MysticClock 1
scoreboard players add @s ScourgeClock 1
scoreboard players add @s WraithClock 1
scoreboard players add @s WorldSpawnClock 1

####################################################
## SEPARATED FOR EASE OF ADJUSTMENT
function player/spawning/set_seconds_between_spawn
####################################################

execute as @s[scores={SpawnMainIsland=1},x=104,y=117,z=31,r=100] run function player/spawning/tally_main_island_cap
execute as @s[scores={SpawnBeast=1},x=95,y=153,z=-467,r=100] run function player/spawning/tally_beast_cap
execute as @s[scores={SpawnMystic=1},x=-536,y=172,z=-173,r=100] run function player/spawning/tally_mystic_cap
execute as @s[scores={SpawnScourge=1},x=23,y=165,z=435,r=100] run function player/spawning/tally_scourge_cap
execute as @s[scores={SpawnWraith=1},x=565,y=165,z=50,r=100] run function player/spawning/tally_wraith_cap

####################################################
## SEPARATED FOR EASE OF ADJUSTMENT
function player/spawning/set_spawn_per_player
####################################################

tag @s remove MainIsland
tag @s remove BeastDungeon
tag @s remove MysticDungeon
tag @s remove ScourgeDungeon
tag @s remove WraithDungeon

scoreboard players set @s[scores={SpawnMainIsland=1..}] MainIslandClock 0
scoreboard players reset @s[scores={SpawnMainIsland=1..}] SpawnMainIsland

scoreboard players set @s[scores={SpawnBeast=1..}] BeastClock 0
scoreboard players reset @s[scores={SpawnBeast=1..}] SpawnBeast

scoreboard players set @s[scores={SpawnMystic=1..}] MysticClock 0
scoreboard players reset @s[scores={SpawnMystic=1..}] SpawnMystic

scoreboard players set @s[scores={SpawnScourge=1..}] ScourgeClock 0
scoreboard players reset @s[scores={SpawnScourge=1..}] SpawnScourge

scoreboard players set @s[scores={SpawnWraith=1..}] WraithClock 0
scoreboard players reset @s[scores={SpawnWraith=1..}] SpawnWraith

####################################################
# Passive World Enderman Spawning
# (.period set in player/spawning/set_seconds_between_spawn)
execute as @s[tag=!InEnd] if score @s WorldSpawnClock > .period WorldSpawnClock run function player/spawning/world_endermen/spawn

execute as @s[tag=dev] run say enderman spawn clock running
