import { Entity } from "@minecraft/server";

/**
 * 
 * @param {Entity} source 
 */

export function viewLife(source) {
    let entities = source.getEntitiesFromViewDirection({ maxDistance: 10 });
    let victim = entities.find(victim => (victim.entity.getComponent('health')));
    if (victim) {
        const health = victim.entity.getComponent('health');
        source.onScreenDisplay.setActionBar(`Entity: ${health.currentValue}§r`)
    }
}