import { system } from "@minecraft/server";
import { Dimensions, randomNum } from "../../helper/utils";
export class FlopEntity {
    constructor(config) {
        this.config = config;
    }
    static registerBehavior(config) {
        const eventEntity = new FlopEntity(config);
        this.register(eventEntity);
    }
    static register(eventEntity) {
        this.entities.push(eventEntity);
    }
    static getEntity(id) {
        return FlopEntity.entities.find((entity) => entity.config.id === id);
    }
    static initialize() {
        system.runInterval(() => {
            for (const dimension in Dimensions) {
                for (const config of this.entities) {
                    Dimensions[dimension].getEntities({ type: config.config.id }).forEach((entity) => {
                        if (entity.isInWater || !entity.isOnGround)
                            return;
                        const horizontal = config.config.strength.horizontal;
                        const vertical = config.config.strength.vertical;
                        const x = Math.random() > 0.5
                            ? randomNum(horizontal.min, horizontal.max)
                            : randomNum(-horizontal.max, -horizontal.min);
                        const z = Math.random() > 0.5
                            ? randomNum(horizontal.min, horizontal.max)
                            : randomNum(-horizontal.max, -horizontal.min);
                        entity.applyImpulse({ x: x, y: randomNum(vertical.min, vertical.max), z: z });
                        if (config.config.sound) {
                            const sound = config.config.sound;
                            entity.dimension.playSound(sound.id, entity.location, {
                                volume: sound.volume,
                                pitch: sound.pitch,
                            });
                        }
                    });
                }
            }
        }, 5);
    }
}
FlopEntity.entities = [];
