import { EquipmentSlot, system, world } from "@minecraft/server";
import { getItemInSlot } from "../../helper/utils";
export class AttackAnimationItem {
    //constructor
    constructor(config) {
        this.config = config;
    }
    static registerBehavior(config) {
        const eventItem = new AttackAnimationItem(config);
        this.items.push(eventItem);
    }
    static getItem(id) {
        return AttackAnimationItem.items.find((item) => item.config.id === id);
    }
    static initialize() {
        system.runInterval(() => {
            for (const config of this.items) {
                for (const player of world.getAllPlayers()) {
                    const item = getItemInSlot(player, EquipmentSlot.Mainhand);
                    if (item?.typeId == config.config.id) {
                        player.playAnimation(config.config.animation, {
                            blendOutTime: 0.1,
                            controller: "attack",
                        });
                    }
                }
            }
        }, 19);
    }
}
AttackAnimationItem.items = [];
