import { EquipmentSlot } from '@minecraft/server';
import { startCooldown } from 'utils/startCooldown';
import { directionToVector3 } from 'utils/vector';
export function teleport(componentData) {
    const source = componentData.source;
    const blockRaycast = source.getBlockFromViewDirection();
    if (!blockRaycast)
        return;
    const offset = directionToVector3(blockRaycast.face);
    const location = {
        x: blockRaycast.block.center().x + offset.x,
        y: blockRaycast.block.center().y + offset.y,
        z: blockRaycast.block.center().z + offset.z
    };
    source.teleport(location);
    const particles = [
        'endorah_mo:enderite_tp_1',
        'endorah_mo:enderite_tp_2',
        'endorah_mo:enderite_tp_3'
    ];
    particles.forEach((particle) => {
        source.dimension.spawnParticle(particle, source.getHeadLocation());
    });
    source.playSound('mob.endermen.portal');
    startCooldown(componentData.itemStack, source);
    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);
}
export function enderiteParticleFunction(componentData) {
    try {
        const particles = [
            'endorah_mo:enderite_1',
            'endorah_mo:enderite_2',
            'endorah_mo:enderite_3',
            'endorah_mo:enderite_4'
        ];
        particles.forEach((particle) => {
            componentData.hitEntity.dimension.spawnParticle(particle, componentData.hitEntity.location);
        });
    }
    catch (error) { }
}
