diff --git a/andy.json b/andy.json index 147211e..70d7355 100644 --- a/andy.json +++ b/andy.json @@ -104,6 +104,13 @@ {"role": "assistant", "content": "Okay, first I'll turn off hunting mode !setMode('hunting', false)"}, {"role": "system", "content": "'hunting' mode disabled."}, {"role": "assistant", "content": "Now I'll follow you !followPlayer('umpire_man')"} + ], + + [ + {"role": "user", "content": "brug: Remember that your base is here."}, + {"role": "assistant", "content": "Sure, I'll save this location as my base. !rememberHere('base')"}, + {"role": "user", "content": "brug: Go to your base."}, + {"role": "assistant", "content": "On my way! !goToPlace('base')"} ] ], diff --git a/andy_npc.json b/andy_npc.json index 561f302..c47497d 100644 --- a/andy_npc.json +++ b/andy_npc.json @@ -121,6 +121,13 @@ {"role": "assistant", "content": "Okay, first I'll turn off hunting mode !setMode('hunting', false)"}, {"role": "system", "content": "'hunting' mode disabled."}, {"role": "assistant", "content": "Now I'll follow you !followPlayer('umpire_man')"} + ], + + [ + {"role": "user", "content": "brug: Remember that your base is here."}, + {"role": "assistant", "content": "Sure, I'll save this location as my base. !rememberHere('base')"}, + {"role": "user", "content": "brug: Go to your base."}, + {"role": "assistant", "content": "On my way! !goToPlace('base')"} ] ], diff --git a/pollux.json b/pollux.json index e2de8eb..e94e5eb 100644 --- a/pollux.json +++ b/pollux.json @@ -102,6 +102,13 @@ {"role": "assistant", "content": "Okay, first I'll turn off hunting mode !setMode('hunting', false)"}, {"role": "system", "content": "'hunting' mode disabled."}, {"role": "assistant", "content": "Now I'll follow you !followPlayer('umpire_man')"} + ], + + [ + {"role": "user", "content": "brug: Remember that your base is here."}, + {"role": "assistant", "content": "Sure, I'll save this location as my base. !rememberHere('base')"}, + {"role": "user", "content": "brug: Go to your base."}, + {"role": "assistant", "content": "On my way! !goToPlace('base')"} ] ], diff --git a/radley.json b/radley.json index a5dae28..a9bceda 100644 --- a/radley.json +++ b/radley.json @@ -104,6 +104,13 @@ {"role": "assistant", "content": "Okay, first I'll turn off hunting mode !setMode('hunting', false)"}, {"role": "system", "content": "'hunting' mode disabled."}, {"role": "assistant", "content": "Now I'll follow you !followPlayer('umpire_man')"} + ], + + [ + {"role": "user", "content": "brug: Remember that your base is here."}, + {"role": "assistant", "content": "Sure, I'll save this location as my base. !rememberHere('base')"}, + {"role": "user", "content": "brug: Go to your base."}, + {"role": "assistant", "content": "On my way! !goToPlace('base')"} ] ], diff --git a/src/agent/agent.js b/src/agent/agent.js index 0736d8a..042cc26 100644 --- a/src/agent/agent.js +++ b/src/agent/agent.js @@ -5,6 +5,7 @@ import { initModes } from './modes.js'; import { initBot } from '../utils/mcdata.js'; import { containsCommand, commandExists, executeCommand, truncCommandMessage } from './commands/index.js'; import { NPCContoller } from './npc/controller.js'; +import { MemoryBank } from './memory_bank.js'; export class Agent { @@ -14,6 +15,7 @@ export class Agent { this.history = new History(this); this.coder = new Coder(this); this.npc = new NPCContoller(this); + this.memory_bank = new MemoryBank(); await this.prompter.initExamples(); diff --git a/src/agent/commands/actions.js b/src/agent/commands/actions.js index 23b401b..02c1fbf 100644 --- a/src/agent/commands/actions.js +++ b/src/agent/commands/actions.js @@ -103,6 +103,28 @@ export const actionsList = [ await skills.moveAway(agent.bot, distance); }) }, + { + name: '!rememberHere', + description: 'Save the current location with a given name.', + params: {'name': '(string) The name to remember the location as.'}, + perform: async function (agent, name) { + const pos = agent.bot.entity.position; + agent.memory_bank.rememberPlace(name, pos.x, pos.y, pos.z); + } + }, + { + name: '!goToPlace', + description: 'Go to a saved location.', + params: {'name': '(string) The name of the location to go to.'}, + perform: wrapExecution(async (agent, name) => { + const pos = agent.memory_bank.recallPlace(name); + if (!pos) { + skills.log(agent.bot, `No location named "${name}" saved.`); + return; + } + await skills.goToPosition(agent.bot, pos[0], pos[1], pos[2], 1); + }) + }, { name: '!givePlayer', description: 'Give the specified item to the given player.', diff --git a/src/agent/commands/queries.js b/src/agent/commands/queries.js index 19260b4..99f5fa9 100644 --- a/src/agent/commands/queries.js +++ b/src/agent/commands/queries.js @@ -122,5 +122,12 @@ export const queryList = [ perform: function (agent) { return agent.bot.modes.getStr(); } + }, + { + name: '!savedPlaces', + description: 'List all saved locations.', + perform: async function (agent) { + return "Saved place names: " + agent.memory_bank.getKeys(); + } } ]; diff --git a/src/agent/history.js b/src/agent/history.js index b79ac80..659113b 100644 --- a/src/agent/history.js +++ b/src/agent/history.js @@ -58,6 +58,9 @@ export class History { const modes = this.agent.bot.modes.getJson(); if (modes !== null) data.modes = modes; + const memory_bank = this.agent.memory_bank.getJson(); + if (memory_bank !== null) + data.memory_bank = memory_bank; const json_data = JSON.stringify(data, null, 4); writeFileSync(this.memory_fp, json_data, (err) => { if (err) { @@ -76,6 +79,8 @@ export class History { this.agent.npc.data = NPCData.fromObject(obj.npc); if (obj.modes) this.agent.bot.modes.loadJson(obj.modes); + if (obj.memory_bank) + this.agent.memory_bank.loadJson(obj.memory_bank); this.turns = obj.turns; } catch (err) { console.error(`Error reading ${this.name}'s memory file: ${err.message}`); diff --git a/src/agent/memory_bank.js b/src/agent/memory_bank.js new file mode 100644 index 0000000..a32ab78 --- /dev/null +++ b/src/agent/memory_bank.js @@ -0,0 +1,25 @@ +export class MemoryBank { + constructor() { + this.memory = {}; + } + + rememberPlace(name, x, y, z) { + this.memory[name] = [x, y, z]; + } + + recallPlace(name) { + return this.memory[name]; + } + + getJson() { + return this.memory + } + + loadJson(json) { + this.memory = json; + } + + getKeys() { + return Object.keys(this.memory).join(', ') + } +} \ No newline at end of file diff --git a/src/agent/modes.js b/src/agent/modes.js index 0081682..ef99b59 100644 --- a/src/agent/modes.js +++ b/src/agent/modes.js @@ -26,13 +26,13 @@ const modes = [ const bot = agent.bot; const block = bot.blockAt(bot.entity.position); const blockAbove = bot.blockAt(bot.entity.position.offset(0, 1, 0)); - if (blockAbove.name === 'water' || blockAbove.name === 'flowing_water') { + if (blockAbove && (blockAbove.name === 'water' || blockAbove.name === 'flowing_water')) { // does not call execute so does not interrupt other actions if (!bot.pathfinder.goal) { bot.setControlState('jump', true); } } - else if (this.fall_blocks.some(name => blockAbove.name.includes(name))) { + else if (blockAbove && this.fall_blocks.some(name => blockAbove.name.includes(name))) { execute(this, agent, async () => { await skills.moveAway(bot, 2); });