mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-07-02 22:55:20 +02:00
added sleep,craft,place commands
This commit is contained in:
parent
8429489839
commit
cf14b7ca6d
4 changed files with 69 additions and 5 deletions
|
@ -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;
|
||||
|
|
|
@ -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<num; i++) {
|
||||
await skills.craftRecipe(agent.bot, recipe_name);
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
name: '!placeHere',
|
||||
description: 'Place a given block in the current location. Do NOT use to build structures, only use for single blocks/torches. Ex: !placeBlockHere("crafting_table")',
|
||||
params: {'type': '(string) The block type to place.'},
|
||||
perform: wrapExecution(async (agent, type) => {
|
||||
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);
|
||||
})
|
||||
}
|
||||
];
|
||||
|
|
|
@ -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<boolean>} true if the item was crafted, false otherwise.
|
||||
* @returns {Promise<boolean>} 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;
|
||||
}
|
||||
}
|
||||
|
||||
export async function goToBed(bot) {
|
||||
/**
|
||||
* Sleep in the nearest bed.
|
||||
* @param {MinecraftBot} bot, reference to the minecraft bot.
|
||||
* @returns {Promise<boolean>} 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;
|
||||
}
|
||||
|
|
|
@ -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!"}
|
||||
]
|
||||
]
|
Loading…
Add table
Reference in a new issue