feat(minecraft): track and display nearby players' held items in context

This commit is contained in:
Rin
2026-02-18 11:12:46 +08:00
committed by Neko Ayaka
parent 60133ae276
commit c77f56d81a
3 changed files with 31 additions and 6 deletions
@@ -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
@@ -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
@@ -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.