From b9f2f74df4f9dc2686424e58b3404a07e0efbd4a Mon Sep 17 00:00:00 2001 From: MaxRobinsonTheGreat Date: Fri, 19 Apr 2024 14:01:46 -0500 Subject: [PATCH 1/2] fixed torch placer bug --- src/agent/modes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent/modes.js b/src/agent/modes.js index 78b62a6..0298e21 100644 --- a/src/agent/modes.js +++ b/src/agent/modes.js @@ -87,7 +87,7 @@ const modes = [ // TODO: check light level instead of nearby torches, block.light is broken const near_torch = world.getNearestBlock(agent.bot, 'torch', 6); if (!near_torch) { - let torches = agent.bot.inventory.items().filter(item => item.name.includes('torch')); + let torches = agent.bot.inventory.items().filter(item => item.name === 'torch'); if (torches.length > 0) { const torch = torches[0]; const pos = agent.bot.entity.position; From 9a929fc3b292abdb21579890a6d3820e271ca7e2 Mon Sep 17 00:00:00 2001 From: MaxRobinsonTheGreat Date: Fri, 19 Apr 2024 14:02:30 -0500 Subject: [PATCH 2/2] added activate command --- src/agent/commands/actions.js | 8 ++++++++ src/agent/library/skills.js | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/agent/commands/actions.js b/src/agent/commands/actions.js index 0b8943d..a57a464 100644 --- a/src/agent/commands/actions.js +++ b/src/agent/commands/actions.js @@ -182,6 +182,14 @@ export const actionsList = [ await skills.goToBed(agent.bot); }) }, + { + name: '!activate', + description: 'Activate the nearest object of a given type.', + params: {'type': '(string) The type of object to activate.'}, + perform: wrapExecution(async (agent, type) => { + await skills.activateNearestBlock(agent.bot, type); + }) + }, { name: '!stay', description: 'Stay in the current location no matter what. Pauses all modes.', diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index 829ccbe..0e5f1f8 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -869,3 +869,27 @@ export async function tillAndSow(bot, x, y, z, seedType=null) { } return true; } + +export async function activateNearestBlock(bot, type) { + /** + * Activate the nearest block of the given type. + * @param {MinecraftBot} bot, reference to the minecraft bot. + * @param {string} type, the type of block to activate. + * @returns {Promise} true if the block was activated, false otherwise. + * @example + * await skills.activateNearestBlock(bot, "lever"); + * **/ + let block = world.getNearestBlock(bot, type, 16); + if (!block) { + log(bot, `Could not find any ${type} to activate.`); + return false; + } + if (bot.entity.position.distanceTo(block.position) > 4.5) { + let pos = block.position; + bot.pathfinder.setMovements(new pf.Movements(bot)); + await bot.pathfinder.goto(new pf.goals.GoalNear(pos.x, pos.y, pos.z, 4)); + } + await bot.activateBlock(block); + log(bot, `Activated ${type} at x:${block.position.x.toFixed(1)}, y:${block.position.y.toFixed(1)}, z:${block.position.z.toFixed(1)}.`); + return true; +}