getNearbyPlayers
Identify and list players in your immediate vicinity within Minecraft. Enhance coordination, interaction, and gameplay strategy by locating nearby users in real-time.
Instructions
Get a list of players nearby
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/info.ts:15-41 (handler)The handler function that retrieves nearby players by filtering the bot's players list, excluding the bot itself, calculating distances to the bot's position, and returning a formatted success response or appropriate error/not connected response.async () => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { const players = Object.values(botState.bot.players) .filter( (player) => player.entity && player.username !== botState.bot?.username ) .map((player) => { if (!botState.bot) return '' const pos = player.entity!.position const distance = pos.distanceTo(botState.bot.entity.position) return `${player.username} (${distance.toFixed(2)} blocks away)` }) if (players.length === 0) { return createSuccessResponse('No other players nearby.') } return createSuccessResponse(`Nearby players: ${players.join(', ')}`) } catch (error) { return createErrorResponse(error) } }
- src/tools/info.ts:11-42 (registration)Registers the 'getNearbyPlayers' tool with server.tool, providing the tool name, description, empty input schema, and the handler function. This occurs within the registerInfoTools function.server.tool( 'getNearbyPlayers', 'Get a list of players nearby', {}, async () => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { const players = Object.values(botState.bot.players) .filter( (player) => player.entity && player.username !== botState.bot?.username ) .map((player) => { if (!botState.bot) return '' const pos = player.entity!.position const distance = pos.distanceTo(botState.bot.entity.position) return `${player.username} (${distance.toFixed(2)} blocks away)` }) if (players.length === 0) { return createSuccessResponse('No other players nearby.') } return createSuccessResponse(`Nearby players: ${players.join(', ')}`) } catch (error) { return createErrorResponse(error) } } )