import { world } from "@minecraft/server";
import shootProjectile from "../projectile";
export class ShootProjectileEntity {
    constructor(config) {
        this.config = config;
    }
    static registerBehavior(config) {
        const entity = new ShootProjectileEntity(config);
        this.register(entity);
    }
    static register(entity) {
        this.entities.push(entity);
    }
    static initialize() {
        world.afterEvents.entitySpawn.subscribe((event) => {
            const entity = event.entity;
            const comp = entity.getComponent("minecraft:projectile");
            if (comp && comp.owner) {
                const owner = comp.owner;
                const ownerConfig = this.entities.find((e) => e.config.id === owner.typeId);
                if (ownerConfig) {
                    const replacement = ownerConfig.config.projectiles.find((p) => p.dummyProjectile === entity.typeId);
                    if (replacement) {
                        // Call shootProjectile with custom velocity from entity's current velocity
                        shootProjectile(owner, replacement.projectile, entity.getVelocity());
                    }
                }
            }
        });
    }
}
ShootProjectileEntity.entities = [];
