import * as mc from "@minecraft/server";
import * as vector from "../utils/vector";

export function eventBehavior(event) {
    return;
    if (!event.entity.isValid())
        return;
    if (event.eventId !== "attempt_spawn_umvuthana")
        return;
    
    const umvuthanaCount = event.entity.dimension.getEntities({
        families: ['hf_mzs_umvuthana'],
        excludeFamilies: ['hf_mzs_umvuthi'],
        maxDistance: 50,
        location: event.entity.location
    }).length;
    if (umvuthanaCount > 2)
        return;

    const umvuthiCount = event.entity.dimension.getEntities({
        amilies: ['hf_mzs_umvuthi'],
        maxDistance: 50,
        location: event.entity.location
    }).length;
    if (umvuthiCount === 0) {
        return;
    }
    
    for (let i = 0; i <= 2; i++) {
        for (let attempts = 0; attempts <= 10; attempts++) {
            const block = event.entity.dimension.getBlockFromRay({
                x: event.entity.location.x + (Math.random() - 0.5) * 22,
                y: 200,
                z: event.entity.location.z + (Math.random() - 0.5) * 22
            }, vector.down, {
                maxDistance: 300,
                includePassableBlocks: false,
                includeTypes: ["minecraft:grass_block", "minecraft:dirt"]
            });
            
            if (block === undefined || !block.block.isValid())
                continue;
            
            const e = event.entity.dimension.spawnEntity("hf_mzs:umvuthana<spawned_in_village>", 
                    vector.add(block.block.location, vector.up));
            e.setProperty("hf_mzs:from_village", true);
            break;
        }
    }
}