import EventWrappers from '../../utils/AfterEvents.js';
import { Server } from "../../../libs/Core/index.js";
import { EntityProjectileComponent } from '@minecraft/server';

EventWrappers.SpawnAfterEvent.registerEvent('plank_waao:sculk_spider_projectile', (e) => {
    let projectile = e.entity;
    const shooter = projectile.dimension.getEntities({
        closest: true,
        type: 'plank_waao:sculk_bug_adult',
        location: projectile.location
    })[0];

    if (!shooter || !shooter.isValid()) {
        projectile.remove();
        return;
    }
    /** @type {EntityProjectileComponent} */
    let projectileComp = projectile.getComponent('minecraft:projectile')
    projectileComp.owner = shooter;

    Server.shootProjectile(projectile, shooter, 0.9, { facingOffset: { x: 1, y: 0, z: 0 }, viewOffsets: { x: 0, y: 0.1, z: 0 } });
});