import { EquipmentSlot, system } from '@minecraft/server';
import { startCooldown } from 'utils/startCooldown';
export function dynamicLight(componentData) {
    const source = componentData.source;
    const dimension = source.dimension;
    const job = system.runInterval(() => {
        const location = source.getHeadLocation();
        location.x = Math.floor(location.x) + 0.5;
        location.y = Math.floor(location.y) + 0.5;
        location.z = Math.floor(location.z) + 0.5;
        location.x =
            Math.sign(location.x) * (Math.floor(Math.abs(location.x)) + 0.5);
        location.y =
            Math.sign(location.y) * (Math.floor(Math.abs(location.y)) + 0.5);
        location.z =
            Math.sign(location.z) * (Math.floor(Math.abs(location.z)) + 0.5);
        const block = dimension.getBlock(location);
        if (block.typeId == 'minecraft:air') {
            block.setType('minecraft:light_block_10');
            system.runTimeout(() => {
                block.setType('minecraft:air');
            }, 20);
        }
    });
    system.runTimeout(() => {
        system.clearRun(job);
    }, 20 * 10);
    source.playSound('endorah.mo.redstone.sword_light_on');
    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);
}
