import { world } from "@minecraft/server";
import { mountsNestsIds, eggPrefixes } from "../DATA/Config";
import { instantNestDespawn } from "../C/NestDespawn";
import { addWardLocation } from "../C/Warding";
export let isFromItem = false;
function getBlockCenteredCoords(entity) {
    let { x, y, z } = entity.location;
    const centeredCoords = {
        x: Math.floor(x) + 0.5,
        y: Math.floor(y),
        z: Math.floor(z) + 0.5,
    };
    return centeredCoords;
}
function alignEntityToBlockCenter(entity) {
    let { x, y, z } = entity.location;
    const coords = { x: Math.floor(x) + 0.5, y: y, z: Math.floor(z) + 0.5 };
    entity.teleport(coords);
}
export function runEntitySpawnAfterEvent(log) {
    world.afterEvents.entitySpawn.subscribe((event) => {
        try {
            const entity = event.entity;
            const entityId = entity.typeId;
            const entityLocation = entity.location;
            if (entityId === "kicu_mmad:egg_incubator") {
                alignEntityToBlockCenter(entity);
            }
            if (entityId === "kicu_mmad:lantern_of_warding") {
                addWardLocation(log, entity);
                alignEntityToBlockCenter(entity);
            }
            if (eggPrefixes.some((prefix) => entityId.startsWith(prefix))) {
                const entities = entity.dimension.getEntities({
                    location: entityLocation,
                    maxDistance: 1,
                    type: entityId,
                    closest: 2,
                });
                if (entities.length > 1) {
                    entity.triggerEvent("kicu_mmad:drop_item");
                }
            }
            if (entity && entity.dimension) {
                const entityLocation = entity.location;
                if (mountsNestsIds.includes(entityId)) {
                    instantNestDespawn(entity, entityLocation, entityId, isFromItem, log);
                    isFromItem = false;
                }
                if (entityId.startsWith("kicu_mmad") && entityId.endsWith("egg_placeholder")) {
                    const objective = world.scoreboard.getObjective("kicu_mmad_EggTimer");
                    objective.setScore(entity, 120);
                }
            }
        }
        catch { }
    });
}
export function setIsFromItemTrue() {
    isFromItem = true;
}

//# sourceMappingURL=../../../../../_KiCuMountsBPDebug/kicu/mmad/ESS/EntitySpawnEvent.js.map
