import { world } from '@minecraft/server';

export function getClosestPlayerPosition(entity) {
    if (entity == undefined){
        return;
    }
    const position = entity.location 
    const closestPlayer = world.getDimension('overworld').getEntities({ location: position, closest: 1, families: ['player'] })
    const closestPlayerPosition = closestPlayer[0].location ?? vector3({x: 0, y: 80, z:0})

    
    //world.sendMessage('chunklock pos' + closestPlayerPosition.x.toString() + closestPlayerPosition.y.toString() + closestPlayerPosition.z.toString())
    //world.sendMessage('chunklock pos' + position.x + position.y + position.z)

    
    entity.teleport({ x: position.x, y: closestPlayerPosition.y, z: position.z })
    return;
}