/*
system.runInterval(()=>{
    CloudEmissionSystem.runInterval();
}, 20);

class CloudEmissionSystem {
    private static readonly gridSize = 64;
    private static readonly emitterHeight = -64;
    public static runInterval() {
        const overworld = world.getDimension(MinecraftDimensionTypes.overworld);
        const requiredEmitterLocations = this.getRequiredEmitterLocations();
        for (const loc of requiredEmitterLocations) {
            const existing = overworld.getEntities({
                type: CloudEmitter.identifier,
                location: loc,
                maxDistance: 4
            });
            if (existing.length === 0) {
                const emitter = overworld.spawnEntity(CloudEmitter.identifier, {
                    x: loc.x,
                    y: loc.y,
                    z: loc.z
                });
            }
        }
    }
    private static getRequiredEmitterLocations(): Vector3[] {
        const overworld = world.getDimension(MinecraftDimensionTypes.overworld);
        const players = overworld.getPlayers();
        const sectors = new Set<string>();
        const result: Vector3[] = [];
        for (const player of players) {
            const { x, z } = player.location;
            const sectorX = Math.floor(x / this.gridSize);
            const sectorZ = Math.floor(z / this.gridSize);
            const key = `${sectorX},${sectorZ}`;
            if (!sectors.has(key)) {
                sectors.add(key);
                result.push({
                    x: sectorX * this.gridSize + this.gridSize / 2,
                    y: this.emitterHeight,
                    z: sectorZ * this.gridSize + this.gridSize / 2,
                });
            }
        }
        return result;
    }
}

class CloudEmitter {
    public static readonly identifier = "nps_atm:cloud_emitter";
    private static readonly maxDistance = 64;
    public static runInterval() {
        const overworld = world.getDimension(MinecraftDimensionTypes.overworld);
        const players = overworld.getPlayers();
        const emitters = overworld.getEntities({ type: this.identifier });
        for (const emitter of emitters) {
            const emitterPos = emitter.location;
            const closestPlayer = players.reduce((closest, player) => {
                const dist = getHorizontalDistance(emitterPos, player.location);
                return dist < closest ? dist : closest;
            }, Infinity);
            if (closestPlayer > this.maxDistance) {
                //console.warn(`Removed emitter too far from players at ${JSON.stringify(emitter.location)}`);
                emitter.remove();
            }
        }
    }
    public static spawnParticle(emitter: Entity) {
        emitter.dimension.spawnParticle('nps_atm:cloud_x', {x: emitter.location.x,y: 194,z: emitter.location.z});
    }
}
*/
var ATMPDP;
(function (ATMPDP) {
    ATMPDP["emitterId"] = "nps_atm:emitter_id";
})(ATMPDP || (ATMPDP = {}));
export {};
/*
system.runInterval(()=>{
    const overworld = world.getDimension(MinecraftDimensionTypes.overworld);
    const players = overworld.getPlayers();
    players.forEach(player => {
        const emitterId = player.getDynamicProperty(ATMPDP.emitterId) as string;
        if(emitterId == undefined) {
            const location = {x: player.location.x,y: -64,z: player.location.z}
            const emitter = overworld.spawnEntity("nps_atm:a0b7f59b", location);
            player.setDynamicProperty(ATMPDP.emitterId, emitter.id);
        } else {
            const emitter = world.getEntity(emitterId);
            if(emitter != undefined) {
                const location = {x: player.location.x,y: -64,z: player.location.z}
                emitter.teleport(location);
            } else {
                const location = {x: player.location.x,y: -64,z: player.location.z}
                const emitter = overworld.spawnEntity("nps_atm:a0b7f59b", location);
                player.setDynamicProperty(ATMPDP.emitterId, emitter.id);
            }
        }
    })
}, 10);*/
