Merge branch 'main' into load-npc

This commit is contained in:
MaxRobinsonTheGreat 2024-05-04 16:21:55 -05:00
commit 385c46bf35
10 changed files with 91 additions and 2 deletions

View file

@ -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')"}
]
],

View file

@ -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')"}
]
],

View file

@ -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')"}
]
],

View file

@ -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')"}
]
],

View file

@ -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();

View file

@ -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.',

View file

@ -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();
}
}
];

View file

@ -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}`);

25
src/agent/memory_bank.js Normal file
View file

@ -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(', ')
}
}

View file

@ -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);
});