import { EquipmentSlot } from '@minecraft/server';
import { startCooldown } from 'utils/startCooldown';
import { traverseTree } from 'utils/treeMiner';
import { tan } from './amethyst';
export function setOnFire(componentData) {
    try {
        componentData.hitEntity.setOnFire(5);
    }
    catch (error) { }
}
export function treeMiner(componentData) {
    const player = componentData.source;
    if (!player.isSneaking)
        return;
    const minedBlock = componentData.minedBlockPermutation;
    if (!minedBlock.type.id.includes('log'))
        return;
    const block = componentData.block;
    const dimension = block.dimension;
    traverseTree(dimension, block, 9);
}
export function boom(componentData) {
    const source = componentData.source;
    const dimension = source.dimension;
    const blockRaycast = componentData.source.getBlockFromViewDirection();
    let location;
    if (!blockRaycast) {
        const tan_location = tan(source.getViewDirection());
        const new_location = {
            x: tan_location.x * 32,
            y: tan_location.y * 32,
            z: tan_location.z * 32
        };
        location = dimension.getBlock({
            x: source.location.x + new_location.x,
            y: source.location.y + new_location.y,
            z: source.location.z + new_location.z
        });
    }
    else {
        const offset = blockRaycast.faceLocation;
        location = dimension.getBlock(blockRaycast.block.offset(offset));
    }
    dimension.createExplosion(location, 4, {
        breaksBlocks: true,
        causesFire: true
    });
    source.playSound('endorah.mo.infernium.sword_explosion');
    dimension.spawnParticle('endorah_mo:infernium_special_2', location);
    dimension.spawnParticle('endorah_mo:infernium_special_4', location);
    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 inferniumParticleFunction(componentData) {
    try {
        const particles = [
            'endorah_mo:infernium_1',
            'endorah_mo:infernium_2',
            'endorah_mo:infernium_3'
        ];
        particles.forEach((particle) => {
            componentData.hitEntity.dimension.spawnParticle(particle, componentData.hitEntity.location);
        });
    }
    catch (error) { }
}
