gradually regenerating structures

I was trying to figure out if this is even possible or if I'm vastly underestimating how complicated it is, but I want to build a dungeon with jigsaw blocks that, when it gets damaged gradually regenerates the broken blocks with higher priority on "deeper" holes in the walls and floor. (Well for now I haven't even got a structure to successfully generate in my testing world because I couldn't figure out if the structure folder had to be in the namespace or minecraft folder, and how the generating function links to it, but already knowing if I need to change some plans would already help a lot) Thank you ^^
Continue to help post