diff --git a/src/agent/coder.js b/src/agent/coder.js index 33de9da..1cbfe76 100644 --- a/src/agent/coder.js +++ b/src/agent/coder.js @@ -150,7 +150,7 @@ export class Coder { } // returns {success: bool, message: string, interrupted: bool, timedout: false} - async execute(func, timeout=1) { + async execute(func, timeout=10) { if (!this.code_template) return {success: false, message: "Code template not loaded.", interrupted: false, timedout: false}; let TIMEOUT; diff --git a/src/agent/commands/actions.js b/src/agent/commands/actions.js index 84f4963..76577b3 100644 --- a/src/agent/commands/actions.js +++ b/src/agent/commands/actions.js @@ -57,6 +57,28 @@ export const actionsList = [ await skills.collectBlock(agent.bot, type, num); }) }, + { + name: '!craftRecipe', + description: 'Craft the given recipe a given number of times. Ex: I will craft 8 sticks !craftRecipe("stick", 2)', + params: { + 'recipe_name': '(string) The name of the output item to craft.', + 'num': '(number) The number of times to craft the recipe. This is NOT the number of output items, as it may craft many more items depending on the recipe.' + }, + perform: wrapExecution(async (agent, recipe_name, num) => { + for (let i=0; i { + let pos = agent.bot.entity.position; + await skills.placeBlock(agent.bot, type, pos.x, pos.y, pos.z); + }) + }, { name: '!attack', description: 'Attack and kill the nearest entity of a given type.', @@ -72,5 +94,12 @@ export const actionsList = [ perform: wrapExecution(async (agent, player_name) => { await skills.defendPlayer(agent.bot, player_name); }) + }, + { + name: '!goToBed', + description: 'Go to the nearest bed and sleep.', + perform: wrapExecution(async (agent) => { + await skills.goToBed(agent.bot); + }) } ]; diff --git a/src/agent/skills.js b/src/agent/skills.js index a025822..1148728 100644 --- a/src/agent/skills.js +++ b/src/agent/skills.js @@ -13,7 +13,7 @@ export async function craftRecipe(bot, itemName) { * Attempt to craft the given item name from a recipe. May craft many items. * @param {MinecraftBot} bot, reference to the minecraft bot. * @param {string} itemName, the item name to craft. - * @returns {Promise} true if the item was crafted, false otherwise. + * @returns {Promise} true if the recipe was crafted, false otherwise. * @example * await skills.craftRecipe(bot, "stick"); **/ @@ -629,4 +629,35 @@ export async function defendPlayer(bot, username) { } return true; -} \ No newline at end of file +} + +export async function goToBed(bot) { + /** + * Sleep in the nearest bed. + * @param {MinecraftBot} bot, reference to the minecraft bot. + * @returns {Promise} true if the bed was found, false otherwise. + * @example + * await skills.goToBed(bot); + **/ + const beds = bot.findBlocks({ + matching: (block) => { + return block.name.includes('bed'); + }, + maxDistance: 32, + count: 1 + }); + if (beds.length === 0) { + log(bot, `Could not find a bed to sleep in.`); + return false; + } + let loc = beds[0]; + await goToPosition(bot, loc.x, loc.y, loc.z); + const bed = bot.blockAt(loc); + await bot.sleep(bed); + log(bot, `You are in bed.`); + while (bot.isSleeping) { + await new Promise(resolve => setTimeout(resolve, 500)); + } + log(bot, `You have woken up.`); + return true; +} diff --git a/src/examples.json b/src/examples.json index 9950928..6a73f41 100644 --- a/src/examples.json +++ b/src/examples.json @@ -22,7 +22,9 @@ {"role": "user", "content": "bobby: Craft a plank"}, {"role": "assistant", "content": "Okay! !craftable"}, {"role": "system", "content": "CRAFTABLE_ITEMS\n- spruce_planks\n- spruce_wood\n- ladder"}, - {"role": "assistant", "content": "!newAction"} + {"role": "assistant", "content": "!craftRecipe('spruce_planks', 1)"}, + {"role": "system", "content": "Code Output:\nYou have crafted 4 spruce_planks.\nCode execution finished successfully."}, + {"role": "assistant", "content": "I've crafted 4 spruce planks!"} ], [ @@ -65,6 +67,8 @@ [ {"role": "user", "content": "trixy88: craft some sticks"}, - {"role": "assistant", "content": "!newAction"} + {"role": "assistant", "content": "!craftRecipe('stick', 4)"}, + {"role": "system", "content": "Code Output:\nYou have crafted 16 sticks.\nCode execution finished successfully."}, + {"role": "assistant", "content": "I've crafted 16 sticks!"} ] ] \ No newline at end of file