import { world, system } from "@minecraft/server";
import { fo } from './utilities/fo_constants.js';




export function initWorldGen() { 

    
    const monolithCoords = [
        { x: 25032, z: 25224, id: "MonolithA01" },
        { x: 25096, z: 25192, id: "MonolithA02" },
        { x: 25096, z: 25256, id: "MonolithA03" },
        { x: 25160, z: 25160, id: "MonolithA04" },
        { x: 25160, z: 25224, id: "MonolithA05" },
        { x: 25160, z: 25288, id: "MonolithA06" },
        { x: 25224, z: 25128, id: "MonolithA07" },
        { x: 25224, z: 25192, id: "MonolithA08" },
        { x: 25224, z: 25256, id: "MonolithA09" },
        { x: 25224, z: 25320, id: "MonolithA10" },
        { x: 25288, z: 25160, id: "MonolithA11" },
        { x: 25288, z: 25224, id: "MonolithA12" },
        { x: 25288, z: 25288, id: "MonolithA13" },
        { x: 25288, z: 25352, id: "MonolithA14" },
        { x: 25352, z: 25128, id: "MonolithA15" },
        { x: 25352, z: 25192, id: "MonolithA16" },
        { x: 25352, z: 25256, id: "MonolithA17" },
        { x: 25352, z: 25320, id: "MonolithA18" },
        { x: 25416, z: 25160, id: "MonolithA19" },
        { x: 25416, z: 25224, id: "MonolithA20" },
        { x: 25416, z: 25288, id: "MonolithA21" },
        { x: 25480, z: 25192, id: "MonolithA22" },
        { x: 25480, z: 25256, id: "MonolithA23" },
        { x: 25544, z: 25224, id: "MonolithA24" },
        { x: 25384, z: 25480, id: "MonolithB01" },
        { x: 25384, z: 25544, id: "MonolithB02" },
        { x: 25384, z: 25608, id: "MonolithB03" },
        { x: 25448, z: 25448, id: "MonolithB04" },
        { x: 25448, z: 25512, id: "MonolithB05" },
        { x: 25448, z: 25576, id: "MonolithB06" },
        { x: 25448, z: 25640, id: "MonolithB07" },
        { x: 25512, z: 25416, id: "MonolithB08" },
        { x: 25512, z: 25480, id: "MonolithB09" },
        { x: 25512, z: 25544, id: "MonolithB10" },
        { x: 25512, z: 25608, id: "MonolithB11" },
        { x: 25512, z: 25672, id: "MonolithB12" },
        { x: 25576, z: 25384, id: "MonolithB13" },
        { x: 25576, z: 25448, id: "MonolithB14" },
        { x: 25576, z: 25512, id: "MonolithB15" },
        { x: 25576, z: 25576, id: "MonolithB16" },
        { x: 25576, z: 25640, id: "MonolithB17" },
        { x: 25640, z: 25352, id: "MonolithB18" },
        { x: 25640, z: 25416, id: "MonolithB19" },
        { x: 25640, z: 25480, id: "MonolithB20" },
        { x: 25640, z: 25544, id: "MonolithB21" },
        { x: 25640, z: 25608, id: "MonolithB22" },
        { x: 25704, z: 25384, id: "MonolithB23" },
        { x: 25704, z: 25448, id: "MonolithB24" },
        { x: 25704, z: 25512, id: "MonolithB25" },
        { x: 25704, z: 25576, id: "MonolithB26" },
        { x: 25704, z: 25640, id: "MonolithB27" },
        { x: 25768, z: 25416, id: "MonolithB28" },
        { x: 25768, z: 25480, id: "MonolithB29" },
        { x: 25768, z: 25544, id: "MonolithB30" },
        { x: 25768, z: 25608, id: "MonolithB31" },
        { x: 25832, z: 25448, id: "MonolithB32" },
        { x: 25832, z: 25512, id: "MonolithB33" },
        { x: 25832, z: 25576, id: "MonolithB34" },
        { x: 25896, z: 25480, id: "MonolithB35" },
        { x: 25896, z: 25544, id: "MonolithB36" },
        { x: 25736, z: 25096, id: "MonolithC01" },
        { x: 25768, z: 25000, id: "MonolithC02" },
        { x: 25832, z: 25000, id: "MonolithC03" },
        { x: 25896, z: 25000, id: "MonolithC04" },
        { x: 25800, z: 25064, id: "MonolithC05" },
        { x: 25800, z: 25128, id: "MonolithC06" },
        { x: 25800, z: 25192, id: "MonolithC07" },
        { x: 25864, z: 25064, id: "MonolithC08" },
        { x: 25864, z: 25128, id: "MonolithC09" },
        { x: 25864, z: 25192, id: "MonolithC10" },
        { x: 25928, z: 25064, id: "MonolithC11" },
        { x: 25928, z: 25128, id: "MonolithC12" },
        { x: 25928, z: 25192, id: "MonolithC13" },
        { x: 25928, z: 25256, id: "MonolithC14" },
        { x: 25992, z: 25128, id: "MonolithC15" },
        { x: 25992, z: 25192, id: "MonolithC16" },
        { x: 25992, z: 25256, id: "MonolithC17" },
        { x: 25992, z: 25320, id: "MonolithC18" },
        { x: 26056, z: 25160, id: "MonolithC19" },
        { x: 26056, z: 25224, id: "MonolithC20" },
        { x: 26056, z: 25288, id: "MonolithC21" },
        { x: 26120, z: 25192, id: "MonolithC22" },
        { x: 26120, z: 25256, id: "MonolithC23" },
        { x: 26056, z: 25480, id: "MonolithD01" },
        { x: 26056, z: 25544, id: "MonolithD02" },
        { x: 26120, z: 25448, id: "MonolithD03" },
        { x: 26120, z: 25512, id: "MonolithD04" },
        { x: 26120, z: 25576, id: "MonolithD05" },
        { x: 26184, z: 25416, id: "MonolithD06" },
        { x: 26184, z: 25480, id: "MonolithD07" },
        { x: 26184, z: 25544, id: "MonolithD08" },
        { x: 26248, z: 25448, id: "MonolithD09" },
        { x: 26248, z: 25512, id: "MonolithD10" },
        { x: 26312, z: 25480, id: "MonolithD11" },
        { x: 26312, z: 25544, id: "MonolithD12" },
        { x: 26376, z: 25512, id: "MonolithD13" },
        { x: 26376, z: 25576, id: "MonolithD14" },
        { x: 26440, z: 25480, id: "MonolithD15" },
        { x: 26440, z: 25544, id: "MonolithD16" },
        { x: 26504, z: 25448, id: "MonolithD17" },
        { x: 26504, z: 25512, id: "MonolithD18" },
        { x: 26504, z: 25576, id: "MonolithD19" },
        { x: 26568, z: 25416, id: "MonolithD20" },
        { x: 26568, z: 25480, id: "MonolithD21" },
        { x: 26568, z: 25544, id: "MonolithD22" },
        { x: 26632, z: 25384, id: "MonolithD23" },
        { x: 26632, z: 25448, id: "MonolithD24" },
        { x: 26632, z: 25512, id: "MonolithD25" },
        { x: 26696, z: 25320, id: "MonolithD26" },
        { x: 26696, z: 25384, id: "MonolithD27" },
        { x: 26696, z: 25448, id: "MonolithD28" },
        { x: 26760, z: 25288, id: "MonolithD29" },
        { x: 26760, z: 25352, id: "MonolithD30" },
        { x: 26760, z: 25416, id: "MonolithD31" },
        { x: 26824, z: 25320, id: "MonolithD32" },
        { x: 26824, z: 25384, id: "MonolithD33" },
        { x: 26248, z: 25288, id: "MonolithE01" },
        { x: 26312, z: 25256, id: "MonolithE02" },
        { x: 26312, z: 25320, id: "MonolithE03" },
        { x: 26376, z: 25224, id: "MonolithE04" },
        { x: 26376, z: 25288, id: "MonolithE05" },
        { x: 26376, z: 25352, id: "MonolithE06" },
        { x: 26440, z: 25192, id: "MonolithE07" },
        { x: 26440, z: 25256, id: "MonolithE08" },
        { x: 26440, z: 25320, id: "MonolithE09" },
        { x: 26504, z: 25160, id: "MonolithE10" },
        { x: 26504, z: 25224, id: "MonolithE11" },
        { x: 26504, z: 25288, id: "MonolithE12" },
        { x: 26568, z: 25192, id: "MonolithE13" },
        { x: 26568, z: 25256, id: "MonolithE14" }
    ];

    const dimensionCoords = [
        { x: 400352, z: 400048, id: "Dimension01" },
        { x: 400416, z: 400048, id: "Dimension02" },
        { x: 400480, z: 400048, id: "Dimension03" },
        { x: 400544, z: 400048, id: "Dimension04" },
        { x: 400608, z: 400048, id: "Dimension05" },
        { x: 400224, z: 400112, id: "Dimension06" },
        { x: 400288, z: 400112, id: "Dimension07" },
        { x: 400352, z: 400112, id: "Dimension08" },
        { x: 400416, z: 400112, id: "Dimension09" },
        { x: 400480, z: 400112, id: "Dimension10" },
        { x: 400544, z: 400112, id: "Dimension11" },
        { x: 400608, z: 400112, id: "Dimension12" },
        { x: 400672, z: 400112, id: "Dimension13" },
        { x: 400736, z: 400112, id: "Dimension14" },
        { x: 400160, z: 400176, id: "Dimension15" },
        { x: 400224, z: 400176, id: "Dimension16" },
        { x: 400288, z: 400176, id: "Dimension17" },
        { x: 400352, z: 400176, id: "Dimension18" },
        { x: 400416, z: 400176, id: "Dimension19" },
        { x: 400480, z: 400176, id: "Dimension20" },
        { x: 400544, z: 400176, id: "Dimension21" },
        { x: 400608, z: 400176, id: "Dimension22" },
        { x: 400672, z: 400176, id: "Dimension23" },
        { x: 400736, z: 400176, id: "Dimension24" },
        { x: 400800, z: 400176, id: "Dimension25" },
        { x: 400096, z: 400240, id: "Dimension26" },
        { x: 400160, z: 400240, id: "Dimension27" },
        { x: 400224, z: 400240, id: "Dimension28" },
        { x: 400288, z: 400240, id: "Dimension29" },
        { x: 400352, z: 400240, id: "Dimension30" },
        { x: 400416, z: 400240, id: "Dimension31" },
        { x: 400480, z: 400240, id: "Dimension32" },
        { x: 400544, z: 400240, id: "Dimension33" },
        { x: 400608, z: 400240, id: "Dimension34" },
        { x: 400672, z: 400240, id: "Dimension35" },
        { x: 400736, z: 400240, id: "Dimension36" },
        { x: 400800, z: 400240, id: "Dimension37" },
        { x: 400864, z: 400240, id: "Dimension38" },
        { x: 400096, z: 400304, id: "Dimension39" },
        { x: 400160, z: 400304, id: "Dimension40" },
        { x: 400224, z: 400304, id: "Dimension41" },
        { x: 400288, z: 400304, id: "Dimension42" },
        { x: 400352, z: 400304, id: "Dimension43" },
        { x: 400416, z: 400304, id: "Dimension44" },
        { x: 400480, z: 400304, id: "Dimension45" },
        { x: 400544, z: 400304, id: "Dimension46" },
        { x: 400608, z: 400304, id: "Dimension47" },
        { x: 400672, z: 400304, id: "Dimension48" },
        { x: 400736, z: 400304, id: "Dimension49" },
        { x: 400800, z: 400304, id: "Dimension50" },
        { x: 400864, z: 400304, id: "Dimension51" },
        { x: 400032, z: 400368, id: "Dimension52" },
        { x: 400096, z: 400368, id: "Dimension53" },
        { x: 400160, z: 400368, id: "Dimension54" },
        { x: 400224, z: 400368, id: "Dimension55" },
        { x: 400288, z: 400368, id: "Dimension56" },
        { x: 400352, z: 400368, id: "Dimension57" },
        { x: 400416, z: 400368, id: "Dimension58" },
        { x: 400480, z: 400368, id: "Dimension59" },
        { x: 400544, z: 400368, id: "Dimension60" },
        { x: 400608, z: 400368, id: "Dimension61" },
        { x: 400672, z: 400368, id: "Dimension62" },
        { x: 400736, z: 400368, id: "Dimension63" },
        { x: 400800, z: 400368, id: "Dimension64" },
        { x: 400864, z: 400368, id: "Dimension65" },
        { x: 400928, z: 400368, id: "Dimension66" },
        { x: 400032, z: 400432, id: "Dimension67" },
        { x: 400096, z: 400432, id: "Dimension68" },
        { x: 400160, z: 400432, id: "Dimension69" },
        { x: 400224, z: 400432, id: "Dimension70" },
        { x: 400288, z: 400432, id: "Dimension71" },
        { x: 400352, z: 400432, id: "Dimension72" },
        { x: 400416, z: 400432, id: "Dimension73" },
        { x: 400480, z: 400432, id: "Dimension74" },
        { x: 400544, z: 400432, id: "Dimension75" },
        { x: 400608, z: 400432, id: "Dimension76" },
        { x: 400672, z: 400432, id: "Dimension77" },
        { x: 400736, z: 400432, id: "Dimension78" },
        { x: 400800, z: 400432, id: "Dimension79" },
        { x: 400864, z: 400432, id: "Dimension80" },
        { x: 400928, z: 400432, id: "Dimension81" },
        { x: 400032, z: 400496, id: "Dimension82" },
        { x: 400096, z: 400496, id: "Dimension83" },
        { x: 400160, z: 400496, id: "Dimension84" },
        { x: 400224, z: 400496, id: "Dimension85" },
        { x: 400288, z: 400496, id: "Dimension86" },
        { x: 400352, z: 400496, id: "Dimension87" },
        { x: 400416, z: 400496, id: "Dimension88" },
        { x: 400480, z: 400496, id: "Dimension89" },
        { x: 400544, z: 400496, id: "Dimension90" },
        { x: 400608, z: 400496, id: "Dimension91" },
        { x: 400672, z: 400496, id: "Dimension92" },
        { x: 400736, z: 400496, id: "Dimension93" },
        { x: 400800, z: 400496, id: "Dimension94" },
        { x: 400864, z: 400496, id: "Dimension95" },
        { x: 400928, z: 400496, id: "Dimension96" },
        { x: 400032, z: 400560, id: "Dimension97" },
        { x: 400096, z: 400560, id: "Dimension98" },
        { x: 400160, z: 400560, id: "Dimension99" },
        { x: 400224, z: 400560, id: "Dimension100" },
        { x: 400288, z: 400560, id: "Dimension101" },
        { x: 400352, z: 400560, id: "Dimension102" },
        { x: 400416, z: 400560, id: "Dimension103" },
        { x: 400480, z: 400560, id: "Dimension104" },
        { x: 400544, z: 400560, id: "Dimension105" },
        { x: 400608, z: 400560, id: "Dimension106" },
        { x: 400672, z: 400560, id: "Dimension107" },
        { x: 400736, z: 400560, id: "Dimension108" },
        { x: 400800, z: 400560, id: "Dimension109" },
        { x: 400864, z: 400560, id: "Dimension110" },
        { x: 400928, z: 400560, id: "Dimension111" },
        { x: 400032, z: 400624, id: "Dimension112" },
        { x: 400096, z: 400624, id: "Dimension113" },
        { x: 400160, z: 400624, id: "Dimension114" },
        { x: 400224, z: 400624, id: "Dimension115" },
        { x: 400288, z: 400624, id: "Dimension116" },
        { x: 400352, z: 400624, id: "Dimension117" },
        { x: 400416, z: 400624, id: "Dimension118" },
        { x: 400480, z: 400624, id: "Dimension119" },
        { x: 400544, z: 400624, id: "Dimension120" },
        { x: 400608, z: 400624, id: "Dimension121" },
        { x: 400672, z: 400624, id: "Dimension122" },
        { x: 400736, z: 400624, id: "Dimension123" },
        { x: 400800, z: 400624, id: "Dimension124" },
        { x: 400864, z: 400624, id: "Dimension125" },
        { x: 400928, z: 400624, id: "Dimension126" },
        { x: 400096, z: 400688, id: "Dimension127" },
        { x: 400160, z: 400688, id: "Dimension128" },
        { x: 400224, z: 400688, id: "Dimension129" },
        { x: 400288, z: 400688, id: "Dimension130" },
        { x: 400352, z: 400688, id: "Dimension131" },
        { x: 400416, z: 400688, id: "Dimension132" },
        { x: 400480, z: 400688, id: "Dimension133" },
        { x: 400544, z: 400688, id: "Dimension134" },
        { x: 400608, z: 400688, id: "Dimension135" },
        { x: 400672, z: 400688, id: "Dimension136" },
        { x: 400736, z: 400688, id: "Dimension137" },
        { x: 400800, z: 400688, id: "Dimension138" },
        { x: 400864, z: 400688, id: "Dimension139" },
        { x: 400096, z: 400752, id: "Dimension140" },
        { x: 400160, z: 400752, id: "Dimension141" },
        { x: 400224, z: 400752, id: "Dimension142" },
        { x: 400288, z: 400752, id: "Dimension143" },
        { x: 400352, z: 400752, id: "Dimension144" },
        { x: 400416, z: 400752, id: "Dimension145" },
        { x: 400480, z: 400752, id: "Dimension146" },
        { x: 400544, z: 400752, id: "Dimension147" },
        { x: 400608, z: 400752, id: "Dimension148" },
        { x: 400672, z: 400752, id: "Dimension149" },
        { x: 400736, z: 400752, id: "Dimension150" },
        { x: 400800, z: 400752, id: "Dimension151" },
        { x: 400864, z: 400752, id: "Dimension152" },
        { x: 400160, z: 400816, id: "Dimension153" },
        { x: 400224, z: 400816, id: "Dimension154" },
        { x: 400288, z: 400816, id: "Dimension155" },
        { x: 400352, z: 400816, id: "Dimension156" },
        { x: 400416, z: 400816, id: "Dimension157" },
        { x: 400480, z: 400816, id: "Dimension158" },
        { x: 400544, z: 400816, id: "Dimension159" },
        { x: 400608, z: 400816, id: "Dimension160" },
        { x: 400672, z: 400816, id: "Dimension161" },
        { x: 400736, z: 400816, id: "Dimension162" },
        { x: 400800, z: 400816, id: "Dimension163" },
        { x: 400224, z: 400880, id: "Dimension164" },
        { x: 400288, z: 400880, id: "Dimension165" },
        { x: 400352, z: 400880, id: "Dimension166" },
        { x: 400416, z: 400880, id: "Dimension167" },
        { x: 400480, z: 400880, id: "Dimension168" },
        { x: 400544, z: 400880, id: "Dimension169" },
        { x: 400608, z: 400880, id: "Dimension170" },
        { x: 400672, z: 400880, id: "Dimension171" },
        { x: 400736, z: 400880, id: "Dimension172" },
        { x: 400352, z: 400944, id: "Dimension173" },
        { x: 400416, z: 400944, id: "Dimension174" },
        { x: 400480, z: 400944, id: "Dimension175" },
        { x: 400544, z: 400944, id: "Dimension176" },
        { x: 400608, z: 400944, id: "Dimension177" },

    ];

    const villageCoords = [
        { id: "foVillague01", structureId: "mystructure:foVAltar01", rotation: "None", x: 400500, y: 2, z: 400483 },
        { id: "foVillague02", structureId: "mystructure:foVFarm01", rotation: "None", x: 400522, y: 2, z: 400485 },
        { id: "foVillague03", structureId: "mystructure:foVFarm02", rotation: "None", x: 400539, y: 2, z: 400492 },
        { id: "foVillague04", structureId: "mystructure:foVFarm03", rotation: "None", x: 400540, y: 2, z: 400512 },
        { id: "foVillague05", structureId: "mystructure:foVSmoker01", rotation: "None", x: 400552, y: 1, z: 400524 },
        { id: "foVillague06", structureId: "mystructure:foVFarm04", rotation: "Rotate180", x: 400553, y: 2, z: 400537 },
        { id: "foVillague07", structureId: "mystructure:foVFisher01", rotation: "Rotate90", x: 400539, y: 1, z: 400549 },
        { id: "foVillague08", structureId: "mystructure:foVFarm03", rotation: "None", x: 400529, y: 2, z: 400569 },
        { id: "foVillague09", structureId: "mystructure:foVMason01", rotation: "Rotate270", x: 400527, y: 1, z: 400537 },
        { id: "foVillague10", structureId: "mystructure:foVHouse07", rotation: "Rotate90", x: 400538, y: 1, z: 400526 },
        { id: "foVillague11", structureId: "mystructure:foVHouse04", rotation: "Rotate90", x: 400530, y: 1, z: 400509 },
        { id: "foVillague12", structureId: "mystructure:foVHouse03", rotation: "Rotate270", x: 400526, y: 1, z: 400501 },
        { id: "foVillague13", structureId: "mystructure:foVCartographer01", rotation: "Rotate180", x: 400515, y: 1, z: 400495 },
        { id: "foVillague14", structureId: "mystructure:foVWell01", rotation: "None", x: 400519, y: 1, z: 400521 },
        { id: "foVillague15", structureId: "mystructure:foVPumpkins01", rotation: "None", x: 400515, y: 2, z: 400539 },
        { id: "foVillague16", structureId: "mystructure:foVHouse01", rotation: "Rotate270", x: 400505, y: 1, z: 400497 },
        { id: "foVillague17", structureId: "mystructure:foVHouse02", rotation: "Rotate90", x: 400506, y: 1, z: 400508 },
        { id: "foVillague18", structureId: "mystructure:foVBlacksmith01", rotation: "Rotate90", x: 400483, y: 1, z: 400491 },
        { id: "foVillague19", structureId: "mystructure:foVBlacksmith02", rotation: "Rotate90", x: 400480, y: 1, z: 400502 },
        { id: "foVillague20", structureId: "mystructure:foVFarm04", rotation: "None", x: 400466, y: 2, z: 400496 },
        { id: "foVillague21", structureId: "mystructure:foVFarm02", rotation: "Rotate90", x: 400462, y: 2, z: 400512 },
        { id: "foVillague22", structureId: "mystructure:foVHouse10", rotation: "Rotate180", x: 400472, y: 1, z: 400525 },
        { id: "foVillague23", structureId: "mystructure:foVHouse06", rotation: "Rotate180", x: 400485, y: 1, z: 400524 },
        { id: "foVillague24", structureId: "mystructure:foVHouse05", rotation: "Rotate270", x: 400500, y: 1, z: 400525 },
        { id: "foVillague25", structureId: "mystructure:foVBlacksmith03", rotation: "Rotate180", x: 400500, y: 1, z: 400537 },
        { id: "foVillague26", structureId: "mystructure:foVHouse08", rotation: "None", x: 400486, y: 1, z: 400539 },
        { id: "foVillague27", structureId: "mystructure:foVHouse09", rotation: "None", x: 400474, y: 1, z: 400534 },
        { id: "foVillague28", structureId: "mystructure:foVBell01", rotation: "None", x: 400476, y: 2, z: 400545 },
        { id: "foVillague29", structureId: "mystructure:foVHouse11", rotation: "Rotate180", x: 400466, y: 1, z: 400543 },
        { id: "foVillague30", structureId: "mystructure:foVHouse12", rotation: "None", x: 400468, y: 1, z: 400552 },
        { id: "foVillague31", structureId: "mystructure:foVHouse09", rotation: "Rotate270", x: 400479, y: 1, z: 400553 },
        { id: "foVillague32", structureId: "mystructure:foVHouse10", rotation: "Rotate90", x: 400488, y: 1, z: 400555 },
        { id: "foVillague33", structureId: "mystructure:foVFarm01", rotation: "Rotate180", x: 400486, y: 2, z: 400571 },
        { id: "foVillague34", structureId: "mystructure:foVChurch01", rotation: "None", x: 400508, y: 1, z: 400556 }
    ];

    const foMirrorCoords = [
        { x: 100080, z: 100064, id: "Mirror01", xb: -192, zb: -192 },
        { x: 100080, z: 100128, id: "Mirror02", xb: -192, zb: -128 },
        { x: 100080, z: 100192, id: "Mirror03", xb: -192, zb: -64 },
        { x: 100080, z: 100256, id: "Mirror04", xb: -192, zb: 0 },
        { x: 100080, z: 100320, id: "Mirror05", xb: -192, zb: 64 },
        { x: 100080, z: 100384, id: "Mirror06", xb: -192, zb: 128 },
        { x: 100144, z: 100064, id: "Mirror07", xb: -128, zb: -192 },
        { x: 100144, z: 100128, id: "Mirror08", xb: -128, zb: -128 },
        { x: 100144, z: 100192, id: "Mirror09", xb: -128, zb: -64 },
        { x: 100144, z: 100256, id: "Mirror10", xb: -128, zb: 0 },
        { x: 100144, z: 100320, id: "Mirror11", xb: -128, zb: 64 },
        { x: 100144, z: 100384, id: "Mirror12", xb: -128, zb: 128 },
        { x: 100208, z: 100064, id: "Mirror13", xb: -64, zb: -192 },
        { x: 100208, z: 100128, id: "Mirror14", xb: -64, zb: -128 },
        { x: 100208, z: 100192, id: "Mirror15", xb: -64, zb: -64 },
        { x: 100208, z: 100256, id: "Mirror16", xb: -64, zb: 0 },
        { x: 100208, z: 100320, id: "Mirror17", xb: -64, zb: 64 },
        { x: 100208, z: 100384, id: "Mirror18", xb: -64, zb: 128 },
        { x: 100272, z: 100064, id: "Mirror19", xb: 0, zb: -192 },
        { x: 100272, z: 100128, id: "Mirror20", xb: 0, zb: -128 },
        { x: 100272, z: 100192, id: "Mirror21", xb: 0, zb: -64 },
        { x: 100272, z: 100256, id: "Mirror22", xb: 0, zb: 0 },
        { x: 100272, z: 100320, id: "Mirror23", xb: 0, zb: 64 },
        { x: 100272, z: 100384, id: "Mirror24", xb: 0, zb: 128 },
        { x: 100336, z: 100064, id: "Mirror25", xb: 64, zb: -192 },
        { x: 100336, z: 100128, id: "Mirror26", xb: 64, zb: -128 },
        { x: 100336, z: 100192, id: "Mirror27", xb: 64, zb: -64 },
        { x: 100336, z: 100256, id: "Mirror28", xb: 64, zb: 0 },
        { x: 100336, z: 100320, id: "Mirror29", xb: 64, zb: 64 },
        { x: 100336, z: 100384, id: "Mirror30", xb: 64, zb: 128 },
        { x: 100400, z: 100064, id: "Mirror31", xb: 128, zb: -192 },
        { x: 100400, z: 100128, id: "Mirror32", xb: 128, zb: -128 },
        { x: 100400, z: 100192, id: "Mirror33", xb: 128, zb: -64 },
        { x: 100400, z: 100256, id: "Mirror34", xb: 128, zb: 0 },
        { x: 100400, z: 100320, id: "Mirror35", xb: 128, zb: 64 },
        { x: 100400, z: 100384, id: "Mirror36", xb: 128, zb: 128 }
    ];

    
    const PROCESSED_MONOLITH_COORDS_PROPERTY = "processedMonolithCoords";
    const PROCESSED_DIMENSION_COORDS_PROPERTY = "processedDimensionCoords";
    const PROCESSED_VILLAGE_COORDS_PROPERTY = "processedVillageCoords";
    const PROCESSED_MIRROR_COORDS_PROPERTY = "processedMirrorCoords";
    const WORLD_GEN_PROGRESS_PROPERTY = "worldGenProgress";

    
    const defaultWorldGenProgress = {
        monoliths: false,
        dimensions: false,
        village: false,
        mirror: false,
        
        details: {
            monolithsCompleted: 0,
            dimensionsCompleted: 0,
            villageCompleted: 0,
            mirrorCompleted: 0,
        }
    };

    
    let
        isProcessingMonolith = false,
        isProcessingDimension = false,
        isProcessingVillage = false,
        isProcessingMirror = false;

    
    function getWorldGenProgress() {
        const progressData = world.getDynamicProperty(WORLD_GEN_PROGRESS_PROPERTY);
        return progressData ? JSON.parse(progressData) : { ...defaultWorldGenProgress };
    }

    
    function updateWorldGenProgress(updates) {
        const currentProgress = getWorldGenProgress();
        const newProgress = {
            ...currentProgress,
            ...updates,
            details: {
                ...currentProgress.details,
                ...updates.details,
            }
        };
        world.setDynamicProperty(WORLD_GEN_PROGRESS_PROPERTY, JSON.stringify(newProgress));
        return newProgress;
    }

    
    function markPhaseCompleted(phaseName) {
        return updateWorldGenProgress({ [phaseName]: true });
    }

    
    function getBaseLocation() {
        const data = world.getDynamicProperty("base_location");
        return data ? JSON.parse(data) : null;
    }

    
    function markCoordProcessed(id, property) {
        const processedCoords = JSON.parse(world.getDynamicProperty(property) || "[]");
        if (!processedCoords.includes(id)) {
            processedCoords.push(id);
            world.setDynamicProperty(property, JSON.stringify(processedCoords));
        }
    }

    
    function isMonolithCoordProcessed(id, property) {
        const processedData = world.getDynamicProperty(property);

        if (!processedData) {
            return false;
        }

        try {
            const progressData = JSON.parse(processedData);
            return progressData[id] && progressData[id].completed === true;
        } catch (error) {
            return false;
        }
    };

    
    function updateMonolithProgress(id, currentY, completed = false) {
        const existingData = world.getDynamicProperty(PROCESSED_MONOLITH_COORDS_PROPERTY);
        let progressData = {};

        if (existingData) {
            try {
                progressData = JSON.parse(existingData);
            } catch (error) {
                console.error(`Error parsing progress data: ${error}`);
            }
        }

        progressData[id] = {
            id: id,
            currentY: currentY,
            completed: completed,
        };

        world.setDynamicProperty(PROCESSED_MONOLITH_COORDS_PROPERTY, JSON.stringify(progressData));
    }

    
    function isCoordProcessed(id, property) {
        const processedCoords = JSON.parse(world.getDynamicProperty(property) || "[]");
        return processedCoords.includes(id);
    }

    
    function isWaterOrIceBlock(block) {
        return block.typeId === "minecraft:water" || block.typeId === "minecraft:ice";
    }

    
    function testForWaterOrIce(overworld, x, z) {
        const testCoords = [
            { x: x + 0, z: z + 0 },
            { x: x + 0, z: z + 15 },
            { x: x + 0, z: z + 30 },
            { x: x + 0, z: z + 45 },
            { x: x + 15, z: z + 0 },
            { x: x + 15, z: z + 15 },
            { x: x + 15, z: z + 30 },
            { x: x + 15, z: z + 45 },
            { x: x + 30, z: z + 0 },
            { x: x + 30, z: z + 15 },
            { x: x + 30, z: z + 30 },
            { x: x + 30, z: z + 45 },
            { x: x + 45, z: z + 0 },
            { x: x + 45, z: z + 15 },
            { x: x + 45, z: z + 30 },
            { x: x + 45, z: z + 45 },
        ];

        let waterOrIceCount = 0;

        for (const coord of testCoords) {
            const block = overworld.getBlock({ x: coord.x, y: 60, z: coord.z });
            if (block && isWaterOrIceBlock(block)) {
                waterOrIceCount++;
            }

            
            if (waterOrIceCount >= 5) {
                break;
            }
        }

        return waterOrIceCount >= 5;
    }

    
    async function processMonolithCoord(coord) {
        const { x, z, id } = coord;

        
        if (isMonolithCoordProcessed(id, PROCESSED_MONOLITH_COORDS_PROPERTY)) {
            
            return;
        }
        const overworld = fo.overworld;

        

        const savedData = world.getDynamicProperty(PROCESSED_MONOLITH_COORDS_PROPERTY);

        const progress = savedData ? JSON.parse(savedData)[id] : null;
        const startLayer = progress && progress.currentY !== undefined ? progress.currentY + 1 : -20;

        
        
        overworld.runCommand(`tickingarea add ${x} 0 ${z} ${x + 63} 0 ${z + 63} foAlphaMonolith`);

        await system.waitTicks(10 * 20 * fo.performanceModifier); 

        const isResuming = startLayer > -20;
        const totalLayers = 250;
        const structureManager = world.structureManager;

        if (!isResuming) {
            
            if (testForWaterOrIce(overworld, x, z)) {
                
                overworld.runCommand(`tickingarea remove foAlphaMonolith`);
                updateMonolithProgress(id, 230, true); 
                return;
            }
            

            for (let layer = startLayer + 20; layer < totalLayers; layer++) {
                const currentY = -20 + layer;

                
                const saveOptions = {
                    saveMode: "World",
                    includeEntities: true,
                    includeBlocks: true,
                };
                try {
                    structureManager.createFromWorld(
                        `mystructure:${id}_layer_${layer}`,
                        overworld,
                        { x, y: currentY, z },
                        { x: x + 63, y: currentY, z: z + 63 },
                        saveOptions
                    );
                } catch (e) { }

                await system.waitTicks(4 * fo.performanceModifier);
            }

        } else {
            
        }

        const MonolithPlaceTime = Math.round((140 * 20) / totalLayers * fo.performanceModifier); 

        

        for (let layer = startLayer + 20; layer < totalLayers; layer++) {
            const currentY = -20 + layer;
            const targetY = 41 + layer;

            
            const placeOptions = {
                animationMode: "Layers",
                animationSeconds: MonolithPlaceTime / 20,
            };

            try {
                structureManager.place(
                    `mystructure:${id}_layer_${layer}`,
                    overworld,
                    { x, y: targetY, z },
                    placeOptions
                );
            } catch (e) {
                
            }

            await system.waitTicks(MonolithPlaceTime + 1);

            overworld.runCommand(`execute positioned ${x} 0 ${z} run kill @e [type=item, r=600]`)
            structureManager.delete(`mystructure:${id}_layer_${layer}`);
            updateMonolithProgress(id, currentY, false);
        }

        
        if (!isResuming || startLayer + 20 >= totalLayers) {
            
            

            const PrimalSeaPlaceTime = Math.round(11 * fo.performanceModifier); 

            const placeOptions2 = {
                animationMode: "Layers",
                animationSeconds: PrimalSeaPlaceTime / 20,
            };

            for (let i = 0; i < 64; i++) {
                const currentZ = z + i;
                structureManager.place(
                    "mystructure:foMonolithWater",
                    overworld,
                    { x, y: -50, z: currentZ },
                    placeOptions2
                );
                await system.waitTicks(PrimalSeaPlaceTime + 1);
                overworld.runCommand(`execute positioned ${x} 0 ${z} run kill @e [type=item, r=600]`)
            }

            
        }

        
        

        overworld.runCommand(`tickingarea remove foAlphaMonolith`);
        
        updateMonolithProgress(id, 230, true);
        
        await system.waitTicks(1);
    };

    
    async function processDimensionCoord(coord) {
        const { x, z, id } = coord;
        const theEnd = fo.theEnd;

        
        
        theEnd.runCommand(`tickingarea remove foVoid`);
        theEnd.runCommand(`tickingarea add ${x} 0 ${z} ${x + 63} 0 ${z + 63} foVoid`);
        await system.waitTicks(5 * 20 * fo.performanceModifier); 

        
        
        const structureManager = world.structureManager;
        const placeTimer = Math.round(0.5 * 20 * fo.performanceModifier);

        const placeOptions = {
            animationMode: "Layers",
            animationSeconds: placeTimer / 20,
        };

        
        for (let i = 0; i < 64; i++) {
            
            const currentZ = z + i;

            
            structureManager.place(
                "mystructure:foVoid",
                theEnd,
                { x, y: 0, z: currentZ }, 
                placeOptions
            );

            
            await system.waitTicks(placeTimer + 1); 
        };

        theEnd.runCommand(`execute positioned ${x + 32} 100 ${z + 32} run kill @e[r=300]`); 
        await system.waitTicks(1); 
        theEnd.runCommand(`execute positioned ${x + 32} 100 ${z + 32} run kill @e[type=item, r=300]`); 
        await system.waitTicks(1); 

        

        
        
        theEnd.runCommand(`tickingarea remove foVoid`);

        
        markCoordProcessed(id, PROCESSED_DIMENSION_COORDS_PROPERTY);
    };

    
    async function processVillageCoord(coord) {
        const { x, y, z, id, structureId, rotation } = coord;
        const theEnd = fo.theEnd;

        
        
        theEnd.runCommand(`tickingarea remove foVoidVillague`);
        theEnd.runCommand(`tickingarea add ${x - 20} 0 ${z - 20} ${x + 20} 0 ${z + 20} foVoidVillague`);
        await system.waitTicks(10 * 20 * fo.performanceModifier); 

        

        const placeTimer = 2 * 20 * fo.performanceModifier;

        try {
            
            world.structureManager.place(
                structureId,
                theEnd,
                { x, y, z },
                {
                    animationMode: "Layers",
                    animationSeconds: placeTimer / 20,
                    rotation: rotation,
                    includeEntities: false
                }
            );

            await system.waitTicks(placeTimer + 5);

            theEnd.runCommand(`execute positioned ${x} 0 ${z} run kill @e [type=item, r=600]`)

            await system.waitTicks(1);
            

            
            
            theEnd.runCommand(`tickingarea remove foVoidVillague`);

            
            markCoordProcessed(id, PROCESSED_VILLAGE_COORDS_PROPERTY);

        } catch (error) {
            
        }
    };


    
    async function processMirrorCoord(coord) {
        const { x, y, z, id, xb, zb } = coord;
        const bedBase = getBaseLocation();
        const xbc = bedBase.x + xb;
        const ybc = bedBase.y
        const zbc = bedBase.z + zb;
        const nether = fo.nether;
        const overworld = fo.overworld;

        
        
        nether.runCommand(`tickingarea remove foNetherMirror`);
        overworld.runCommand(`tickingarea remove foOverworldMirror`);

        overworld.runCommand(`tickingarea add ${xbc} 0 ${zbc} ${xbc + 63} 0 ${zbc + 63} foOverworldMirror`);
        await system.waitTicks(180 * fo.performanceModifier); 

        const structureManager = world.structureManager;
        structureManager.delete(`mystructure:${id}_terrain`);
        await system.waitTicks(20)

        
        
        const saveOptions = {
            saveMode: "Memory",
            includeEntities: true,
            includeBlocks: true,
        };
        try {
            structureManager.createFromWorld(
                `mystructure:${id}_terrain`,
                overworld,
                { x: xbc, y: ybc - 60, z: zbc },
                { x: xbc + 63, y: ybc + 65, z: zbc + 63 },
                saveOptions
            );
        } catch (e) {
            console.warn(`Unable to save location for Mirror World: ${e}`)
        }
        await system.waitTicks(200 * fo.performanceModifier); 


        
        

        nether.runCommand(`tickingarea add ${x} 0 ${z} ${x + 63} 127 ${z + 63} foNetherMirror`);
        await system.waitTicks(100 * fo.performanceModifier); 

        
        for (let i = 0; i < 125; i++) {
            system.runTimeout(() => {
                nether.runCommand(`fill ${x} ${i + 2} ${z} ${x + 63} ${i + 2} ${z + 63} air replace lava`)
            }, i)
        } await system.waitTicks(127)

        
        for (let i = 0; i < 125; i++) {
            system.runTimeout(() => {
                nether.runCommand(`fill ${x} ${i + 1} ${z} ${x + 63} ${i + 2} ${z + 63} air replace flowing_lava`)
            }, i)
        } await system.waitTicks(127)

        

        const placeTime = Math.round(100 * 20 * fo.performanceModifier)
        try {
            
            structureManager.place(
                `mystructure:${id}_terrain`,
                nether,
                { x: x, y: 2, z: z },
                {
                    animationMode: "Layers",
                    animationSeconds: placeTime / 20,
                    includeEntities: true
                }
            );

            await system.waitTicks(placeTime + 1); 

            nether.runCommand(`execute positioned ${x + 32} 100 ${z + 32} run kill @e[type=item, r=300]`); 
            await system.waitTicks(1);

            

            
            
            structureManager.delete(`mystructure:${id}_terrain`);
            nether.runCommand(`tickingarea remove foNetherMirror`);
            overworld.runCommand(`tickingarea remove foOverworldMirror`);

            
            markCoordProcessed(id, PROCESSED_MIRROR_COORDS_PROPERTY);

        } catch (error) {
            
        }
    };

    
    async function processAllMonolithCoords() {
        if (isProcessingMonolith) {
            return;
        }

        isProcessingMonolith = true;

        for (const coord of monolithCoords) {
            await processMonolithCoord(coord);
        }

        markPhaseCompleted('monoliths');
        startWorldGen();
        isProcessingMonolith = false;
    };

    
    async function processAllDimensionCoords() {
        if (isProcessingDimension) {
            return;
        }

        isProcessingDimension = true;

        for (const coord of dimensionCoords) {
            if (!isCoordProcessed(coord.id, PROCESSED_DIMENSION_COORDS_PROPERTY)) {
                await processDimensionCoord(coord);
            }
        }

        markPhaseCompleted('dimensions');
        startWorldGen();
        isProcessingDimension = false;
    }

    
    async function processAllVillageCoords() {
        if (isProcessingVillage) {
            return;
        }

        isProcessingVillage = true;

        for (const coord of villageCoords) {
            if (!isCoordProcessed(coord.id, PROCESSED_VILLAGE_COORDS_PROPERTY)) {
                await processVillageCoord(coord);
            }
        }

        markPhaseCompleted('village');
        startWorldGen();
        isProcessingVillage = false;
    }

    
    async function processAllMirrorCoords() {
        if (isProcessingMirror) {
            return;
        }

        isProcessingMirror = true;

        for (const coord of foMirrorCoords) {
            if (!isCoordProcessed(coord.id, PROCESSED_MIRROR_COORDS_PROPERTY)) {
                await processMirrorCoord(coord);
            }
        }

        markPhaseCompleted('mirror');
        startWorldGen();
        isProcessingMirror = false;
    }


    
    system.runTimeout(startWorldGen, 1157)

    function startWorldGen() {
        const progress = getWorldGenProgress();

        
        const processedMonolithData = JSON.parse(world.getDynamicProperty(PROCESSED_MONOLITH_COORDS_PROPERTY) || "{}");
        const processedDimensionCoords = JSON.parse(world.getDynamicProperty(PROCESSED_DIMENSION_COORDS_PROPERTY) || "[]");
        const processedVillageCoords = JSON.parse(world.getDynamicProperty(PROCESSED_VILLAGE_COORDS_PROPERTY) || "[]");
        const processedMirrorCoords = JSON.parse(world.getDynamicProperty(PROCESSED_MIRROR_COORDS_PROPERTY) || "[]");

        
        const allMonolithProcessed = progress.monoliths || monolithCoords.every(coord => processedMonolithData[coord.id]?.completed === true);
        const allDimensionProcessed = progress.dimensions || processedDimensionCoords.length >= dimensionCoords.length;
        const allVillageProcessed = progress.village || processedVillageCoords.length >= villageCoords.length;
        const allMirrorProcessed = progress.mirror || processedMirrorCoords.length >= foMirrorCoords.length;

        const mirrorBaseLocation = getBaseLocation();

        
        if (allMonolithProcessed && !progress.monoliths) updateWorldGenProgress({ monoliths: true, details: { monolithsCompleted: monolithCoords.length } });
        if (allDimensionProcessed && !progress.dimensions) updateWorldGenProgress({ dimensions: true, details: { dimensionsCompleted: dimensionCoords.length } });
        if (allVillageProcessed && !progress.village) updateWorldGenProgress({ village: true, details: { villageCompleted: villageCoords.length } });
        if (allMirrorProcessed && !progress.mirror) updateWorldGenProgress({ mirror: true, details: { mirrorCompleted: foMirrorCoords.length } });

        

        
        if (!allMonolithProcessed) {
            processAllMonolithCoords();
        } else if (!allDimensionProcessed) {
            processAllDimensionCoords();
        } else if (!allVillageProcessed) {
            processAllVillageCoords();
        } else if (!allMirrorProcessed && mirrorBaseLocation !== null) {
            processAllMirrorCoords();
        } else {
            
        }
    }

}
