import { world, EquipmentSlot } from "@minecraft/server";

// EXE Sword
export function SwordMechaniExecutioner() {
    world.afterEvents.itemUse.subscribe(({ source }) => {
        const equippable = source.getComponent("equippable");
        const item = equippable.getEquipment(EquipmentSlot.Mainhand);
        if (!item) return;
        switch (item.typeId) {
            case "morellager:executioners_cursed_axe": // ExecutionerBasic
                if (item.typeId === "morellager:executioners_cursed_axe" && !source.hasTag('cooldown_sword_basic') && source.isOnGround) {
                    source.runCommandAsync('function weapon/executioners_curse');
                    source.addTag('cooldown_sword_basic');
                    break;
                }

        }
    });
}

// Freak
export function SwordMechanifreak() {
    world.afterEvents.itemUse.subscribe(({ source }) => {
        const equippable = source.getComponent("equippable");
        const item = equippable.getEquipment(EquipmentSlot.Mainhand);
        if (!item) return;
        switch (item.typeId) {
            case "morellager:bag_of_horrors": // ExecutionerBasic
                if (item.typeId === "morellager:bag_of_horrors" && !source.hasTag('cooldown_sword_basic') && source.isOnGround) {
                    source.runCommandAsync('function weapon/freak_attack');
                    source.addTag('cooldown_sword_basic');
                    break;
                }

        }
    });
}

// HeadsetM
export function HeadsetM() {
    world.afterEvents.itemUse.subscribe(({ source }) => {
        const equippable = source.getComponent("equippable");
        const item = equippable.getEquipment(EquipmentSlot.Mainhand);
        if (!item) return;
        switch (item.typeId) {
            case "morellager:headphones_morellagers": // Headset
                if (item.typeId === "morellager:headphones_morellagers" && !source.hasTag('cooldown_sword_basic') && source.isOnGround) {
                    source.runCommandAsync('function Other/headphones_morellagers');
                    source.addTag('cooldown_sword_basic');
                    break;
                }

        }
    });
}