###Performs castle tax collection###
execute at @e[tag=nitGoldStor,limit=1,sort=nearest,distance=..300] run function nitk:recurs/castle_taxes

###Checks for the time of day and adds requisite scores at noon###
scoreboard players add @s[tag=nitLumberer] nitResourceSpawn 1
scoreboard players add @s[tag=nitMiner] nitResourceSpawn 1
execute if entity @s[tag=nitFisherman] unless entity @e[type=cod,distance=..8] run scoreboard players add @s[tag=nitFisherman] nitResourceSpawn 1
scoreboard players add @s[tag=nitFarmhand] nitResourceSpawn 1
scoreboard players operation @s[tag=nitLumberer,tag=nitAtSilo] nitResourceSpawn += @s nitResourceSpawn
scoreboard players operation @s[tag=nitMiner,tag=nitAtSilo] nitResourceSpawn += @s nitResourceSpawn

###Performs item and fish distribution###
execute if entity @s[scores={nitResourceSpawn=1..},tag=nitLumberer] at @e[tag=nitLumberStor,limit=1,sort=nearest] run summon minecraft:item ~ ~0.4 ~ {Item:{id:"minecraft:oak_log",Count:12b}}
execute if entity @s[scores={nitResourceSpawn=1..},tag=nitMiner] at @e[tag=nitStoneStor,limit=1,sort=nearest] run summon minecraft:item ~ ~0.4 ~ {Item:{id:"minecraft:stone",Count:12b}}
execute if entity @s[scores={nitResourceSpawn=1..},tag=nitFisherman] at @e[tag=nitFishPond,limit=1,sort=nearest] run function nitk:recurs/fish_spawn

execute if entity @s[scores={nitResourceSpawn=1..},tag=nitFarmhand] at @e[tag=nitFarmStor,limit=1,sort=nearest] run loot insert ~ ~ ~ loot nitk:command/farm_daily
execute if entity @s[scores={nitResourceSpawn=1..},tag=nitFarmhand] at @e[tag=nitFarmStor,tag=nitWindmillDouble,limit=1,sort=nearest] run loot insert ~ ~ ~ loot nitk:command/farm_daily
execute if entity @s[scores={nitResourceSpawn=1..},tag=nitFarmhandNurse] at @e[tag=nitFarmStor,limit=1,sort=nearest] run loot insert ~ ~ ~ loot nitk:command/farm_nurse_daily
execute if entity @s[scores={nitResourceSpawn=1..},tag=nitFarmhandNurse] at @e[tag=nitFarmStor,tag=nitWindmillDouble,limit=1,sort=nearest] run loot insert ~ ~ ~ loot nitk:command/farm_nurse_daily

###Decrements scores###
scoreboard players remove @s[scores={nitResourceSpawn=1..},tag=nitLumberer] nitResourceSpawn 1
scoreboard players remove @s[scores={nitResourceSpawn=1..},tag=nitMiner] nitResourceSpawn 1
scoreboard players remove @s[scores={nitResourceSpawn=1..},tag=nitFisherman] nitResourceSpawn 1
scoreboard players remove @s[scores={nitResourceSpawn=1..},tag=nitFarmhand] nitResourceSpawn 1

###Performs doubled resource drops and decrements scores###
execute if entity @s[scores={nitResourceSpawn=1..},tag=nitLumberer] at @e[tag=nitLumberStor,limit=1,sort=nearest] run summon minecraft:item ~ ~0.4 ~ {Item:{id:"minecraft:oak_log",Count:12b}}
execute if entity @s[scores={nitResourceSpawn=1..},tag=nitMiner] at @e[tag=nitStoneStor,limit=1,sort=nearest] run summon minecraft:item ~ ~0.4 ~ {Item:{id:"minecraft:stone",Count:12b}}
execute if entity @s[scores={nitResourceSpawn=1..},tag=nitFarmhand] at @e[tag=nitFarmStor,tag=nitWindmillDouble,limit=1,sort=nearest] run loot insert ~ ~ ~ loot nitk:command/farm_daily

scoreboard players remove @s[scores={nitResourceSpawn=1..},tag=nitLumberer] nitResourceSpawn 1
scoreboard players remove @s[scores={nitResourceSpawn=1..},tag=nitMiner] nitResourceSpawn 1

###Announces the event###
execute if entity @s[tag=nitLumberer] run tag @a[tag=nitCitizen] add nitInform
execute if entity @s[tag=nitMiner] run tag @a[tag=nitCitizen] add nitInform
execute if entity @s[tag=nitLumberer] at @e[tag=nitStoneStor] run playsound minecraft:block.bell.use master @a ~ ~ ~ 5
execute if entity @s[tag=nitMiner] at @e[tag=nitStoneStor] run playsound minecraft:block.bell.use master @a ~ ~ ~ 5