###Builds the upgrade with the same rotation as the original###
execute positioned ~-1 ~ ~ if entity @e[tag=nitRotation,distance=..0.5] run place template nitk:upgrades/tap_mine ~7 ~-8 ~7 180

execute positioned ~1 ~ ~ if entity @e[tag=nitRotation,distance=..0.5] run place template nitk:upgrades/tap_mine ~-7 ~-8 ~-7

execute positioned ~ ~ ~1 if entity @e[tag=nitRotation,distance=..0.5] run place template nitk:upgrades/tap_mine ~7 ~-8 ~-7 clockwise_90

execute positioned ~ ~ ~-1 if entity @e[tag=nitRotation,distance=..0.5] run place template nitk:upgrades/tap_mine ~-7 ~-8 ~7 counterclockwise_90

###Moves and Promotes the Miner###
tp @e[tag=nitMiner,limit=1,sort=nearest] @e[tag=nitMinerSpot,limit=1,sort=nearest]
data modify entity @e[tag=nitMiner,limit=1,sort=nearest] CustomName set value '{"text":"Mine Foreman"}'

###Miner setup###
scoreboard players operation @e[tag=nitCitizen,distance=..20] nitID = @e[tag=nitKTP,limit=1,sort=nearest] nitID
scoreboard players operation #nitID nitTemp = @e[tag=nitKTP,limit=1,sort=nearest] nitID
execute as @e[tag=nitMiner] if score @s nitID = #nitID nitTemp run tag @s add nitID_match
execute if entity @e[tag=nitStoneStor,tag=nitAtSilo] run tag @e[tag=nitMiner,type=villager,tag=nitID_match] add nitAtSilo
tag @e[tag=nitMiner,tag=nitID_match] remove nitID_match

###Cleanup###
function nitk:siteplanner/upgrades/cleanup