import { ItemComponentHitEntityEvent, ItemComponentUseEvent, ItemCooldownComponent } from "@minecraft/server";
import { onHitEntityWrapper, onUseWrapper } from "./wrapper";
import * as Server from "../../../libs/Core/Server/index";


export class WardenSword extends onUseWrapper {
    constructor() {
        super();
    }

    /**
     * @param {ItemComponentUseEvent} e 
     */
    onUse(e) {
        Server.entityShootProjectile('plank_waao:warden_sword_projectile', e.source, 0.3, { gravity: 0, ignorePitch: true });
        e.source.runCommandAsync('playsound item.plank_waao.warden_sword.attack @a ~~~');

        /** @type {ItemCooldownComponent} */
        const cooldownComponent = e.itemStack.getComponent('minecraft:cooldown');
        cooldownComponent.startCooldown(e.source);

        this.decrementDurability(e.source, e.itemStack, 1);
    }

}
