###Establishes identity matching for the Town Planner###
scoreboard players operation #nitID nitTemp = @p[limit=1,advancements={nitco:nitco/ach5.1=true}] nitID
execute if score @s nitID = #nitID nitTemp run tag @s add nitID_match

###Performs the update to the matching Town Planner###
execute if entity @s[tag=nitID_match,tag=!nitKTPnew] if entity @p[limit=1,advancements={nitco:nitco/ach5.1=true}] run data modify entity @s Offers.Recipes append value {buy:{id:"minecraft:feather",Count:1},sell:{id:"minecraft:written_book",Count:1,tag:{pages:['["",{"text":"End Portal.","bold":true,"underlined":true,"hoverEvent":{"action":"show_item","value":"{\\"id\\":\\"bundle\\",\\"Count\\":1,\\"tag\\":{\\"display\\":{\\"Name\\":\'{\\"text\\":\\"Site Planner\\",\\"italic\\":\\"false\\"}\'},\\"Items\\":[{\\"id\\":\\"minecraft:ender_eye\\",\\"Count\\":6},{\\"id\\":\\"minecraft:chain\\",\\"Count\\":16},{\\"id\\":\\"minecraft:ender_eye\\",\\"Count\\":6},{},{\\"id\\":\\"minecraft:stone\\",\\"Count\\":32},{\\"id\\":\\"minecraft:music_disc_13\\",\\"Count\\":1,\\"tag\\":{\\"Enchantments\\":[{\\"lvl\\":0,\\"id\\":\\"minecraft:protection\\"}]}},{\\"id\\":\\"minecraft:stone\\",\\"Count\\":32},{},{\\"id\\":\\"minecraft:stone\\",\\"Count\\":64},{\\"id\\":\\"minecraft:oak_log\\",\\"Count\\":16},{\\"id\\":\\"minecraft:stone\\",\\"Count\\":64},{}]}}"}},{"text":" A housing structure for completing an End Portal, to stop the Tyrant\'s invasion.","color":"reset"}]','["",{"text":"Completed Portal.","bold":true,"underlined":true,"hoverEvent":{"action":"show_item","value":"{\\"id\\":\\"bundle\\",\\"Count\\":1,\\"tag\\":{\\"display\\":{\\"Name\\":\'{\\"text\\":\\"Portal Reactor\\",\\"italic\\":\\"false\\"}\'},\\"Items\\":[{\\"id\\":\\"minecraft:ender_eye\\",\\"Count\\":1},{\\"id\\":\\"minecraft:ender_eye\\",\\"Count\\":1},{\\"id\\":\\"minecraft:ender_eye\\",\\"Count\\":1},{},{\\"id\\":\\"minecraft:ender_eye\\",\\"Count\\":1},{\\"id\\":\\"minecraft:gold_ingot\\",\\"Count\\":64},{\\"id\\":\\"minecraft:ender_eye\\",\\"Count\\":1},{},{\\"id\\":\\"minecraft:ender_eye\\",\\"Count\\":1},{\\"id\\":\\"minecraft:nether_star\\",\\"Count\\":1},{\\"id\\":\\"minecraft:ender_eye\\",\\"Count\\":1},{}]}}"}},{"text":" Completes the End Portal when placed in the Portal Reactor.","color":"reset"}]'],title:"End Portal Recipe",author:"Town Planner"}},maxUses:1}
execute if entity @p[limit=1,advancements={nitco:nitco/ach5.1=true}] run tag @s[tag=nitID_match] add nitKTPnew
execute if entity @s[tag=nitID_match] if entity @p[limit=1,advancements={nitco:nitco/ach5.1=true}] run particle minecraft:happy_villager ~ ~1 ~ 0.3 0.5 0.3 0 1 normal

###Informs the players of the update###
execute if entity @s[tag=nitKTP,tag=nitKTPnew,tag=nitID_match] if entity @p[limit=1,sort=nearest,tag=!nitKTPinformed,nbt={Dimension:"minecraft:overworld"},advancements={nitco:nitco/ach5.1=true}] run tellraw @a[distance=..50,tag=nitDenizen] [{"text":"[۩]","color":"green","bold":true},{"text":": ","color":"white","bold":false},{"text":"These invasion plans seem interesting. Maybe the Town Planner can decipher them...","color":"white","bold":false}]
execute if entity @s[tag=nitKTP,tag=nitKTPnew,tag=nitID_match] if entity @p[limit=1,sort=nearest,tag=!nitKTPinformed,nbt={Dimension:"minecraft:overworld"},advancements={nitco:nitco/ach5.1=true}] run tag @a[distance=..50,tag=nitDenizen] add nitKTPinformed
tag @s[tag=nitID_match] remove nitID_match
