#count nearby mob spawns
scoreboard players set @s KyuDummy3 0
execute at @s run execute at @e[distance=..25,type=skeleton] run scoreboard players add @s KyuDummy3 1
execute at @s run execute at @e[distance=..25,type=wither_skeleton] run scoreboard players add @s KyuDummy3 1
execute at @s run execute at @e[distance=..25,type=stray] run scoreboard players add @s KyuDummy3 1

#summon a bunch of markers, to be spread out
summon marker ~ ~ ~ {Tags:["PirateSpawn2"]}
summon marker ~ ~ ~ {Tags:["PirateSpawn2"]}
summon marker ~ ~ ~ {Tags:["PirateSpawn2"]}


#spread the markers
execute at @s run execute as @e[type=marker,distance=..1,tag=PirateSpawn2] run function zzzzdonotuse:mobspawners/spawnerstuff/piratespawnerspreadcoord


#summon a marker, and generate a number between 0-9 to determine how many markers(from above) will spawn mobs, up to 1
summon marker ~ ~ ~ {Tags:["PirateSpawnNum"]}
execute at @s run execute store result score @s KyuDummy run data get entity @e[type=marker,distance=..1,tag=PirateSpawnNum,limit=1,sort=nearest] UUID[0] .1
scoreboard players set @s KyuDummy2 9
scoreboard players operation @s KyuDummy %= @s KyuDummy2

#100% chance to spawn 1 mob
##if KyuDummy3(nearby mob count) is more than 10, do not spawn any mobs
execute as @s[scores={KyuDummy3=11..}] run scoreboard players set @s KyuDummy -1000
execute at @s[scores={KyuDummy=0..10}] run tag @e[type=marker,distance=..10,tag=PirateSpawn2,limit=1,sort=random] add DoASpawn
#execute at @s[scores={KyuDummy=6..8}] run tag @e[type=marker,distance=..10,tag=PirateSpawn2,limit=2,sort=random] add DoASpawn
#execute at @s[scores={KyuDummy=9}] run tag @e[type=marker,distance=..10,tag=PirateSpawn2,limit=3,sort=random] add DoASpawn
execute at @s run kill @e[type=marker,distance=..1,sort=nearest,tag=PirateSpawnNum]


##I *would* have spread this out into another function, but eh

#generate random number(based on marker's UUID) between 0-23 to determine the mob spawn
execute at @s run execute as @e[type=marker,distance=..10,tag=PirateSpawn2,tag=DoASpawn] run execute at @s run execute store result score @s KyuDummy run data get entity @s UUID[0] .1
execute at @s run execute as @e[type=marker,distance=..10,tag=PirateSpawn2,tag=DoASpawn] run scoreboard players set @s KyuDummy2 24
execute at @s run execute as @e[type=marker,distance=..10,tag=PirateSpawn2,tag=DoASpawn] run scoreboard players operation @s KyuDummy %= @s KyuDummy2


#spawn the mob - 1/3 chance for each of stray/skele/wither skele, and a 75/25 split of swordsman/bowman
execute at @s run execute as @e[type=marker,distance=..10,tag=PirateSpawn2,tag=DoASpawn] run execute at @s[scores={KyuDummy=0..5}] run summon skeleton ~ ~ ~ {Tags:["KyuSpawnerMob","GKNameTag"],HandItems:[{id:"minecraft:iron_sword",Count:1b,tag:{Enchantments:[{id:"minecraft:knockback",lvl:2s}]}},{}],ArmorItems:[{},{},{},{id:"minecraft:iron_helmet",Count:1b,tag:{Enchantments:[{id:"minecraft:protection",lvl:2s}]}}]}
execute at @s run execute as @e[type=marker,distance=..10,tag=PirateSpawn2,tag=DoASpawn] run execute at @s[scores={KyuDummy=6..11}] run summon wither_skeleton ~ ~ ~ {Tags:["KyuSpawnerMob","GKNameTag"],HandItems:[{id:"minecraft:iron_sword",Count:1b,tag:{Enchantments:[{id:"minecraft:knockback",lvl:2s}]}},{}],ArmorItems:[{},{},{},{id:"minecraft:iron_helmet",Count:1b,tag:{Enchantments:[{id:"minecraft:protection",lvl:2s}]}}]}
execute at @s run execute as @e[type=marker,distance=..10,tag=PirateSpawn2,tag=DoASpawn] run execute at @s[scores={KyuDummy=12..17}] run summon stray ~ ~ ~ {Tags:["KyuSpawnerMob","GKNameTag"],HandItems:[{id:"minecraft:iron_sword",Count:1b,tag:{Enchantments:[{id:"minecraft:knockback",lvl:2s}]}},{}],ArmorItems:[{},{},{},{id:"minecraft:iron_helmet",Count:1b,tag:{Enchantments:[{id:"minecraft:protection",lvl:2s}]}}]}
execute at @s run execute as @e[type=marker,distance=..10,tag=PirateSpawn2,tag=DoASpawn] run execute at @s[scores={KyuDummy=18..19}] run summon skeleton ~ ~ ~ {Tags:["KyuSpawnerMob","GKNameTag"],HandItems:[{id:"minecraft:bow",Count:1b,tag:{Enchantments:[{id:"minecraft:punch",lvl:1s}]}},{}],ArmorItems:[{},{},{},{id:"minecraft:iron_helmet",Count:1b,tag:{Enchantments:[{id:"minecraft:protection",lvl:2s}]}}]}
execute at @s run execute as @e[type=marker,distance=..10,tag=PirateSpawn2,tag=DoASpawn] run execute at @s[scores={KyuDummy=20..21}] run summon wither_skeleton ~ ~ ~ {Tags:["KyuSpawnerMob","GKNameTag"],HandItems:[{id:"minecraft:bow",Count:1b,tag:{Enchantments:[{id:"minecraft:punch",lvl:1s}]}},{}],ArmorItems:[{},{},{},{id:"minecraft:iron_helmet",Count:1b,tag:{Enchantments:[{id:"minecraft:protection",lvl:2s}]}}]}
execute at @s run execute as @e[type=marker,distance=..10,tag=PirateSpawn2,tag=DoASpawn] run execute at @s[scores={KyuDummy=22..23}] run summon stray ~ ~ ~ {Tags:["KyuSpawnerMob","GKNameTag"],HandItems:[{id:"minecraft:bow",Count:1b,tag:{Enchantments:[{id:"minecraft:punch",lvl:1s}]}},{}],ArmorItems:[{},{},{},{id:"minecraft:iron_helmet",Count:1b,tag:{Enchantments:[{id:"minecraft:protection",lvl:2s}]}}]}



execute at @s run execute as @e[type=marker,distance=..10,tag=PirateSpawn2,tag=DoASpawn] run execute at @s run particle large_smoke ~ ~1 ~ 0.2 0.5 0.2 0.07 15 normal
#execute at @s run execute as @e[type=marker,distance=..10,tag=PirateSpawn2,tag=DoASpawn] run execute at @s run playsound minecraft:entity.wither_skeleton.ambient hostile @a[distance=..7] ~ ~ ~ 1 0.85
execute at @s run execute as @e[type=marker,distance=..10,tag=PirateSpawn2] run kill @s

# 1% chance to destroy the mob spawner and summon a live tnt
#execute if predicate suhc:1percent run tag @s add TimeToDielol
#execute at @s[tag=TimeToDielol] run setblock ~ ~ ~ air
#execute at @s[tag=TimeToDielol] run summon tnt ~ ~ ~ {Fuse:60}
#kill @s[tag=TimeToDielol]



