import { world } from "@minecraft/server"

export class WorldHelper {
    
    /**
     * 
     * @param {import("@minecraft/server").EntityQueryOptions} queryOptions 
     * @returns 
     */
    static getAllEntities(queryOptions) {
        const dimensions = [
            "minecraft:nether",
            "minecraft:overworld",
            "minecraft:the_end"
        ]

        const entities = []
        for (const dimension of dimensions) {
            entities.push(...world.getDimension(dimension).getEntities(queryOptions))
        }
        return entities
    }

    /**
     * 
     * @param {number} x 
     * @param {number} y 
     * @param {number} z
     * @returns {import("@minecraft/server").Vector3}
     */
    static createNewLocation(x, y, z) {
        return {x: x, y:y, z:z}
    }

    /**
     * Calculates the coordinates of the corners of a 2D axis-aligned bounding box (AABB) 
     * given its center point and its dimensions along the x and y axes.
     * 
     * @param {number[]} center - An array of two numbers representing the center point [centerX, centerY].
     * @param {number[]} dimensions - An array of two numbers representing the width and length [width, length].
     * @returns {number[]} - Returns an array of four numbers representing the bounding box's coordinates [x1, y1, x2, y2].
     */
    static getBoundingBox(center, dimensions) {
        center = center.map(n => Math.floor(n))
        const [centerX, centerY] = center;
        const [width, height] = dimensions;

        const x1 = Math.floor(centerX - width / 2);
        const y1 = Math.floor(centerY - height / 2);
        const x2 = Math.ceil(centerX + width / 2);
        const y2 = Math.ceil(centerY + height / 2);

        return [x1, y1, x2, y2];
    }

    static worldTimeString() {
        const timeOfDay = world.getTimeOfDay();

        if (timeOfDay >= 13000 && timeOfDay <= 22813) return "Night"
    }
}