import { world, system, BlockPermutation } from '@minecraft/server';
const entityTypeId = "sapphire_portality:portal_black";
const entityTypeIdItem = "minecraft:item";
const list_dimention = ["overworld", "nether", "the_end"]
let black_Portal_1 = [
    { x: undefined, y: undefined, z: undefined },
    { directionX: 0, directionZ: 0, horizontalStrength: 0, verticalStrength: 0 },
    { full: 0 },
    { x: undefined, y: undefined, z: undefined },
    { x: undefined, y: undefined, z: undefined },
    { x: undefined, y: undefined, z: undefined },
    "",
    { x: undefined, y: undefined, z: undefined },
    { x: 0, z: 0 }
];
let black_Portal_2 = [
    { x: undefined, y: undefined, z: undefined },
    { directionX: 0, directionZ: 0, horizontalStrength: 0, verticalStrength: 0 },
    { full: 0 },
    { x: undefined, y: undefined, z: undefined },
    { x: undefined, y: undefined, z: undefined },
    { x: undefined, y: undefined, z: undefined },
    "",
    { x: undefined, y: undefined, z: undefined },
    { x: 0, z: 0 }
]
// console.warn("black_2:", JSON.stringify(black_Portal_2[0].x, null, 2));
// console.warn("entity.location:", JSON.stringify(entity.location, null, 2));
let entities;
let entity_close;
let black_teleported = false;
let portal_1 = 0;
let portal_2 = 0;
let black_item_teleported = false;
function Spawn() {
    if (!black_teleported || !black_item_teleported) {
        for (let index = 0; index < list_dimention.length; index++) {
            const var_dimension = list_dimention[index];
            entities = world.getDimension(var_dimension).getEntities({ type: entityTypeId });
            for (const aux of entities) {
                entity_close = aux.id;
            }
            if (black_Portal_1[0].x != undefined && black_Portal_2[0].x != undefined) {
                for (const entity of entities) {
                    DetectFullPortal(entity, var_dimension);
                    if (black_Portal_1[2].full == 1 && black_Portal_2[2].full == 1) {
                        entity.triggerEvent("animation_turn_on")
                    } else {
                        entity.triggerEvent("animation_turn_off")
                    }
                }
            } else {
                for (const entity of entities) {
                    if (DetectPLacementPortal(entity)) {
                        entity.triggerEvent("animation_edge_off")
                    }
                }
            }
            for (const entity of entities) {
                if (black_Portal_1[0].x != undefined && black_Portal_2[0].x != undefined && !areLocationsEqual(black_Portal_1[0], entity.location) && !areLocationsEqual(black_Portal_2[0], entity.location)) {
                    entity.triggerEvent("instant_despawn")
                    world.sendMessage("§lThe §8Portals§r§l are already connected.")
                    return
                } else {
                    if (entity.getComponent('skin_id').value != 1) {
                        if (black_Portal_1[0].x === undefined) {
                            if (black_Portal_2[0].x !== undefined) {
                                if (!areLocationsEqual(black_Portal_2[0], entity.location)) {
                                    if (DetectPLacementPortal(entity)) {
                                        black_Portal_1[0].x = entity.location.x;
                                        black_Portal_1[0].y = entity.location.y;
                                        black_Portal_1[0].z = entity.location.z;
                                        entity.triggerEvent("animation_edge_off");
                                        if (entity.getComponent('variant').value == 0) {
                                            entity.triggerEvent("structure_1");
                                        }
                                        portal_1 = 0;
                                    } else if (!DetectPLacementPortal(entity) && portal_1 == 0) {
                                        world.sendMessage("§lRemove the blocks inside the designated area!")
                                        portal_1++;
                                    }
                                    continue;
                                }
                            } else {
                                if (black_Portal_2[0].x === undefined || areLocationsEqual(black_Portal_2[0], entity.location)) {
                                    if (DetectPLacementPortal(entity)) {
                                        black_Portal_1[0].x = entity.location.x;
                                        black_Portal_1[0].y = entity.location.y;
                                        black_Portal_1[0].z = entity.location.z;
                                        entity.triggerEvent("animation_edge_off");
                                        if (entity.getComponent('variant').value == 0) {
                                            entity.triggerEvent("structure_1");
                                        }
                                        portal_1 = 0;
                                    } else if (!DetectPLacementPortal(entity) && portal_1 == 0) {
                                        world.sendMessage("§lRemove the blocks inside the designated area!")
                                        portal_1++;
                                    }
                                    continue;
                                }
                            }
                        } else if (black_Portal_2[0].x === undefined) {
                            if (black_Portal_1[0].x !== undefined) {
                                if (!areLocationsEqual(black_Portal_1[0], entity.location)) {
                                    if (DetectPLacementPortal(entity)) {
                                        black_Portal_2[0].x = entity.location.x;
                                        black_Portal_2[0].y = entity.location.y;
                                        black_Portal_2[0].z = entity.location.z;
                                        entity.triggerEvent("animation_edge_off");
                                        if (entity.getComponent('variant').value == 0) {
                                            entity.triggerEvent("structure_1");
                                        }
                                        portal_2 = 0;
                                    } else if (!DetectPLacementPortal(entity) && portal_2 == 0) {
                                        world.sendMessage("§lRemove the blocks inside the designated area!")
                                        portal_2++;
                                    }
                                    continue;
                                }
                            } else {
                                if (black_Portal_1[0].x === undefined || areLocationsEqual(black_Portal_1[0], entity.location)) {
                                    if (DetectPLacementPortal(entity)) {
                                        black_Portal_2[0].x = entity.location.x;
                                        black_Portal_2[0].y = entity.location.y;
                                        black_Portal_2[0].z = entity.location.z;
                                        entity.triggerEvent("animation_edge_off");
                                        if (entity.getComponent('variant').value == 0) {
                                            entity.triggerEvent("structure_1");
                                        }
                                        portal_2 = 0;
                                    } else if (!DetectPLacementPortal(entity) && portal_2 == 0) {
                                        world.sendMessage("§lRemove the blocks inside the designated area!")
                                        portal_2++;
                                    }
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    /* for(const entity in entities){
         console.warn("black_1",entity.location.x);
     }*/
    /*player_1.teleport(
        { x: entity.location.x, y: entity.location.y + 1, z: entity.location.z }
    );*/
}
function areLocationsEqual(loc1, loc2) {
    return loc1.x === loc2.x && loc1.y === loc2.y && loc1.z === loc2.z;
}
function blackTeleportItems(item, entity) {

    if (black_Portal_1[0].x !== undefined && black_Portal_2[0].x !== undefined) {
        if (black_Portal_1[0].x !== undefined) {
            if ((areLocationsEqual(black_Portal_1[0], entity.location))) {
                if (black_Portal_1[2].full == 1 && black_Portal_2[2].full == 1) {
                    item.applyImpulse(black_Portal_1[3])
                    system.runTimeout(() => {
                        item.teleport(
                            {
                                x: black_Portal_2[7].x,
                                y: black_Portal_2[7].y + 1,
                                z: black_Portal_2[7].z
                            },
                            {
                                dimension: world.getDimension(black_Portal_2[6]),
                            }
                        );
                    }, 9);
                }
            }
        }
        if (black_Portal_2[0].x !== undefined) {
            if ((areLocationsEqual(black_Portal_2[0], entity.location))) {
                if (black_Portal_1[2].full == 1 && black_Portal_2[2].full == 1) {
                    item.applyImpulse(black_Portal_2[3])
                    system.runTimeout(() => {
                        item.teleport(
                            {
                                x: black_Portal_1[7].x,
                                y: black_Portal_1[7].y + 1,
                                z: black_Portal_1[7].z
                            },
                            {
                                dimension: world.getDimension(black_Portal_1[6]),
                            }
                        );
                    }, 9);
                }
            }
        }
    }
    //const entities = world.getDimension("overworld").getEntities({type: entityTypeId });
}
function Teleport() {
    for (let index = 0; index < list_dimention.length; index++) {
        const var_dimension = list_dimention[index];
        if (!black_teleported) {
            for (let player of world.getDimension(var_dimension).getPlayers()) {
                const entities = world.getDimension(var_dimension).getEntities({ type: entityTypeId, location: player.location, closest: 2, maxDistance: 2 });
                for (let entity of entities) {
                    const { x, y, z } = player.location;
                    const block = player.dimension.getBlock({ x, y: y - 1, z });
                    if (block?.permutation.matches('sapphire_portality:portal_black_block') || block?.permutation.matches('sapphire_portality:portal_black_east_block') || block?.permutation.matches('minecraft:barrier')) {
                        system.run(() => {
                            if (player != null || player != undefined || player != anonymous) {
                                blackTeleport(player, entity);
                                return;
                            }
                        });
                    }
                }
            }
        }
        if (!black_item_teleported) {
            const entities = world.getDimension(var_dimension).getEntities({ type: entityTypeId });
            for (const entity of entities) {
                const items = world.getDimension(var_dimension).getEntities({ type: entityTypeIdItem, location: entity.location, closest: 2, maxDistance: 2 });
                for (const item of items) {
                    const { x, y, z } = item.location;
                    const block = item.dimension.getBlock({ x, y: y - 1, z });
                    if (block?.permutation.matches('sapphire_portality:portal_black_block') || block?.permutation.matches('sapphire_portality:portal_black_east_block') || block?.permutation.matches('minecraft:barrier')) {
                        system.run(() => {
                            blackTeleportItems(item, entity);
                        });
                    }
                }
            }
        }
    }
}


function blackTeleport(player, entity) {
    if (black_Portal_1[0].x !== undefined && black_Portal_2[0].x !== undefined) {
        if (black_Portal_1[0].x !== undefined) {
            if ((areLocationsEqual(black_Portal_1[0], entity.location))) {
                if (black_Portal_1[2].full == 1 && black_Portal_2[2].full == 1) {
                    black_teleported = true;
                    player.runCommand("playsound sapphire_portality:teleport @s")
                    player.applyKnockback(black_Portal_1[1].directionX, black_Portal_1[1].directionZ, black_Portal_1[1].horizontalStrength, black_Portal_1[1].verticalStrength);
                    system.runTimeout(() => {
                        player.teleport(
                            {
                                x: black_Portal_2[0].x + black_Portal_2[8].x,
                                y: black_Portal_2[0].y + 2.5,
                                z: black_Portal_2[0].z + black_Portal_2[8].z
                            },
                            {
                                dimension: world.getDimension(black_Portal_2[6]),
                            }
                        );
                    }, 9);
                    if (black_Portal_1[6] != black_Portal_2[6]) {
                        world.afterEvents.playerDimensionChange.subscribe(data => {
                            if (black_teleported) {
                                const run_1 = system.runInterval(() => {
                                    const valid = player.isValid();
                                    const { x, y, z } = player.location;
                                    const block = player.dimension.getBlock({ x, y: y - 1, z });
                                    if (valid && (block?.permutation.matches('sapphire_portality:portal_black_block') || block?.permutation.matches('sapphire_portality:portal_black_east_block') || block?.permutation.matches('minecraft:barrier'))) {
                                        player.runCommand("playsound sapphire_portality:teleport @s")
                                        player.applyKnockback(-black_Portal_2[1].directionX, -black_Portal_2[1].directionZ, black_Portal_2[1].horizontalStrength, black_Portal_2[1].verticalStrength);
                                        system.clearRun(run_1)
                                        system.runTimeout(() => {
                                            black_teleported = false;
                                        }, 50);
                                        player.runCommand("scoreboard players set @a sapphire_portality_tick 0")
                                    }
                                }, 10);
                            }
                        })
                    } else {
                        const run_2 = system.runInterval(() => {
                            const valid = player.isValid();
                            const { x, y, z } = player.location;
                            const block = player.dimension.getBlock({ x, y: y - 1, z });
                            if (valid && (block?.permutation.matches('sapphire_portality:portal_black_block') || block?.permutation.matches('sapphire_portality:portal_black_east_block') || block?.permutation.matches('minecraft:barrier'))) {
                                player.runCommand("playsound sapphire_portality:teleport @s")
                                player.applyKnockback(-black_Portal_2[1].directionX, -black_Portal_2[1].directionZ, black_Portal_2[1].horizontalStrength, black_Portal_2[1].verticalStrength);
                                system.clearRun(run_2)
                                system.runTimeout(() => {
                                    black_teleported = false;
                                }, 50);
                                player.runCommand("scoreboard players set @a sapphire_portality_tick 0")
                            }
                        }, 10);
                    }
                }
            }
        }
        if (black_Portal_2[0].x !== undefined) {
            if ((areLocationsEqual(black_Portal_2[0], entity.location))) {
                if (black_Portal_1[2].full == 1 && black_Portal_2[2].full == 1) {
                    black_teleported = true;
                    player.runCommand("playsound sapphire_portality:teleport @s")
                    player.applyKnockback(black_Portal_2[1].directionX, black_Portal_2[1].directionZ, black_Portal_2[1].horizontalStrength, black_Portal_2[1].verticalStrength);
                    system.runTimeout(() => {
                        player.teleport(
                            {
                                x: black_Portal_1[0].x + black_Portal_1[8].x,
                                y: black_Portal_1[0].y + 2.5,
                                z: black_Portal_1[0].z + black_Portal_1[8].z
                            },
                            {
                                dimension: world.getDimension(black_Portal_1[6]),
                            }
                        );
                    }, 9);
                    if (black_Portal_1[6] != black_Portal_2[6]) {
                        world.afterEvents.playerDimensionChange.subscribe(data => {
                            if (black_teleported) {
                                const run_3 = system.runInterval(() => {
                                    const valid = player.isValid();
                                    const { x, y, z } = player.location;
                                    const block = player.dimension.getBlock({ x, y: y - 1, z });
                                    if (valid && (block?.permutation.matches('sapphire_portality:portal_black_block') || block?.permutation.matches('sapphire_portality:portal_black_east_block') || block?.permutation.matches('minecraft:barrier'))) {
                                        player.runCommand("playsound sapphire_portality:teleport @s")
                                        player.applyKnockback(-black_Portal_1[1].directionX, -black_Portal_1[1].directionZ, black_Portal_1[1].horizontalStrength, black_Portal_1[1].verticalStrength);
                                        system.clearRun(run_3)
                                        system.runTimeout(() => {
                                            black_teleported = false;
                                        }, 50);
                                        player.runCommand("scoreboard players set @a sapphire_portality_tick 0")
                                    }
                                }, 10);
                            }
                        })
                    } else {
                        const run_4 = system.runInterval(() => {
                            const valid = player.isValid();
                            const { x, y, z } = player.location;
                            const block = player.dimension.getBlock({ x, y: y - 1, z });
                            if (valid && (block?.permutation.matches('sapphire_portality:portal_black_block') || block?.permutation.matches('sapphire_portality:portal_black_east_block') || block?.permutation.matches('minecraft:barrier'))) {
                                player.runCommand("playsound sapphire_portality:teleport @s")
                                player.applyKnockback(-black_Portal_1[1].directionX, -black_Portal_1[1].directionZ, black_Portal_1[1].horizontalStrength, black_Portal_1[1].verticalStrength);
                                system.clearRun(run_4)
                                system.runTimeout(() => {
                                    black_teleported = false;
                                }, 50);
                                player.runCommand("scoreboard players set @a sapphire_portality_tick 0")
                            }
                        }, 10);
                    }
                }
            }
        }
    }
    //const entities = world.getDimension("overworld").getEntities({type: entityTypeId });
}
function DetectPLacementPortal(entity) {
    let fullblackPortal = 0;
    const { x, y, z } = entity.location;
    const front = [
        { x: x + 1, y: y, z: z },
        { x: x + 2, y: y, z: z },
        { x: x + 2, y: y + 1, z: z },
        { x: x + 2, y: y + 2, z: z },
        { x: x + 2, y: y + 3, z: z },
        { x: x + 2, y: y + 4, z: z },
        { x: x + 1, y: y + 4, z: z },
        { x: x, y: y + 4, z: z },
        { x: x - 1, y: y + 4, z: z },
        { x: x - 2, y: y + 4, z: z },
        { x: x - 2, y: y + 3, z: z },
        { x: x - 2, y: y + 2, z: z },
        { x: x - 2, y: y + 1, z: z },
        { x: x - 2, y: y, z: z },
        { x: x - 1, y: y, z: z },
        { x: x + 1, y: y, z: z + 1 },
        { x: x + 2, y: y, z: z + 1 },
        { x: x + 2, y: y + 1, z: z + 1 },
        { x: x + 2, y: y + 2, z: z + 1 },
        { x: x + 2, y: y + 3, z: z + 1 },
        { x: x + 2, y: y + 4, z: z + 1 },
        { x: x + 1, y: y + 4, z: z + 1 },
        { x: x, y: y + 4, z: z + 1 },
        { x: x - 1, y: y + 4, z: z + 1 },
        { x: x - 2, y: y + 4, z: z + 1 },
        { x: x - 2, y: y + 3, z: z + 1 },
        { x: x - 2, y: y + 2, z: z + 1 },
        { x: x - 2, y: y + 1, z: z + 1 },
        { x: x - 2, y: y, z: z + 1 },
        { x: x - 1, y: y, z: z + 1 },
        { x: x, y: y, z: z + 1 },
        { x: x + 1, y: y, z: z + 2 },
        { x: x + 2, y: y, z: z + 2 },
        { x: x + 2, y: y + 1, z: z + 2 },
        { x: x + 2, y: y + 2, z: z + 2 },
        { x: x + 2, y: y + 3, z: z + 2 },
        { x: x + 2, y: y + 4, z: z + 2 },
        { x: x + 1, y: y + 4, z: z + 2 },
        { x: x, y: y + 4, z: z + 2 },
        { x: x - 1, y: y + 4, z: z + 2 },
        { x: x - 2, y: y + 4, z: z + 2 },
        { x: x - 2, y: y + 3, z: z + 2 },
        { x: x - 2, y: y + 2, z: z + 2 },
        { x: x - 2, y: y + 1, z: z + 2 },
        { x: x - 2, y: y, z: z + 2 },
        { x: x - 1, y: y, z: z + 2 },
        { x: x, y: y, z: z + 2 },
        { x: x, y: y + 1, z: z },
        { x: x, y: y + 1, z: z + 1 },
        { x: x, y: y + 1, z: z + 2 },
        { x: x + 1, y: y + 1, z: z },
        { x: x - 1, y: y + 1, z: z },
        { x: x + 1, y: y + 1, z: z + 1 },
        { x: x - 1, y: y + 1, z: z + 1 },
        { x: x + 1, y: y + 1, z: z + 2 },
        { x: x - 1, y: y + 1, z: z + 2 },
        { x: x, y: y + 2, z: z },
        { x: x, y: y + 2, z: z + 1 },
        { x: x, y: y + 2, z: z + 2 },
        { x: x + 1, y: y + 2, z: z },
        { x: x - 1, y: y + 2, z: z },
        { x: x + 1, y: y + 2, z: z + 1 },
        { x: x - 1, y: y + 2, z: z + 1 },
        { x: x + 1, y: y + 2, z: z + 2 },
        { x: x - 1, y: y + 2, z: z + 2 },
        { x: x, y: y + 3, z: z },
        { x: x, y: y + 3, z: z + 1 },
        { x: x, y: y + 3, z: z + 2 },
        { x: x + 1, y: y + 3, z: z },
        { x: x - 1, y: y + 3, z: z },
        { x: x + 1, y: y + 3, z: z + 1 },
        { x: x - 1, y: y + 3, z: z + 1 },
        { x: x + 1, y: y + 3, z: z + 2 },
        { x: x - 1, y: y + 3, z: z + 2 },
    ];
    const back = [
        { x: x + 1, y: y, z: z },
        { x: x + 2, y: y, z: z },
        { x: x + 2, y: y + 1, z: z },
        { x: x + 2, y: y + 2, z: z },
        { x: x + 2, y: y + 3, z: z },
        { x: x + 2, y: y + 4, z: z },
        { x: x + 1, y: y + 4, z: z },
        { x: x, y: y + 4, z: z },
        { x: x - 1, y: y + 4, z: z },
        { x: x - 2, y: y + 4, z: z },
        { x: x - 2, y: y + 3, z: z },
        { x: x - 2, y: y + 2, z: z },
        { x: x - 2, y: y + 1, z: z },
        { x: x - 2, y: y, z: z },
        { x: x - 1, y: y, z: z },
        { x: x + 1, y: y, z: z - 1 },
        { x: x + 2, y: y, z: z - 1 },
        { x: x + 2, y: y + 1, z: z - 1 },
        { x: x + 2, y: y + 2, z: z - 1 },
        { x: x + 2, y: y + 3, z: z - 1 },
        { x: x + 2, y: y + 4, z: z - 1 },
        { x: x + 1, y: y + 4, z: z - 1 },
        { x: x, y: y + 4, z: z - 1 },
        { x: x - 1, y: y + 4, z: z - 1 },
        { x: x - 2, y: y + 4, z: z - 1 },
        { x: x - 2, y: y + 3, z: z - 1 },
        { x: x - 2, y: y + 2, z: z - 1 },
        { x: x - 2, y: y + 1, z: z - 1 },
        { x: x - 2, y: y, z: z - 1 },
        { x: x - 1, y: y, z: z - 1 },
        { x: x, y: y, z: z - 1 },
        { x: x + 1, y: y, z: z - 2 },
        { x: x + 2, y: y, z: z - 2 },
        { x: x + 2, y: y + 1, z: z - 2 },
        { x: x + 2, y: y + 2, z: z - 2 },
        { x: x + 2, y: y + 3, z: z - 2 },
        { x: x + 2, y: y + 4, z: z - 2 },
        { x: x + 1, y: y + 4, z: z - 2 },
        { x: x, y: y + 4, z: z - 2 },
        { x: x - 1, y: y + 4, z: z - 2 },
        { x: x - 2, y: y + 4, z: z - 2 },
        { x: x - 2, y: y + 3, z: z - 2 },
        { x: x - 2, y: y + 2, z: z - 2 },
        { x: x - 2, y: y + 1, z: z - 2 },
        { x: x - 2, y: y, z: z - 2 },
        { x: x - 1, y: y, z: z - 2 },
        { x: x, y: y, z: z - 2 },
        { x: x, y: y + 1, z: z },
        { x: x, y: y + 1, z: z - 1 },
        { x: x, y: y + 1, z: z - 2 },
        { x: x + 1, y: y + 1, z: z },
        { x: x - 1, y: y + 1, z: z },
        { x: x + 1, y: y + 1, z: z - 1 },
        { x: x - 1, y: y + 1, z: z - 1 },
        { x: x + 1, y: y + 1, z: z - 2 },
        { x: x - 1, y: y + 1, z: z - 2 },
        { x: x, y: y + 2, z: z },
        { x: x, y: y + 2, z: z - 1 },
        { x: x, y: y + 2, z: z - 2 },
        { x: x + 1, y: y + 2, z: z },
        { x: x - 1, y: y + 2, z: z },
        { x: x + 1, y: y + 2, z: z - 1 },
        { x: x - 1, y: y + 2, z: z - 1 },
        { x: x + 1, y: y + 2, z: z - 2 },
        { x: x - 1, y: y + 2, z: z - 2 },
        { x: x, y: y + 3, z: z },
        { x: x, y: y + 3, z: z - 1 },
        { x: x, y: y + 3, z: z - 2 },
        { x: x + 1, y: y + 3, z: z },
        { x: x - 1, y: y + 3, z: z },
        { x: x + 1, y: y + 3, z: z - 1 },
        { x: x - 1, y: y + 3, z: z - 1 },
        { x: x + 1, y: y + 3, z: z - 2 },
        { x: x - 1, y: y + 3, z: z - 2 },
    ];
    const left = [
        { x: x, y: y, z: z + 1 },
        { x: x, y: y, z: z + 2 },
        { x: x, y: y + 1, z: z + 2 },
        { x: x, y: y + 2, z: z + 2 },
        { x: x, y: y + 3, z: z + 2 },
        { x: x, y: y + 4, z: z + 2 },
        { x: x, y: y + 4, z: z + 1 },
        { x: x, y: y + 4, z: z },
        { x: x, y: y + 4, z: z - 1 },
        { x: x, y: y + 4, z: z - 2 },
        { x: x, y: y + 3, z: z - 2 },
        { x: x, y: y + 2, z: z - 2 },
        { x: x, y: y + 1, z: z - 2 },
        { x: x, y: y, z: z - 2 },
        { x: x, y: y, z: z - 1 },
        { x: x + 1, y: y, z: z + 1 },
        { x: x + 1, y: y, z: z + 2 },
        { x: x + 1, y: y + 1, z: z + 2 },
        { x: x + 1, y: y + 2, z: z + 2 },
        { x: x + 1, y: y + 3, z: z + 2 },
        { x: x + 1, y: y + 4, z: z + 2 },
        { x: x + 1, y: y + 4, z: z + 1 },
        { x: x + 1, y: y + 4, z: z },
        { x: x + 1, y: y + 4, z: z - 1 },
        { x: x + 1, y: y + 4, z: z - 2 },
        { x: x + 1, y: y + 3, z: z - 2 },
        { x: x + 1, y: y + 2, z: z - 2 },
        { x: x + 1, y: y + 1, z: z - 2 },
        { x: x + 1, y: y, z: z - 2 },
        { x: x + 1, y: y, z: z - 1 },
        { x: x + 1, y: y, z: z },
        { x: x + 2, y: y, z: z + 1 },
        { x: x + 2, y: y, z: z + 2 },
        { x: x + 2, y: y + 1, z: z + 2 },
        { x: x + 2, y: y + 2, z: z + 2 },
        { x: x + 2, y: y + 3, z: z + 2 },
        { x: x + 2, y: y + 4, z: z + 2 },
        { x: x + 2, y: y + 4, z: z + 1 },
        { x: x + 2, y: y + 4, z: z },
        { x: x + 2, y: y + 4, z: z - 1 },
        { x: x + 2, y: y + 4, z: z - 2 },
        { x: x + 2, y: y + 3, z: z - 2 },
        { x: x + 2, y: y + 2, z: z - 2 },
        { x: x + 2, y: y + 1, z: z - 2 },
        { x: x + 2, y: y, z: z - 2 },
        { x: x + 2, y: y, z: z - 1 },
        { x: x + 2, y: y, z: z },
        { x: x, y: y + 1, z: z },
        { x: x + 1, y: y + 1, z: z },
        { x: x + 2, y: y + 1, z: z },
        { x: x, y: y + 1, z: z - 1 },
        { x: x, y: y + 1, z: z + 1 },
        { x: x + 1, y: y + 1, z: z - 1 },
        { x: x + 1, y: y + 1, z: z + 1 },
        { x: x + 2, y: y + 1, z: z - 1 },
        { x: x + 2, y: y + 1, z: z + 1 },
        { x: x, y: y + 2, z: z },
        { x: x + 1, y: y + 2, z: z },
        { x: x + 2, y: y + 2, z: z },
        { x: x, y: y + 2, z: z - 1 },
        { x: x, y: y + 2, z: z + 1 },
        { x: x + 1, y: y + 2, z: z - 1 },
        { x: x + 1, y: y + 2, z: z + 1 },
        { x: x + 2, y: y + 2, z: z - 1 },
        { x: x + 2, y: y + 2, z: z + 1 },
        { x: x, y: y + 3, z: z },
        { x: x + 1, y: y + 3, z: z },
        { x: x + 2, y: y + 3, z: z },
        { x: x, y: y + 3, z: z - 1 },
        { x: x, y: y + 3, z: z + 1 },
        { x: x + 1, y: y + 3, z: z - 1 },
        { x: x + 1, y: y + 3, z: z + 1 },
        { x: x + 2, y: y + 3, z: z - 1 },
        { x: x + 2, y: y + 3, z: z + 1 },
    ]
    const right = [
        { x: x, y: y, z: z + 1 },
        { x: x, y: y, z: z + 2 },
        { x: x, y: y + 1, z: z + 2 },
        { x: x, y: y + 2, z: z + 2 },
        { x: x, y: y + 3, z: z + 2 },
        { x: x, y: y + 4, z: z + 2 },
        { x: x, y: y + 4, z: z + 1 },
        { x: x, y: y + 4, z: z },
        { x: x, y: y + 4, z: z - 1 },
        { x: x, y: y + 4, z: z - 2 },
        { x: x, y: y + 3, z: z - 2 },
        { x: x, y: y + 2, z: z - 2 },
        { x: x, y: y + 1, z: z - 2 },
        { x: x, y: y, z: z - 2 },
        { x: x, y: y, z: z - 1 },
        { x: x - 1, y: y, z: z + 1 },
        { x: x - 1, y: y, z: z + 2 },
        { x: x - 1, y: y + 1, z: z + 2 },
        { x: x - 1, y: y + 2, z: z + 2 },
        { x: x - 1, y: y + 3, z: z + 2 },
        { x: x - 1, y: y + 4, z: z + 2 },
        { x: x - 1, y: y + 4, z: z + 1 },
        { x: x - 1, y: y + 4, z: z },
        { x: x - 1, y: y + 4, z: z - 1 },
        { x: x - 1, y: y + 4, z: z - 2 },
        { x: x - 1, y: y + 3, z: z - 2 },
        { x: x - 1, y: y + 2, z: z - 2 },
        { x: x - 1, y: y + 1, z: z - 2 },
        { x: x - 1, y: y, z: z - 2 },
        { x: x - 1, y: y, z: z - 1 },
        { x: x - 1, y: y, z: z },
        { x: x - 2, y: y, z: z + 1 },
        { x: x - 2, y: y, z: z + 2 },
        { x: x - 2, y: y + 1, z: z + 2 },
        { x: x - 2, y: y + 2, z: z + 2 },
        { x: x - 2, y: y + 3, z: z + 2 },
        { x: x - 2, y: y + 4, z: z + 2 },
        { x: x - 2, y: y + 4, z: z + 1 },
        { x: x - 2, y: y + 4, z: z },
        { x: x - 2, y: y + 4, z: z - 1 },
        { x: x - 2, y: y + 4, z: z - 2 },
        { x: x - 2, y: y + 3, z: z - 2 },
        { x: x - 2, y: y + 2, z: z - 2 },
        { x: x - 2, y: y + 1, z: z - 2 },
        { x: x - 2, y: y, z: z - 2 },
        { x: x - 2, y: y, z: z - 1 },
        { x: x - 2, y: y, z: z },
        { x: x, y: y + 1, z: z },
        { x: x - 1, y: y + 1, z: z },
        { x: x - 2, y: y + 1, z: z },
        { x: x, y: y + 1, z: z - 1 },
        { x: x, y: y + 1, z: z + 1 },
        { x: x - 1, y: y + 1, z: z - 1 },
        { x: x - 1, y: y + 1, z: z + 1 },
        { x: x - 2, y: y + 1, z: z - 1 },
        { x: x - 2, y: y + 1, z: z + 1 },
        { x: x, y: y + 2, z: z },
        { x: x - 1, y: y + 2, z: z },
        { x: x - 2, y: y + 2, z: z },
        { x: x, y: y + 2, z: z - 1 },
        { x: x, y: y + 2, z: z + 1 },
        { x: x - 1, y: y + 2, z: z - 1 },
        { x: x - 1, y: y + 2, z: z + 1 },
        { x: x - 2, y: y + 2, z: z - 1 },
        { x: x - 2, y: y + 2, z: z + 1 },
        { x: x, y: y + 3, z: z },
        { x: x - 1, y: y + 3, z: z },
        { x: x - 2, y: y + 3, z: z },
        { x: x, y: y + 3, z: z - 1 },
        { x: x, y: y + 3, z: z + 1 },
        { x: x - 1, y: y + 3, z: z - 1 },
        { x: x - 1, y: y + 3, z: z + 1 },
        { x: x - 2, y: y + 3, z: z - 1 },
        { x: x - 2, y: y + 3, z: z + 1 },
    ]
    // console.warn("dir_1:", JSON.stringify(entity.hasTag("dir_1"), null, 2));
    // console.warn("dir_2:", JSON.stringify(entity.hasTag("dir_2"), null, 2));
    // console.warn("dir_3:", JSON.stringify(entity.hasTag("dir_3"), null, 2));
    // console.warn("dir_4:", JSON.stringify(entity.hasTag("dir_4"), null, 2));
    fullblackPortal = 0;
    front.forEach(cords => {
        const block = entity.dimension.getBlock(cords);
        if (block?.permutation.matches('sapphire_portality:portal_black_block') || block?.permutation.matches('sapphire_portality:portal_black_east_block') || block?.permutation.matches('minecraft:air')) {
            fullblackPortal++;
        }
    });
    if (entity.hasTag("dir_4") && fullblackPortal == 74) {
        return true;
    }
    fullblackPortal = 0;
    left.forEach(cords => {
        const block = entity.dimension.getBlock(cords);
        if (block?.permutation.matches('sapphire_portality:portal_black_block') || block?.permutation.matches('sapphire_portality:portal_black_east_block') || block?.permutation.matches('minecraft:air')) {
            fullblackPortal++;
        }
    });
    if (entity.hasTag("dir_2") && fullblackPortal == 74) {
        return true;
    }
    fullblackPortal = 0;
    back.forEach(cords => {
        const block = entity.dimension.getBlock(cords);
        if (block?.permutation.matches('sapphire_portality:portal_black_block') || block?.permutation.matches('sapphire_portality:portal_black_east_block') || block?.permutation.matches('minecraft:air')) {
            fullblackPortal++;
        }
    });
    if (entity.hasTag("dir_1") && fullblackPortal == 74) {
        return true;
    }
    fullblackPortal = 0;
    right.forEach(cords => {
        const block = entity.dimension.getBlock(cords);
        if (block?.permutation.matches('sapphire_portality:portal_black_block') || block?.permutation.matches('sapphire_portality:portal_black_east_block') || block?.permutation.matches('minecraft:air')) {
            fullblackPortal++;
        }
    });
    if (entity.hasTag("dir_3") && fullblackPortal == 74) {
        return true;
    }
    return false;

}
function DetectFullPortal(entity, var_dimension) {
    let fullblackPortal_empty = 0;
    const { x, y, z } = entity.location;
    const front_empty = [
        { x: x, y: y + 1, z: z },
        { x: x, y: y + 1, z: z + 1 },
        { x: x, y: y + 1, z: z + 2 },
        { x: x + 1, y: y + 1, z: z },
        { x: x - 1, y: y + 1, z: z },
        { x: x + 1, y: y + 1, z: z + 1 },
        { x: x - 1, y: y + 1, z: z + 1 },
        { x: x + 1, y: y + 1, z: z + 2 },
        { x: x - 1, y: y + 1, z: z + 2 },
        { x: x, y: y + 2, z: z },
        { x: x, y: y + 2, z: z + 1 },
        { x: x, y: y + 2, z: z + 2 },
        { x: x + 1, y: y + 2, z: z },
        { x: x - 1, y: y + 2, z: z },
        { x: x + 1, y: y + 2, z: z + 1 },
        { x: x - 1, y: y + 2, z: z + 1 },
        { x: x + 1, y: y + 2, z: z + 2 },
        { x: x - 1, y: y + 2, z: z + 2 },
        { x: x, y: y + 3, z: z },
        { x: x, y: y + 3, z: z + 1 },
        { x: x, y: y + 3, z: z + 2 },
        { x: x + 1, y: y + 3, z: z },
        { x: x - 1, y: y + 3, z: z },
        { x: x + 1, y: y + 3, z: z + 1 },
        { x: x - 1, y: y + 3, z: z + 1 },
        { x: x + 1, y: y + 3, z: z + 2 },
        { x: x - 1, y: y + 3, z: z + 2 },
    ]
    const back_empty = [
        { x: x, y: y + 1, z: z },
        { x: x, y: y + 1, z: z - 1 },
        { x: x, y: y + 1, z: z - 2 },
        { x: x + 1, y: y + 1, z: z },
        { x: x - 1, y: y + 1, z: z },
        { x: x + 1, y: y + 1, z: z - 1 },
        { x: x - 1, y: y + 1, z: z - 1 },
        { x: x + 1, y: y + 1, z: z - 2 },
        { x: x - 1, y: y + 1, z: z - 2 },
        { x: x, y: y + 2, z: z },
        { x: x, y: y + 2, z: z - 1 },
        { x: x, y: y + 2, z: z - 2 },
        { x: x + 1, y: y + 2, z: z },
        { x: x - 1, y: y + 2, z: z },
        { x: x + 1, y: y + 2, z: z - 1 },
        { x: x - 1, y: y + 2, z: z - 1 },
        { x: x + 1, y: y + 2, z: z - 2 },
        { x: x - 1, y: y + 2, z: z - 2 },
        { x: x, y: y + 3, z: z },
        { x: x, y: y + 3, z: z - 1 },
        { x: x, y: y + 3, z: z - 2 },
        { x: x + 1, y: y + 3, z: z },
        { x: x - 1, y: y + 3, z: z },
        { x: x + 1, y: y + 3, z: z - 1 },
        { x: x - 1, y: y + 3, z: z - 1 },
        { x: x + 1, y: y + 3, z: z - 2 },
        { x: x - 1, y: y + 3, z: z - 2 },
    ]
    const left_empty = [
        { x: x, y: y + 1, z: z },
        { x: x + 1, y: y + 1, z: z },
        { x: x + 2, y: y + 1, z: z },
        { x: x, y: y + 1, z: z - 1 },
        { x: x, y: y + 1, z: z + 1 },
        { x: x + 1, y: y + 1, z: z - 1 },
        { x: x + 1, y: y + 1, z: z + 1 },
        { x: x + 2, y: y + 1, z: z - 1 },
        { x: x + 2, y: y + 1, z: z + 1 },
        { x: x, y: y + 2, z: z },
        { x: x + 1, y: y + 2, z: z },
        { x: x + 2, y: y + 2, z: z },
        { x: x, y: y + 2, z: z - 1 },
        { x: x, y: y + 2, z: z + 1 },
        { x: x + 1, y: y + 2, z: z - 1 },
        { x: x + 1, y: y + 2, z: z + 1 },
        { x: x + 2, y: y + 2, z: z - 1 },
        { x: x + 2, y: y + 2, z: z + 1 },
        { x: x, y: y + 3, z: z },
        { x: x + 1, y: y + 3, z: z },
        { x: x + 2, y: y + 3, z: z },
        { x: x, y: y + 3, z: z - 1 },
        { x: x, y: y + 3, z: z + 1 },
        { x: x + 1, y: y + 3, z: z - 1 },
        { x: x + 1, y: y + 3, z: z + 1 },
        { x: x + 2, y: y + 3, z: z - 1 },
        { x: x + 2, y: y + 3, z: z + 1 },
    ]
    const right_empty = [
        { x: x, y: y + 1, z: z },
        { x: x - 1, y: y + 1, z: z },
        { x: x - 2, y: y + 1, z: z },
        { x: x, y: y + 1, z: z - 1 },
        { x: x, y: y + 1, z: z + 1 },
        { x: x - 1, y: y + 1, z: z - 1 },
        { x: x - 1, y: y + 1, z: z + 1 },
        { x: x - 2, y: y + 1, z: z - 1 },
        { x: x - 2, y: y + 1, z: z + 1 },
        { x: x, y: y + 2, z: z },
        { x: x - 1, y: y + 2, z: z },
        { x: x - 2, y: y + 2, z: z },
        { x: x, y: y + 2, z: z - 1 },
        { x: x, y: y + 2, z: z + 1 },
        { x: x - 1, y: y + 2, z: z - 1 },
        { x: x - 1, y: y + 2, z: z + 1 },
        { x: x - 2, y: y + 2, z: z - 1 },
        { x: x - 2, y: y + 2, z: z + 1 },
        { x: x, y: y + 3, z: z },
        { x: x - 1, y: y + 3, z: z },
        { x: x - 2, y: y + 3, z: z },
        { x: x, y: y + 3, z: z - 1 },
        { x: x, y: y + 3, z: z + 1 },
        { x: x - 1, y: y + 3, z: z - 1 },
        { x: x - 1, y: y + 3, z: z + 1 },
        { x: x - 2, y: y + 3, z: z - 1 },
        { x: x - 2, y: y + 3, z: z + 1 },
    ]
    // console.warn("dir_1:", JSON.stringify(entity.hasTag("dir_1"), null, 2));
    // console.warn("dir_2:", JSON.stringify(entity.hasTag("dir_2"), null, 2));
    // console.warn("dir_3:", JSON.stringify(entity.hasTag("dir_3"), null, 2));
    // console.warn("dir_4:", JSON.stringify(entity.hasTag("dir_4"), null, 2));
    fullblackPortal_empty = 0;
    front_empty.forEach(cords => {
        const block = entity.dimension.getBlock(cords);
        if (block?.permutation.matches('minecraft:air')) {
            fullblackPortal_empty++;
        }
    });
    if (entity.hasTag("dir_4") && fullblackPortal_empty == 27) {
        if (areLocationsEqual(black_Portal_1[0], entity.location)) {
            black_Portal_1[1] = { directionX: 0, directionZ: 3, horizontalStrength: 2.7, verticalStrength: 0.3 };
            black_Portal_1[2].full = 1;
            black_Portal_1[3] = { x: 0, y: 0.4, z: 0.5 };
            black_Portal_1[4] = { x: x, y: y, z: z + 5 };
            black_Portal_1[5] = { x: x, y: y + 1, z: z + 1 };
            black_Portal_1[6] = var_dimension;
            black_Portal_1[7] = { x: x, y: y, z: z + 3 };
            black_Portal_1[8] = { x: 0, z: 2 };
        } else if (areLocationsEqual(black_Portal_2[0], entity.location)) {
            black_Portal_2[1] = { directionX: 0, directionZ: 3, horizontalStrength: 2.7, verticalStrength: 0.3 };
            black_Portal_2[2].full = 1;
            black_Portal_2[3] = { x: 0, y: 0.4, z: 0.5 };
            black_Portal_2[4] = { x: x, y: y, z: z + 5 };
            black_Portal_2[5] = { x: x, y: y, z: z + 1 };
            black_Portal_2[6] = var_dimension;
            black_Portal_2[7] = { x: x, y: y, z: z + 3 };
            black_Portal_2[8] = { x: 0, z: 2 };
        }
        return;

    } else {
        if (areLocationsEqual(black_Portal_1[0], entity.location)) {
            black_Portal_1[2].full = 0;
        } else if (areLocationsEqual(black_Portal_2[0], entity.location)) {
            black_Portal_2[2].full = 0;
        }
    }
    fullblackPortal_empty = 0;
    left_empty.forEach(cords => {
        const block = entity.dimension.getBlock(cords);
        if (block?.permutation.matches('minecraft:air')) {
            fullblackPortal_empty++;
        }
    });
    if (entity.hasTag("dir_2") && fullblackPortal_empty == 27) {
        if (areLocationsEqual(black_Portal_1[0], entity.location)) {
            black_Portal_1[1] = { directionX: 3, directionZ: 0, horizontalStrength: 2.7, verticalStrength: 0.3 };
            black_Portal_1[2].full = 1;
            black_Portal_1[3] = { x: 0.5, y: 0.4, z: 0 };
            black_Portal_1[4] = { x: 5, y: 0, z: 0 };
            black_Portal_1[4] = { x: x + 5, y: y, z: z };
            black_Portal_1[5] = { x: x + 1, y: y + 1, z: z };
            black_Portal_1[6] = var_dimension;
            black_Portal_1[7] = { x: x + 3, y: y, z: z };
            black_Portal_1[8] = { x: 2, z: 0 };
        } else if (areLocationsEqual(black_Portal_2[0], entity.location)) {
            black_Portal_2[1] = { directionX: 3, directionZ: 0, horizontalStrength: 2.7, verticalStrength: 0.3 };
            black_Portal_2[2].full = 1;
            black_Portal_2[3] = { x: 0.5, y: 0.4, z: 0 };
            black_Portal_2[4] = { x: x + 5, y: y, z: z };
            black_Portal_2[5] = { x: x + 1, y: y + 1, z: z };
            black_Portal_2[6] = var_dimension;
            black_Portal_2[7] = { x: x + 3, y: y, z: z };
            black_Portal_2[8] = { x: 2, z: 0 };
        }
        return;
    } else {
        if (areLocationsEqual(black_Portal_1[0], entity.location)) {
            black_Portal_1[2].full = 0;
        } else if (areLocationsEqual(black_Portal_2[0], entity.location)) {
            black_Portal_2[2].full = 0;
        }
    }
    fullblackPortal_empty = 0;
    back_empty.forEach(cords => {
        const block = entity.dimension.getBlock(cords);
        if (block?.permutation.matches('minecraft:air')) {
            fullblackPortal_empty++;
        }
    });
    if (entity.hasTag("dir_1") && fullblackPortal_empty == 27) {
        if (areLocationsEqual(black_Portal_1[0], entity.location)) {
            black_Portal_1[1] = { directionX: 0, directionZ: -3, horizontalStrength: 2.7, verticalStrength: 0.3 };
            black_Portal_1[2].full = 1;
            black_Portal_1[3] = { x: 0, y: 0.4, z: z - 0.5 };
            black_Portal_1[4] = { x: x, y: y, z: z - 5 };
            black_Portal_1[5] = { x: x, y: y + 1, z: z - 1 };
            black_Portal_1[6] = var_dimension;
            black_Portal_1[7] = { x: x, y: y, z: z - 3 };
            black_Portal_1[8] = { x: 0, z: -2 };
        } else if (areLocationsEqual(black_Portal_2[0], entity.location)) {
            black_Portal_2[1] = { directionX: 0, directionZ: -3, horizontalStrength: 2.7, verticalStrength: 0.3 };
            black_Portal_2[2].full = 1;
            black_Portal_2[3] = { x: 0, y: 0.4, z: -0.5 };
            black_Portal_2[4] = { x: x, y: y, z: z - 5 };
            black_Portal_2[5] = { x: x, y: y + 1, z: z - 1 };
            black_Portal_2[6] = var_dimension;
            black_Portal_2[7] = { x: x, y: y, z: z - 3 };
            black_Portal_2[8] = { x: 0, z: -2 };
        }
        return;
    } else {
        if (areLocationsEqual(black_Portal_1[0], entity.location)) {
            black_Portal_1[2].full = 0;
        } else if (areLocationsEqual(black_Portal_2[0], entity.location)) {
            black_Portal_2[2].full = 0;
        }
    }
    fullblackPortal_empty = 0;
    right_empty.forEach(cords => {
        const block = entity.dimension.getBlock(cords);
        if (block?.permutation.matches('minecraft:air')) {
            fullblackPortal_empty++;
        }
    });
    if (entity.hasTag("dir_3") && fullblackPortal_empty == 27) {
        if (areLocationsEqual(black_Portal_1[0], entity.location)) {
            black_Portal_1[1] = { directionX: -3, directionZ: 0, horizontalStrength: 2.7, verticalStrength: 0.3 };
            black_Portal_1[2].full = 1;
            black_Portal_1[3] = { x: -0.5, y: 0.4, z: 0 };
            black_Portal_1[4] = { x: x - 5, y: y, z: z };
            black_Portal_1[5] = { x: x - 1, y: y + 1, z: z };
            black_Portal_1[6] = var_dimension;
            black_Portal_1[7] = { x: x - 3, y: y, z: z };
            black_Portal_1[8] = { x: -2, z: 0 };
        } else if (areLocationsEqual(black_Portal_2[0], entity.location)) {
            black_Portal_2[1] = { directionX: -3, directionZ: 0, horizontalStrength: 2.7, verticalStrength: 0.3 };
            black_Portal_2[2].full = 1;
            black_Portal_2[3] = { x: -0.5, y: 0.4, z: 0 };
            black_Portal_2[4] = { x: x - 5, y: y, z: z };
            black_Portal_2[5] = { x: x - 1, y: y + 1, z: z };
            black_Portal_2[6] = var_dimension;
            black_Portal_2[7] = { x: x - 3, y: y, z: z };
            black_Portal_2[8] = { x: -2, z: 0 };
        }
    } else {
        if (areLocationsEqual(black_Portal_1[0], entity.location)) {
            black_Portal_1[2].full = 0;
        } else if (areLocationsEqual(black_Portal_2[0], entity.location)) {
            black_Portal_2[2].full = 0;
        }
    }

}
function blackDespawn() {
    for (let index = 0; index < list_dimention.length; index++) {
        const var_dimension = list_dimention[index];

        entities = world.getDimension(var_dimension).getEntities({ type: entityTypeId });
        for (const entity of entities) {
            entity.triggerEvent("animation_turn_off")
            if (black_Portal_1[0] != { x: undefined, y: undefined, z: undefined } && black_Portal_2[0] != { x: undefined, y: undefined, z: undefined } && !areLocationsEqual(black_Portal_1[0], entity.location) && !areLocationsEqual(black_Portal_2[0], entity.location)) {
            } else {
                if (entity.getComponent('skin_id').value == 1) {
                    if (black_Portal_1[0] != { x: undefined, y: undefined, z: undefined }) {
                        if ((areLocationsEqual(black_Portal_1[0], entity.location))) {
                            black_Portal_1[0] = { x: undefined, y: undefined, z: undefined }
                            black_Portal_1[2].full = 0;
                            return
                        }
                    }
                    if (black_Portal_2[0] != { x: undefined, y: undefined, z: undefined }) {
                        if ((areLocationsEqual(black_Portal_2[0], entity.location))) {
                            black_Portal_2[0] = { x: undefined, y: undefined, z: undefined }
                            black_Portal_2[2].full = 0;
                            return
                        }
                    }
                }
            }
        }
    }
}
function blackInteract() {

    for (const player of world.getPlayers()) {
        for (let index = 0; index < list_dimention.length; index++) {
            const var_dimension = list_dimention[index];
            entities = world.getDimension(var_dimension).getEntities({ type: entityTypeId, location: player.location, closest: 6, maxDistance: 6 });
            for (const entity of entities) {
                if (black_Portal_1[0].x !== undefined && black_Portal_2[0].x !== undefined) {
                    if (black_Portal_1[0].x !== undefined) {
                        if ((areLocationsEqual(black_Portal_1[0], entity.location))) {
                            if (black_Portal_1[6] == "overworld") {
                                player.sendMessage("You are currently on: §a" + black_Portal_1[0].x + " " + black_Portal_1[0].y + " " + black_Portal_1[0].z + "§r, Dimention §l§2Overworld§r.");
                            } else if (black_Portal_1[6] == "nether") {
                                player.sendMessage("You are currently on: §a" + black_Portal_1[0].x + " " + black_Portal_1[0].y + " " + black_Portal_1[0].z + "§r, Dimention §l§4Nether§r.");
                            } else {
                                player.sendMessage("You are currently on: §a" + black_Portal_1[0].x + " " + black_Portal_1[0].y + " " + black_Portal_1[0].z + "§r, Dimention §l§8The end§r.");
                            }
                            system.runTimeout(() => {
                                if (black_Portal_2[6] == "overworld") {
                                    player.sendMessage("The portal conected is in: §a" + black_Portal_2[0].x + " " + black_Portal_2[0].y + " " + black_Portal_2[0].z + "§r, Dimention §l§2Overworld§r.");
                                } else if (black_Portal_2[6] == "nether") {
                                    player.sendMessage("The portal conected is in: §a" + black_Portal_2[0].x + " " + black_Portal_2[0].y + " " + black_Portal_2[0].z + "§r, Dimention §l§4Nether§r.");
                                } else {
                                    player.sendMessage("The portal conected is in: §a" + black_Portal_2[0].x + " " + black_Portal_2[0].y + " " + black_Portal_2[0].z + "§r, Dimention §l§8The end§r.");
                                }
                            }, 50);
                        }
                    }
                    if (black_Portal_2[0].x !== undefined) {
                        if ((areLocationsEqual(black_Portal_2[0], entity.location))) {
                            if (black_Portal_2[6] == "overworld") {
                                player.sendMessage("You are currently on: §a" + black_Portal_2[0].x + " " + black_Portal_2[0].y + " " + black_Portal_2[0].z + "§r, Dimention §l§2Overworld§r.");
                            } else if (black_Portal_2[6] == "nether") {
                                player.sendMessage("You are currently on: §a" + black_Portal_2[0].x + " " + black_Portal_2[0].y + " " + black_Portal_2[0].z + "§r, Dimention §l§4Nether§r.");
                            } else {
                                player.sendMessage("You are currently on: §a" + black_Portal_2[0].x + " " + black_Portal_2[0].y + " " + black_Portal_2[0].z + "§r, Dimention §l§8The end§r.");
                            }
                            system.runTimeout(() => {
                                if (black_Portal_1[6] == "overworld") {
                                    player.sendMessage("The portal conected is in: §a" + black_Portal_1[0].x + " " + black_Portal_1[0].y + " " + black_Portal_1[0].z + "§r, Dimention §l§2Overworld§r.");
                                } else if (black_Portal_1[6] == "nether") {
                                    player.sendMessage("The portal conected is in: §a" + black_Portal_1[0].x + " " + black_Portal_1[0].y + " " + black_Portal_1[0].z + "§r, Dimention §l§4Nether§r.");
                                } else {
                                    player.sendMessage("The portal conected is in: §a" + black_Portal_1[0].x + " " + black_Portal_1[0].y + " " + black_Portal_1[0].z + "§r, Dimention §l§8The end§r.");
                                }
                            }, 50);
                        }
                    }
                }
            }
        }
    }
}
system.afterEvents.scriptEventReceive.subscribe(data => {
    const id = data.id
    if (id === "portality:black_teleport") {
        system.run(Teleport);
    };
    if (id === "portality:black_despawn") {
        system.run(blackDespawn);
    };
    if (id === "portality:black_spawn") {
        system.run(Spawn);
    };
    if (id === "portality:black_interact") {
        system.run(blackInteract);
    };
})
