###Adds requisite scores###
scoreboard players add @s[tag=nitFestival] nitResourceSpawn 1

###Begins festival###
#Summons festival villagers#
execute if entity @s[scores={nitResourceSpawn=10},tag=nitFestival] at @e[tag=nitFestFish,limit=1,sort=nearest] run summon villager ~ ~ ~ {VillagerData:{profession:fisherman,level:3,type:"plains"},Invulnerable:1,PersistenceRequired:1,CustomName:'{"text":"Festival Fish Salesman"}',ActiveEffects:[{Id:10,Amplifier:1,Duration:999999},{Id:21,Amplifier:0,Duration:999999},{Id:26,Amplifier:0,Duration:999999}],Offers:{Recipes:[{buy:{id:gold_ingot,Count:7},sell:{id:salmon_bucket,Count:1},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:10},sell:{id:tropical_fish_bucket,Count:1},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:16},sell:{id:pufferfish_bucket,Count:1},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:30},sell:{id:axolotl_bucket,Count:1},rewardExp:0b,maxUses:1}]},Tags:[nitFestCitizen,nitCitizen,nitEntity,smithed.entity,smithed.strict]}
execute if entity @s[scores={nitResourceSpawn=10},tag=nitFestival] at @e[tag=nitFestFood,limit=1,sort=nearest] run summon villager ~ ~ ~ {VillagerData:{profession:farmer,level:3,type:"plains"},Invulnerable:1,PersistenceRequired:1,CustomName:'{"text":"Festival Food Salesman"}',ActiveEffects:[{Id:10,Amplifier:1,Duration:999999},{Id:21,Amplifier:0,Duration:999999},{Id:26,Amplifier:0,Duration:999999}],Offers:{Recipes:[{buy:{id:gold_ingot,Count:3},sell:{id:apple,Count:1},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:8},sell:{id:golden_apple,Count:1},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:14},sell:{id:pumpkin_pie,Count:1},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:19},sell:{id:cookie,Count:16},rewardExp:0b,maxUses:1}]},Tags:[nitFestCitizen,nitCitizen,nitEntity,smithed.entity,smithed.strict]}
execute if entity @s[scores={nitResourceSpawn=10},tag=nitFestival] at @e[tag=nitFestFlower,limit=1,sort=nearest] run summon villager ~ ~ ~ {VillagerData:{profession:cartographer,level:3,type:"plains"},Invulnerable:1,PersistenceRequired:1,CustomName:'{"text":"Festival Flower Salesman"}',ActiveEffects:[{Id:10,Amplifier:1,Duration:999999},{Id:21,Amplifier:0,Duration:999999},{Id:26,Amplifier:0,Duration:999999}],Offers:{Recipes:[{buy:{id:gold_ingot,Count:4},sell:{id:peony,Count:3},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:4},sell:{id:rose_bush,Count:3},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:4},sell:{id:lilac,Count:3},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:8},sell:{id:spore_blossom,Count:1},rewardExp:0b,maxUses:1}]},Tags:[nitFestCitizen,nitCitizen,nitEntity,smithed.entity,smithed.strict]}
execute if entity @s[scores={nitResourceSpawn=10},tag=nitFestival] at @e[tag=nitFestDeco,limit=1,sort=nearest] run summon villager ~ ~ ~ {VillagerData:{profession:mason,level:3,type:"plains"},Invulnerable:1,PersistenceRequired:1,CustomName:'{"text":"Festival Decorator"}',ActiveEffects:[{Id:10,Amplifier:1,Duration:999999},{Id:21,Amplifier:0,Duration:999999},{Id:26,Amplifier:0,Duration:999999}],Offers:{Recipes:[{buy:{id:gold_ingot,Count:9},sell:{id:lantern,Count:4},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:12},sell:{id:flowering_azalea,Count:2},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:15},sell:{id:glow_item_frame,Count:4},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:20},sell:{id:candle,Count:10},rewardExp:0b,maxUses:1}]},Tags:[nitFestCitizen,nitCitizen,nitEntity,smithed.entity,smithed.strict]}
execute if entity @s[scores={nitResourceSpawn=10},tag=nitFestival] at @e[tag=nitFestArt,limit=1,sort=nearest] run summon villager ~ ~ ~ {VillagerData:{profession:cleric,level:3,type:"plains"},Invulnerable:1,PersistenceRequired:1,CustomName:'{"text":"Festival Artist"}',ActiveEffects:[{Id:10,Amplifier:1,Duration:999999},{Id:21,Amplifier:0,Duration:999999},{Id:26,Amplifier:0,Duration:999999}],Offers:{Recipes:[{buy:{id:gold_ingot,Count:12},sell:{id:zombie_head,Count:1},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:25},sell:{id:skeleton_skull,Count:1},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:31},sell:{id:creeper_head,Count:4},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:40},sell:{id:wither_skeleton_skull,Count:1},rewardExp:0b,maxUses:1},{buy:{id:gold_ingot,Count:46},sell:{id:player_head,Count:1,tag:{SkullOwner:"kanokarob"}},rewardExp:0b,maxUses:1}]},Tags:[nitFestCitizen,nitCitizen,nitEntity,smithed.entity,smithed.strict]}

#Announces festival#
execute if entity @s[scores={nitResourceSpawn=10},tag=nitFestival] run tellraw @a[tag=nitCitizen,distance=..200] [{"text":"[۩]","color":"green","bold":true},{"text":": ","color":"white","bold":false},{"text":"The town has decided to throw a festival at the Festival Grounds!","color":"yellow","bold":false}]
execute as @s[scores={nitResourceSpawn=10},tag=nitFestival] at @s run playsound minecraft:block.bell.use block @a ~ ~ ~ 5
execute as @s[scores={nitResourceSpawn=10},tag=nitFestival] at @s run playsound minecraft:music_disc.blocks block @a ~ ~ ~ 5

#Increments festival stage#
execute if entity @s[scores={nitResourceSpawn=10},tag=nitFestival] run scoreboard players add @s[tag=nitFestival] nitResourceSpawn 1

###Runs continuous festival features###
execute if entity @s[scores={nitResourceSpawn=11},tag=nitFestival] run particle minecraft:happy_villager ~ ~ ~ 15 5 7 0 20 normal @a[distance=..17]

###Ends festival###
execute if entity @s[scores={nitResourceSpawn=12},tag=nitFestival] run tp @e[tag=nitFestCitizen] ~ -1000 ~
execute if entity @s[scores={nitResourceSpawn=12},tag=nitFestival] run tellraw @a[tag=nitCitizen,distance=..200] [{"text":"[۩]","color":"green","bold":true},{"text":": ","color":"white","bold":false},{"text":"The town festival has ended.","color":"yellow","bold":false}]
execute if entity @s[scores={nitResourceSpawn=12},tag=nitFestival] run stopsound @a block minecraft:music_disc.blocks
scoreboard players set @s[scores={nitResourceSpawn=12},tag=nitFestival] nitResourceSpawn 0