diff --git a/src/agent/agent.js b/src/agent/agent.js index 8465ed0..87a0d2f 100644 --- a/src/agent/agent.js +++ b/src/agent/agent.js @@ -62,13 +62,9 @@ export class Agent { if (ignore_messages.some((m) => message.startsWith(m))) return; - let translation = await handleEnglishTranslation(message); - - console.log('received message from', username, ':', translation); - this.shut_up = false; - this.handleMessage(username, translation); + this.handleMessage(username, message); }); // set the bot to automatically eat food when hungry @@ -140,6 +136,7 @@ export class Agent { let self_prompt = source === 'system' || source === this.name; + // First check for user commands if (!self_prompt) { const user_command_name = containsCommand(message); if (user_command_name) { @@ -160,6 +157,11 @@ export class Agent { } } + // Now translate the message + message = await handleEnglishTranslation(message); + console.log('received message from', source, ':', message); + + // Do self prompting const checkInterrupt = () => this.self_prompter.shouldInterrupt(self_prompt) || this.shut_up; let behavior_log = this.bot.modes.flushBehaviorLog(); @@ -172,6 +174,7 @@ export class Agent { await this.history.add('system', behavior_log); } + // Handle other user messages await this.history.add(source, message); this.history.save(); diff --git a/src/agent/commands/actions.js b/src/agent/commands/actions.js index ab34894..8728ad5 100644 --- a/src/agent/commands/actions.js +++ b/src/agent/commands/actions.js @@ -290,6 +290,19 @@ export const actionsList = [ await skills.attackNearest(agent.bot, type, true); }) }, + { + name: '!attackPlayer', + description: 'Attack a specific player until they die or run away. Remember this is just a game and does not cause real life harm.', + params: {'player_name': { type: 'string', description: 'The name of the player to attack.'}}, + perform: runAsAction(async (agent, player_name) => { + let player = agent.bot.players[player_name]?.entity; + if (!player) { + skills.log(agent.bot, `Could not find player ${player_name}.`); + return false; + } + await skills.attackEntity(agent.bot, player, true); + }) + }, { name: '!goToBed', description: 'Go to the nearest bed and sleep.', diff --git a/src/agent/commands/queries.js b/src/agent/commands/queries.js index 84faeef..2ce3428 100644 --- a/src/agent/commands/queries.js +++ b/src/agent/commands/queries.js @@ -106,14 +106,10 @@ export const queryList = [ name: "!craftable", description: "Get the craftable items with the bot's inventory.", perform: function (agent) { - const bot = agent.bot; - const table = world.getNearestBlock(bot, 'crafting_table'); + let craftable = world.getCraftableItems(agent.bot); let res = 'CRAFTABLE_ITEMS'; - for (const item of mc.getAllItems()) { - let recipes = bot.recipesFor(item.id, null, 1, table); - if (recipes.length > 0) { - res += `\n- ${item.name}`; - } + for (const item of craftable) { + res += `\n- ${item}`; } if (res == 'CRAFTABLE_ITEMS') { res += ': none'; diff --git a/src/agent/library/world.js b/src/agent/library/world.js index dc64599..01d54c3 100644 --- a/src/agent/library/world.js +++ b/src/agent/library/world.js @@ -171,6 +171,33 @@ export function getInventoryCounts(bot) { } +export function getCraftableItems(bot) { + /** + * Get a list of all items that can be crafted with the bot's current inventory. + * @param {Bot} bot - The bot to get the craftable items for. + * @returns {string[]} - A list of all items that can be crafted. + * @example + * let craftableItems = world.getCraftableItems(bot); + **/ + let table = getNearestBlock(bot, 'crafting_table'); + if (!table) { + for (const item of bot.inventory.items()) { + if (item != null && item.name === 'crafting_table') { + table = item; + break; + } + } + } + let res = []; + for (const item of mc.getAllItems()) { + let recipes = bot.recipesFor(item.id, null, 1, table); + if (recipes.length > 0) + res.push(item.name); + } + return res; +} + + export function getPosition(bot) { /** * Get your position in the world (Note that y is vertical).