import { EquipmentSlot } from '@minecraft/server';
import { startCooldown } from 'utils/startCooldown';
export function crystal(componentData) {
    const source = componentData.source;
    const head_location = source.getHeadLocation();
    const view_direction = source.getViewDirection();
    const tan_view_direction = tan(view_direction);
    const spawn_location = {
        x: head_location.x + tan_view_direction.x,
        y: head_location.y + tan_view_direction.y,
        z: head_location.z + tan_view_direction.z
    };
    const entity = source.dimension.spawnEntity('endorah_mo:crystal', spawn_location);
    const multiplied_vector = {
        x: view_direction.x * 4,
        y: view_direction.y,
        z: view_direction.z * 4
    };
    entity.applyImpulse(multiplied_vector);
    entity.addTag('endorah_mo:amethyst_crystal');
    source.playSound('endorah.mo.amethyst.sword_attack');
    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);
}
export function amethystParticleFunction(componentData) {
    try {
        const particles = [
            'endorah_mo:amethyst_1',
            'endorah_mo:amethyst_2',
            'endorah_mo:amethyst_3'
        ];
        particles.forEach((particle) => {
            componentData.hitEntity.dimension.spawnParticle(particle, componentData.hitEntity.location);
        });
    }
    catch (error) { }
}
export function tan(v) {
    return {
        x: Math.tan(v.x),
        y: Math.tan(v.y),
        z: Math.tan(v.z)
    };
}
