###Creates new siteplanners for unoccupied sites adjacent to site newly constructed to the east###
execute if entity @s[tag=nitSiteEast,tag=!nitCoBridge] run fill ~6 ~-6 ~-2 ~10 ~-6 ~2 minecraft:repeating_command_block{auto:1,Command:"fill ~ ~ ~ ~ 20 ~ nether_bricks"}
execute if entity @s[tag=nitSiteEast] if block ~23 ~-2 ~ minecraft:bedrock run tag @s add nitSiteExistsEast
execute if entity @s[tag=nitSiteEast] if block ~8 ~-2 ~-15 minecraft:bedrock run tag @s add nitSiteExistsNorth
execute if entity @s[tag=nitSiteEast] if block ~8 ~-2 ~15 minecraft:bedrock run tag @s add nitSiteExistsSouth
execute if entity @s[tag=nitSiteEast] run function nitco:siteplanner/new_sites_tech/newsite_e

###Creates new siteplanners for unoccupied sites adjacent to site newly constructed to the west###
execute if entity @s[tag=nitSiteWest,tag=!nitCoBridge] run fill ~-6 ~-6 ~-2 ~-10 ~-6 ~2 minecraft:repeating_command_block{auto:1,Command:"fill ~ ~ ~ ~ 20 ~ nether_bricks"}
execute if entity @s[tag=nitSiteWest] if block ~-23 ~-2 ~ minecraft:bedrock run tag @s add nitSiteExistsWest
execute if entity @s[tag=nitSiteWest] if block ~-8 ~-2 ~-15 minecraft:bedrock run tag @s add nitSiteExistsNorth
execute if entity @s[tag=nitSiteWest] if block ~-8 ~-2 ~15 minecraft:bedrock run tag @s add nitSiteExistsSouth
execute if entity @s[tag=nitSiteWest] run function nitco:siteplanner/new_sites_tech/newsite_w

###Creates new siteplanners for unoccupied sites adjacent to site newly constructed to the north###
execute if entity @s[tag=nitSiteNorth,tag=!nitCoBridge] run fill ~-2 ~-6 ~-6 ~2 ~-6 ~-10 minecraft:repeating_command_block{auto:1,Command:"fill ~ ~ ~ ~ 20 ~ nether_bricks"}
execute if entity @s[tag=nitSiteNorth] if block ~ ~-2 ~-23 minecraft:bedrock run tag @s add nitSiteExistsNorth
execute if entity @s[tag=nitSiteNorth] if block ~15 ~-2 ~-8 minecraft:bedrock run tag @s add nitSiteExistsEast
execute if entity @s[tag=nitSiteNorth] if block ~-15 ~-2 ~-8 minecraft:bedrock run tag @s add nitSiteExistsWest
execute if entity @s[tag=nitSiteNorth] run function nitco:siteplanner/new_sites_tech/newsite_n

###Creates new siteplanners for unoccupied sites adjacent to site newly constructed to the south###
execute if entity @s[tag=nitSiteSouth,tag=!nitCoBridge] run fill ~-2 ~-6 ~6 ~2 ~-6 ~10 minecraft:repeating_command_block{auto:1,Command:"fill ~ ~ ~ ~ 20 ~ nether_bricks"}
execute if entity @s[tag=nitSiteSouth] if block ~ ~-2 ~23 minecraft:bedrock run tag @s add nitSiteExistsSouth
execute if entity @s[tag=nitSiteSouth] if block ~15 ~-2 ~8 minecraft:bedrock run tag @s add nitSiteExistsEast
execute if entity @s[tag=nitSiteSouth] if block ~-15 ~-2 ~8 minecraft:bedrock run tag @s add nitSiteExistsWest
execute if entity @s[tag=nitSiteSouth] run function nitco:siteplanner/new_sites_tech/newsite_s

###Establishes id matches for hell attack sites###
execute if entity @s[tag=!nitCoBridge] run scoreboard players operation #nitID nitTemp = @e[tag=nitCWS,limit=1,sort=nearest] nitID
execute as @e[tag=nitCSpecialFeature] if score @s nitID = #nitID nitTemp run tag @s add nitID_match

###Increases the Hell attack danger count, then performs matching attack###
execute as @e[tag=nitCSpecialFeature,tag=nitID_match] at @s run function nitco:hell_attack

###Increases siteplanning count on player for advancement purposes###
execute if entity @s[tag=!nitCoBridge] run scoreboard players add @a[distance=..50,tag=nitDenizen] nitWarCraft 1
advancement grant @a[scores={nitWarCraft=1..}] only nitco:nitco/ach2 co-siteplanner-1
advancement grant @a[scores={nitWarCraft=5..}] only nitco:nitco/ach3 co-siteplanner-5
advancement grant @a[scores={nitWarCraft=9..}] only nitco:nitco/ach4 co-siteplanner-9

###Creates text prompts to guide player to the hidden features###
execute if entity @s[tag=!nitCoBridge] if entity @p[scores={nitWarCraft=1},distance=..50] run tellraw @a[distance=..50,tag=nitDenizen] [{"text":"[۩]","color":"green","bold":true},{"text":": ","color":"white","bold":false},{"text":"Your scouts have uncovered the trawler ship! Seek out the glowing skeletons!","color":"dark_red"}]
execute if entity @s[tag=!nitCoBridge] if entity @p[scores={nitWarCraft=2..3},distance=..50] run tellraw @a[distance=..50,tag=nitDenizen] [{"text":"[۩]","color":"green","bold":true},{"text":": ","color":"white","bold":false},{"text":"The Tyrant's forces have restocked the Trawler Ship","color":"dark_red"}]
execute if entity @s[tag=!nitCoBridge] if entity @p[scores={nitWarCraft=5},distance=..50] run tellraw @a[distance=..50,tag=nitDenizen] [{"text":"[۩]","color":"green","bold":true},{"text":": ","color":"white","bold":false},{"text":"Your scouts have uncovered the portal factory! Look high for their glow!","color":"dark_red"}]
execute if entity @s[tag=!nitCoBridge] if entity @p[scores={nitWarCraft=6},distance=..50] run tellraw @a[distance=..50,tag=nitDenizen] [{"text":"[۩]","color":"green","bold":true},{"text":": ","color":"white","bold":false},{"text":"The Tyrant's forces have restocked the Portal Factory","color":"dark_red"}]
execute if entity @s[tag=!nitCoBridge] if entity @p[scores={nitWarCraft=9},distance=..50] run tellraw @a[distance=..50,tag=nitDenizen] [{"text":"[۩]","color":"green","bold":true},{"text":": ","color":"white","bold":false},{"text":"The ancient drill is discovered! Its defenders glow far below!","color":"dark_red"}]

###Cleanup###
tag @a add nitDenizen
tag @e[type=minecraft:villager,distance=..20] add nitDenizen
scoreboard players operation @e[tag=nitDenizen,distance=..20] nitID = @e[tag=nitCWS,limit=1,sort=nearest] nitID
execute at @s run fill ~ ~ ~ ~ ~3 ~ air
kill @e[type=item,distance=..2,tag=!smithed.entity,tag=!smithed.strict]
execute if entity @s[tag=nitSiteEast] run particle large_smoke ~7 ~2 ~ 3 2 3 0.3 200 force
execute if entity @s[tag=nitSiteWest] run particle large_smoke ~-7 ~2 ~ 3 2 3 0.3 200 force
execute if entity @s[tag=nitSiteNorth] run particle large_smoke ~ ~2 ~-7 3 2 3 0.3 200 force
execute if entity @s[tag=nitSiteSouth] run particle large_smoke ~ ~2 ~7 3 2 3 0.3 200 force
playsound minecraft:block.anvil.use block @a ~ ~ ~ 5 0.7
playsound minecraft:entity.villager.work_weaponsmith block @a ~ ~ ~ 5 0.5
playsound minecraft:block.respawn_anchor.set_spawn block @a ~ ~ ~ 5 1 1
playsound minecraft:block.fire.extinguish block @a ~ ~ ~ 5 1