import { world, ItemComponentTypes, system } from "@minecraft/server"
import { bossAxeWeapon } from "../weapons/boss_axe_weapon"
import { sendDebugMessage } from "../JM_Utils"

system.beforeEvents.startup.subscribe(startEvent => {
    startEvent.itemComponentRegistry.registerCustomComponent("lb_as:big_axe", {
        onUse: (useEvent) => {
            const player = useEvent.source
            const item = useEvent.itemStack
            const component = item.getComponent(ItemComponentTypes.Cooldown)
            const remaining = component.getCooldownTicksRemaining(player)
            // inconsistent; sometimes it's 0, sometimes it's total-1 😡
            if (remaining === 0 || remaining >= component.cooldownTicks - 1) {
                bossAxeWeapon(item, player)
            }
        }
    })
})