diff --git a/services/minecraft/src/cognitive/conscious/context-view.ts b/services/minecraft/src/cognitive/conscious/context-view.ts index f15b9a544..9a0265db9 100644 --- a/services/minecraft/src/cognitive/conscious/context-view.ts +++ b/services/minecraft/src/cognitive/conscious/context-view.ts @@ -8,9 +8,11 @@ export interface ConsciousContextView { export function buildConsciousContextView(ctx: ReflexContextState): ConsciousContextView { const pos = ctx.self.location const roundedPos = `(${Math.round(pos.x)}, ${Math.round(pos.y)}, ${Math.round(pos.z)})` - const selfSummary = `Position ${roundedPos} Health ${ctx.self.health}/20 Food ${ctx.self.food}/20 Holding ${ctx.self.holding ?? 'nothing'}` + const selfSummary = `Position ${roundedPos} Health ${ctx.self.health}/20 Food ${ctx.self.food}/20 and I'm holding ${ctx.self.holding ?? 'nothing'}` - const players = ctx.environment.nearbyPlayers.map(p => p.name).join(',') + const players = ctx.environment.nearbyPlayers + .map(p => (p.holding ? `${p.name} is holding (${p.holding})` : p.name)) + .join(',') const entities = ctx.environment.nearbyEntities.map(e => e.name).join(',') const gaze = ctx.environment.nearbyPlayersGaze diff --git a/services/minecraft/src/cognitive/reflex/context.ts b/services/minecraft/src/cognitive/reflex/context.ts index b0c44f774..59accf79d 100644 --- a/services/minecraft/src/cognitive/reflex/context.ts +++ b/services/minecraft/src/cognitive/reflex/context.ts @@ -10,7 +10,7 @@ export interface ReflexSelfState { export interface ReflexEnvironmentState { time: 'day' | 'night' | 'sunset' | 'sunrise' weather: 'clear' | 'rain' | 'thunder' - nearbyPlayers: Array<{ name: string, distance?: number }> + nearbyPlayers: Array<{ name: string, distance?: number, holding?: string | null }> nearbyPlayersGaze: Array<{ name: string distanceToSelf: number diff --git a/services/minecraft/src/cognitive/reflex/runtime.ts b/services/minecraft/src/cognitive/reflex/runtime.ts index ace24a727..8c33b25c4 100644 --- a/services/minecraft/src/cognitive/reflex/runtime.ts +++ b/services/minecraft/src/cognitive/reflex/runtime.ts @@ -148,12 +148,35 @@ export class ReflexRuntime { holding: bot.bot.heldItem?.name ?? null, }) + const selfPos = entity.position + const maxNearbyDistance = 32 + const players = Object.entries(bot.bot.players ?? {}) + .filter(([name]) => name !== bot.bot.username) + .reduce((acc, [name, player]) => { + const pos = player?.entity?.position + if (!pos) + return acc + let distance: number | null = null + try { + distance = selfPos.distanceTo(pos) + } + catch { + distance = null + } + if (distance === null || distance > maxNearbyDistance) + return acc + acc.push({ + name, + distance, + holding: player?.entity?.heldItem?.name ?? null, + }) + return acc + }, [] as Array<{ name: string, distance: number, holding: string | null }>) + this.context.updateEnvironment({ time: bot.bot.time?.isDay ? 'day' : 'night', weather: bot.bot.isRaining ? 'rain' : 'clear', - nearbyPlayers: Object.keys(bot.bot.players ?? {}) - .filter(p => p !== bot.bot.username) - .map(name => ({ name })), + nearbyPlayers: players, }) // Allow explicit modes like 'work' / 'wander' to remain until changed by caller.