Skip to content

Commit c77f56d

Browse files
shinohara-rinnekomeowww
authored andcommitted
feat(minecraft): track and display nearby players' held items in context
1 parent 60133ae commit c77f56d

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

services/minecraft/src/cognitive/conscious/context-view.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ export interface ConsciousContextView {
88
export function buildConsciousContextView(ctx: ReflexContextState): ConsciousContextView {
99
const pos = ctx.self.location
1010
const roundedPos = `(${Math.round(pos.x)}, ${Math.round(pos.y)}, ${Math.round(pos.z)})`
11-
const selfSummary = `Position ${roundedPos} Health ${ctx.self.health}/20 Food ${ctx.self.food}/20 Holding ${ctx.self.holding ?? 'nothing'}`
11+
const selfSummary = `Position ${roundedPos} Health ${ctx.self.health}/20 Food ${ctx.self.food}/20 and I'm holding ${ctx.self.holding ?? 'nothing'}`
1212

13-
const players = ctx.environment.nearbyPlayers.map(p => p.name).join(',')
13+
const players = ctx.environment.nearbyPlayers
14+
.map(p => (p.holding ? `${p.name} is holding (${p.holding})` : p.name))
15+
.join(',')
1416
const entities = ctx.environment.nearbyEntities.map(e => e.name).join(',')
1517

1618
const gaze = ctx.environment.nearbyPlayersGaze

services/minecraft/src/cognitive/reflex/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface ReflexSelfState {
1010
export interface ReflexEnvironmentState {
1111
time: 'day' | 'night' | 'sunset' | 'sunrise'
1212
weather: 'clear' | 'rain' | 'thunder'
13-
nearbyPlayers: Array<{ name: string, distance?: number }>
13+
nearbyPlayers: Array<{ name: string, distance?: number, holding?: string | null }>
1414
nearbyPlayersGaze: Array<{
1515
name: string
1616
distanceToSelf: number

services/minecraft/src/cognitive/reflex/runtime.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,35 @@ export class ReflexRuntime {
148148
holding: bot.bot.heldItem?.name ?? null,
149149
})
150150

151+
const selfPos = entity.position
152+
const maxNearbyDistance = 32
153+
const players = Object.entries(bot.bot.players ?? {})
154+
.filter(([name]) => name !== bot.bot.username)
155+
.reduce((acc, [name, player]) => {
156+
const pos = player?.entity?.position
157+
if (!pos)
158+
return acc
159+
let distance: number | null = null
160+
try {
161+
distance = selfPos.distanceTo(pos)
162+
}
163+
catch {
164+
distance = null
165+
}
166+
if (distance === null || distance > maxNearbyDistance)
167+
return acc
168+
acc.push({
169+
name,
170+
distance,
171+
holding: player?.entity?.heldItem?.name ?? null,
172+
})
173+
return acc
174+
}, [] as Array<{ name: string, distance: number, holding: string | null }>)
175+
151176
this.context.updateEnvironment({
152177
time: bot.bot.time?.isDay ? 'day' : 'night',
153178
weather: bot.bot.isRaining ? 'rain' : 'clear',
154-
nearbyPlayers: Object.keys(bot.bot.players ?? {})
155-
.filter(p => p !== bot.bot.username)
156-
.map(name => ({ name })),
179+
nearbyPlayers: players,
157180
})
158181

159182
// Allow explicit modes like 'work' / 'wander' to remain until changed by caller.

0 commit comments

Comments
 (0)