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

Entity.prototype.spawning = false;

world.afterEvents.entitySpawn.subscribe((event) => {
    const { entity, cause } = event;

    const entityTypeFamily = entity.getComponent("minecraft:type_family");

    if (cause == EntityInitializationCause.Spawned) {
        if (entity.spawning == false) {
            entity.spawning = true;

            system.runTimeout(() => {
                entity.spawning = false;
            }, 1 * 20);
        }
    }

    const canMobsSpawn = world.getDynamicProperty("CanMobsSpawn");

    if (canMobsSpawn != undefined) {
        if (canMobsSpawn == false) {
            try {
                if (entityTypeFamily.hasTypeFamily("ns_ma")) {
                    entity?.remove();
                }
            } catch (e) {}
        }
    }
});
