import * as selectors from "../utils/selectors";

export function eventBehavior(event) {
    const entity = event.entity;

    if (event.eventId === "minecraft:entity_spawned") {
        let entities = selectors.union({
            location: entity.location,
            maxDistance: 15,
        }, ["pig", "sheep", "cow", "chicken"], entity.dimension, entity.id);
        if (entities[0] !== undefined) {
            entity.remove();
            return;
        }
        entities = selectors.union({
            location: entity.location,
            maxDistance: 32,
        }, ["villager", "illager"], entity.dimension, entity.id);
        if (entities[0] !== undefined) {
            entity.remove();
            return;
        }
        
        entities = selectors.union({
            location: entity.location,
            maxDistance: 42,
        }, ["hf_mzs_umvuthana"], entity.dimension, entity.id);
        if (entities.length >=5) {
            entity.remove();
            return;
        }

        if (Math.random()>=0.12){
            entity.remove();
            return;
        }

        entity.triggerEvent("spawn");
    }
}