import { EquipmentSlot, MolangVariableMap } from '@minecraft/server';
import { startCooldown } from 'utils/startCooldown';
import { tan } from './amethyst';
import { applyDamageOverTime } from 'utils/random';
export function ray(componentData) {
    const source = componentData.source;
    const head_location = source.getHeadLocation();
    const view_direction = source.getViewDirection();
    const molang = new MolangVariableMap();
    molang.setFloat('endorah_x', view_direction.x);
    molang.setFloat('endorah_y', view_direction.y);
    molang.setFloat('endorah_z', view_direction.z);
    source.dimension.spawnParticle('endorah_mo:iris_specia_2', {
        x: head_location.x + tan(view_direction).x,
        y: head_location.y + tan(view_direction).y,
        z: head_location.z + tan(view_direction).z
    }, molang);
    source.dimension.spawnParticle('endorah_mo:iris_specia_3', {
        x: head_location.x + tan(view_direction).x,
        y: head_location.y + tan(view_direction).y,
        z: head_location.z + tan(view_direction).z
    });
    source.playSound('endorah.mo.iris.sword_rainbow_laser');
    const durability_component = componentData.itemStack.getComponent('durability');
    if (durability_component)
        durability_component.damage += 1;
    const equippable_component = source.getComponent('equippable');
    if (equippable_component)
        equippable_component.setEquipment(EquipmentSlot.Mainhand, componentData.itemStack);
    startCooldown(componentData.itemStack, source);
    const entities = source.getEntitiesFromViewDirection({
        maxDistance: 10,
        excludeTypes: ['minecraft:item']
    });
    applyDamageOverTime(entities, 10, 10, 4);
}
export function irisParticleFunction(componentData) {
    try {
        const particles = [
            'endorah_mo:iris_1',
            'endorah_mo:iris_2',
            'endorah_mo:iris_3',
            'endorah_mo:iris_4',
            'endorah_mo:iris_5'
        ];
        particles.forEach((particle) => {
            componentData.hitEntity.dimension.spawnParticle(particle, componentData.hitEntity.location);
        });
    }
    catch (error) { }
}
