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

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

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


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

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


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

#generate random number(based on marker's UUID) between 0-21 to determine the mob spawn
execute at @s run execute as @e[type=marker,distance=..10,tag=StalagSpawn2,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=StalagSpawn2,tag=DoASpawn] run scoreboard players set @s KyuDummy2 22
execute at @s run execute as @e[type=marker,distance=..10,tag=StalagSpawn2,tag=DoASpawn] run scoreboard players operation @s KyuDummy %= @s KyuDummy2

#spawn the mob
execute at @s run execute as @e[type=marker,distance=..10,tag=StalagSpawn2,tag=DoASpawn] run execute at @s[scores={KyuDummy=0..4}] run summon wither_skeleton ~ ~ ~ {Tags:["KyuSpawnerMob"],HandItems:[{id:"minecraft:stone_axe",Count:1b},{}],ArmorItems:[{id:"minecraft:chainmail_boots",Count:1b},{id:"minecraft:chainmail_leggings",Count:1b},{id:"minecraft:chainmail_chestplate",Count:1b},{id:"minecraft:leather_helmet",Count:1b}],ArmorDropChances:[0.025F,0.025F,0.025F,0.025F]}
execute at @s run execute as @e[type=marker,distance=..10,tag=StalagSpawn2,tag=DoASpawn] run execute at @s[scores={KyuDummy=5..6}] run summon cave_spider ~ ~ ~ {Tags:["KyuSpawnerMob"],Attributes:[{Name:generic.armor,Base:5}]}
execute at @s run execute as @e[type=marker,distance=..10,tag=StalagSpawn2,tag=DoASpawn] run execute at @s[scores={KyuDummy=7..11}] run summon zombie ~ ~ ~ {Tags:["KyuSpawnerMob"],HandItems:[{id:"minecraft:stone_axe",Count:1b},{}],ArmorItems:[{id:"minecraft:chainmail_boots",Count:1b},{id:"minecraft:chainmail_leggings",Count:1b},{id:"minecraft:chainmail_chestplate",Count:1b},{id:"minecraft:leather_helmet",Count:1b}],ArmorDropChances:[0.025F,0.025F,0.025F,0.025F]}
execute at @s run execute as @e[type=marker,distance=..10,tag=StalagSpawn2,tag=DoASpawn] run execute at @s[scores={KyuDummy=12..16}] run summon skeleton ~ ~ ~ {Tags:["KyuSpawnerMob"],HandItems:[{id:"minecraft:bow",Count:1b,tag:{Enchantments:[{id:"minecraft:power",lvl:1s}]}},{}],ArmorItems:[{id:'minecraft:chainmail_boots',Count:1b},{id:'minecraft:chainmail_leggings',Count:1b},{id:'minecraft:chainmail_chestplate',Count:1b},{id:'minecraft:leather_helmet',Count:1b}],ArmorDropChances:[0.025F,0.025F,0.025F,0.025F]}
execute at @s run execute as @e[type=marker,distance=..10,tag=StalagSpawn2,tag=DoASpawn] run execute at @s[scores={KyuDummy=17..21}] run summon spider ~ ~ ~ {Tags:["KyuSpawnerMob"],Attributes:[{Name:generic.armor,Base:5}]}


execute at @s run execute as @e[type=marker,distance=..10,tag=StalagSpawn2,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=StalagSpawn2,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=StalagSpawn2] 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]



