feat(minecraft): move gaze to perception + query.gaze

This commit is contained in:
Rin
2026-02-18 11:14:43 +08:00
committed by Neko Ayaka
parent 5ea05fb33e
commit 942d03584a
6 changed files with 10 additions and 27 deletions
@@ -229,6 +229,7 @@ export class JavaScriptPlanner {
{ name: 'query', kind: 'object', readonly: true },
{ name: 'query.self', kind: 'function', readonly: true },
{ name: 'query.snapshot', kind: 'function', readonly: true },
{ name: 'query.gaze', kind: 'function', readonly: true },
{ name: 'bot', kind: 'object', readonly: true },
{ name: 'mineflayer', kind: 'object', readonly: true },
{ name: 'mem', kind: 'object', readonly: false },
@@ -5,6 +5,8 @@ import type { Mineflayer } from '../../libs/mineflayer'
import { Vec3 } from 'vec3'
import { computeNearbyPlayerGaze } from '../perception/gaze'
import * as world from '../../skills/world'
interface BlockRecord {
@@ -388,5 +390,11 @@ export function createQueryRuntime(mineflayer: Mineflayer) {
entities: () => new EntityQueryChain(mineflayer),
inventory: () => new InventoryQueryChain(mineflayer),
craftable: () => new NameQueryChain(world.getCraftableItems(mineflayer)),
gaze: (options?: { range?: number }) => {
return computeNearbyPlayerGaze(mineflayer.bot, {
maxDistance: 32,
nearbyDistance: options?.range ?? 16,
})
},
}
}
+1 -10
View File
@@ -5,7 +5,6 @@ import { DebugService } from '../debug'
import { McpReplServer } from '../debug/mcp-repl-server'
import { ChatMessageHandler } from '../libs/mineflayer'
import { createAgentContainer } from './container'
import { computeNearbyPlayerGaze } from './reflex/gaze'
export function CognitiveEngine(options: CognitiveEngineOptions): MineflayerPlugin {
let container: ReturnType<typeof createAgentContainer>
@@ -91,15 +90,7 @@ export function CognitiveEngine(options: CognitiveEngineOptions): MineflayerPlug
if (tickCount % 5 !== 0)
return
const gaze = computeNearbyPlayerGaze(bot.bot, { maxDistance: 32, nearbyDistance: 16 })
reflexManager.updateEnvironment({
nearbyPlayersGaze: gaze.map(g => ({
name: g.playerName,
distanceToSelf: g.distanceToSelf,
lookPoint: g.lookPoint,
hitBlock: g.hitBlock,
})),
})
// Other periodic updates can go here
})
// Resolve EventBus for message handling
@@ -11,12 +11,6 @@ export interface ReflexEnvironmentState {
time: string
weather: 'clear' | 'rain' | 'thunder'
nearbyPlayers: Array<{ name: string, distance?: number, holding?: string | null }>
nearbyPlayersGaze: Array<{
name: string
distanceToSelf: number
lookPoint: { x: number, y: number, z: number }
hitBlock: null | { name: string, pos: { x: number, y: number, z: number } }
}>
nearbyEntities: Array<{ name: string, distance?: number, kind?: string }>
lightLevel: number
}
@@ -75,7 +69,6 @@ export class ReflexContext {
time: 'SOMETHING WENT WRONG, YOU SHOULD NOTIFY THE USER OF THIS',
weather: 'clear',
nearbyPlayers: [],
nearbyPlayersGaze: [],
nearbyEntities: [],
lightLevel: 15,
},
@@ -113,16 +106,6 @@ export class ReflexContext {
environment: {
...this.state.environment,
nearbyPlayers: this.state.environment.nearbyPlayers.map(p => ({ ...p })),
nearbyPlayersGaze: this.state.environment.nearbyPlayersGaze.map(p => ({
...p,
lookPoint: { ...p.lookPoint },
hitBlock: p.hitBlock
? {
...p.hitBlock,
pos: { ...p.hitBlock.pos },
}
: null,
})),
nearbyEntities: this.state.environment.nearbyEntities.map(e => ({ ...e })),
},
social: {