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


export const spawnFixedParticle = (() => {

    // object storing used fixed particle location and their delays
    const activeParticles = {};

    // cleanup activeParticle locations (might be best to convert this into a runJob later)
    system.runInterval(() => {
        const timeout = system.currentTick - 200;
        for (const [loc, tick] of Object.entries(activeParticles)) {
            if (timeout > tick) delete activeParticles[loc];
        }
    }, 210);

    return (particle, dimension, location, delay=0, molangVariables=undefined) => {
        const id = `${location.x},${location.y},${location.z}`;

        const tick = activeParticles[id];
        if (tick && system.currentTick < (tick + delay)) return false;

        activeParticles[id] = system.currentTick;

        dimension.spawnParticle(particle, location, molangVariables);
        return true;
    };

})();

