import { world, InputPermissionCategory, } from "@minecraft/server";
import nestLocator from "../C/NestLocator";
import { callingHornStore, callingHornRelease } from "../C/CallingHorn";
import { getLinkedMount } from "../C/Linking";
import { skillFluteAttack, attackFluteAttack } from "../C/Attacking";
import { changePage } from "../C/CraftingBook";
import { openMainPage } from "../F/Form";
import { setIsFromItemTrue } from "./EntitySpawnEvent";
import { mountEggIds, mountsEggIds } from "../DATA/Config";
import { fastTravel } from "../C/FastTravel";
export function runItemUseAfterEvent(log) {
    world.afterEvents.itemUse.subscribe((itemUseAfterEvent) => {
        const { itemStack, source: player } = itemUseAfterEvent;
        if (!itemStack) {
            log(`The entity event didn't work as expected.`, -1);
            return;
        }
        const typeId = itemStack.typeId;
        const scoreboard = world.scoreboard.getObjective("kicu_mmad:jig_computer.addon_stats");
        switch (typeId) {
            case "kicu_mmad:nest_locator":
                scoreboard?.addScore("kicu_mmad_nest_locator_used_stat", 1);
                nestLocator(log, itemUseAfterEvent);
                break;
            case "kicu_mmad:calling_horn":
                scoreboard?.addScore("kicu_mmad_calling_horn_blown_stat", 1);
                callingHornStore(player, log);
                break;
            case "kicu_mmad:calling_horn_occupied":
                callingHornRelease(player, itemStack, log);
                break;
            case "kicu_mmad:attack_flute": {
                if (!player.inputPermissions.isPermissionCategoryEnabled(InputPermissionCategory.Dismount))
                    break;
                const entityMounts = getLinkedMount(player);
                if (entityMounts.length) {
                    scoreboard?.addScore("kicu_mmad_flute_tooted_stat", 1);
                    attackFluteAttack(entityMounts[0], log);
                }
                break;
            }
            case "kicu_mmad:skill_flute": {
                if (!player.inputPermissions.isPermissionCategoryEnabled(InputPermissionCategory.Dismount))
                    break;
                const entityMounts = getLinkedMount(player);
                if (entityMounts.length) {
                    scoreboard?.addScore("kicu_mmad_flutea_tooted_stat", 1);
                    skillFluteAttack(entityMounts[0], log);
                }
                break;
            }
            default:
                if (mountEggIds.includes(typeId)) {
                    player.playSound("sound.kicu_mmad_place_egg", { pitch: 1.0, volume: 0.1 });
                }
                else if (typeId.startsWith("kicu_mmad:recipe")) {
                    changePage(log, itemStack, player);
                }
                else if (typeId === "kicu_mmad:fake_book") {
                    openMainPage(player, log);
                }
                else if (typeId === "kicu_mmad:travelers_flute") {
                    fastTravel(player);
                }
                break;
        }
    });
}
export function runItemUseBeforeEvent(log) {
    world.beforeEvents.itemUse.subscribe((itemUseBeforeEvent) => {
        const { itemStack, source } = itemUseBeforeEvent;
        if (itemStack && mountsEggIds.includes(itemStack.typeId)) {
            const raycastHits = source.getEntitiesFromViewDirection({
                maxDistance: 7,
                type: "kicu_mmad:egg_incubator",
            });
            if (raycastHits.length > 0) {
                itemUseBeforeEvent.cancel = true;
            }
            setIsFromItemTrue();
        }
    });
}

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