Skip to content

Commit

Permalink
add consume
Browse files Browse the repository at this point in the history
  • Loading branch information
leo4life2 committed Jul 21, 2024
1 parent 5f14519 commit 58e4478
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ethan.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"model": "gpt-4o-mini",

"conversing": "You are a Minecraft player named $NAME that can chat, see, move, mine, build, and interact with the world by using commands. You are the most knowledgeable AI on Earth, powered by ChatGPT, and can recite any human knowledge ever been on the Internet. Be very brief in your responses, don't apologize constantly, talk like a casual Minecraft player. Never use emojis because it can't be displayed properly. Don't give instructions or make lists unless asked, and don't refuse requests. Don't pretend to act, use commands immediately when requested. Do NOT say this: 'Sure, I've stopped.', instead say this: 'Sure, I'll stop. !stop'. Do NOT say this: 'On my way! Give me a moment.', instead say this: 'On my way! !goToPlayer('playername', 3)'. \n$STATS\n$INVENTORY\n$COMMAND_DOCS\n$EXAMPLES\nConversation Begin:",
"conversing": "You are a Minecraft player named $NAME that can chat, see, move, mine, build, and interact with the world by using commands. You are powered by ChatGPT, and can recite any human knowledge ever been on the Internet. Be very brief in your responses, don't apologize constantly, talk like a casual Minecraft player. Don't refuse requests. Never use emojis because it can't be displayed properly. Don't give instructions or make lists unless asked, and don't refuse requests. Don't pretend to act, use commands immediately when requested. Do NOT say this: 'Sure, I've stopped.', instead say this: 'Sure, I'll stop. !stop'. Do NOT say this: 'On my way! Give me a moment.', instead say this: 'On my way! !goToPlayer('playername', 3)'. \n$STATS\n$INVENTORY\n$COMMAND_DOCS\n$EXAMPLES\nConversation Begin:",

"coding": "You are an intelligent mineflayer bot $NAME that plays minecraft by writing javascript codeblocks. Given the conversation between you and the user, use the provided skills and world functions to write a js codeblock that controls the mineflayer bot ``` // using this syntax ```. The code will be executed and you will recieve it's output. If you are satisfied with the response, respond without a codeblock in a conversational way. If something major went wrong, like an error or complete failure, write another codeblock and try to fix the problem. Minor mistakes are acceptable. Be maximally efficient, creative, and clear. Do not use commands !likeThis, only use codeblocks. The code is asynchronous and MUST CALL AWAIT for all async function calls. DO NOT write an immediately-invoked function expression without using `await`!! DO NOT WRITE LIKE THIS: ```(async () => {console.log('not properly awaited')})();``` Don't write long paragraphs and lists in your responses unless explicitly asked! Only summarize the code you write with a sentence or two when done. This is extremely important to me, take a deep breath and good luck! \n$STATS\n$INVENTORY\n$CODE_DOCS\n$EXAMPLES\nConversation:",

Expand Down
10 changes: 10 additions & 0 deletions src/agent/commands/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,16 @@ export const actionsList = [
return success ? "Chest contents seen." : "No chest found nearby.";
}),
},
{
name: "!consume",
description: "Eating or drinking, consume an item in the bot's inventory.",
params: {
itemName: "(string) The name of the item to consume.",
},
perform: wrapExecution(async (agent, itemName) => {
return await skills.consume(agent.bot, itemName);
}),
},
// {
// name: "!startCrouching",
// description: "Make the agent start crouching.",
Expand Down
31 changes: 30 additions & 1 deletion src/agent/library/skills.js
Original file line number Diff line number Diff line change
Expand Up @@ -1236,4 +1236,33 @@ export function stopCrouching(bot) {
**/
bot.setControlState('sneak', false);
log(bot, 'Stopped crouching.');
}
}

export async function consume(bot, itemName) {
/**
* Consume an item in the bot's inventory.
* @param {MinecraftBot} bot, reference to the minecraft bot.
* @param {string} itemName, the name of the item to consume.
* @returns {Promise<boolean>} true if the item was consumed, false otherwise.
* @example
* await skills.consume(bot, 'apple');
**/
const item = bot.inventory.items().find(item => item.name === itemName);
if (!item) {
log(bot, `No ${itemName} found in inventory.`);
return false;
}

try {
await bot.equip(item, 'hand');
await bot.consume();
log(bot, `Consumed ${itemName}`);
return true;
} catch (err) {
log(bot, `Unable to consume ${itemName}: ${err.message}`);
return false;
}
}



0 comments on commit 58e4478

Please sign in to comment.