import { world, system } from "@minecraft/server";

function startLight(entity, length) {
    let seconds = 0;
    const duration = length * 60 * 20;

    const interval = system.runInterval(() => {
        try {
            entity.runCommandAsync("function sapphire/meteors/light"); // Ahora llama directamente a light.mcfunction
        } catch (error) {
            console.error("Error ejecutando function light:", error);
        }

        seconds++;
        if (seconds >= duration) {
            try {
                entity.runCommandAsync("function sapphire/meteors/light_off");
            } catch (error) {
                console.error("Error ejecutando function light_off:", error);
            }
            system.clearRun(interval);
        }
    }, 1);
}

export const event = {
    onConsume(event) {
        const { source } = event

        startLight(source, 3);
    }
};
