From 1f6f352e534f74300ec99a37c8dfc6636aef8a4d Mon Sep 17 00:00:00 2001 From: Lawtro37 <98205608+Lawtro37@users.noreply.github.com> Date: Mon, 20 Jan 2025 20:43:35 +1000 Subject: [PATCH 1/5] added digDown skill --- src/agent/library/skills.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index be5882f..765c86d 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -1340,3 +1340,28 @@ export async function activateNearestBlock(bot, type) { 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; } + + +export async function digDown(bot, distance = 10) { + /** + * Digs down a specified distance. + * @param {MinecraftBot} bot, reference to the minecraft bot. + * @param {int} distance, distance to dig down. + * @returns {Promise} true if successfully dug down. + * @example + * await skills.digDown(bot, 10); + **/ + + for (let i = 0; i < distance; i++) { + const targetBlock = bot.blockAt(bot.entity.position.offset(0, -1, 0)); + if (targetBlock && bot.canDigBlock(targetBlock)) { + await bot.dig(targetBlock); + await bot.waitForTicks(10); // wait for a short period to avoid issues + await goToPosition(bot, bot.entity.position.x, bot.entity.position.y - 1, bot.entity.position.z); + } else { + log('Cannot dig block at position:', bot.entity.position.offset(0, -1, 0)); + return false; + } + } + return true; +} From e2cf9912ade4188e7cd3290e9d012457645f23e0 Mon Sep 17 00:00:00 2001 From: Lawtro37 <98205608+Lawtro37@users.noreply.github.com> Date: Mon, 20 Jan 2025 20:44:55 +1000 Subject: [PATCH 2/5] added "!digDown" action to actions.js --- src/agent/commands/actions.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/agent/commands/actions.js b/src/agent/commands/actions.js index 34e6693..e72a778 100644 --- a/src/agent/commands/actions.js +++ b/src/agent/commands/actions.js @@ -407,6 +407,14 @@ export const actionsList = [ return `Converstaion with ${player_name} ended.`; } }, + { + name: '!digDown', + description: 'Digs down a specified distance.', + params: {'distance': { type: 'int', description: 'Distance to dig down'}}, + perform: runAsAction(async (agent, distance) => { + await skills.digDown(agent.bot, distance) + }) + }, // { // commented for now, causes confusion with goal command // name: '!npcGoal', // description: 'Set a simple goal for an item or building to automatically work towards. Do not use for complex goals.', From 2a768c3e9797ba8a0dd7ec9f0e7fe3a6068665e4 Mon Sep 17 00:00:00 2001 From: Lawtro <98205608+Lawtro37@users.noreply.github.com> Date: Tue, 21 Jan 2025 18:45:03 +1000 Subject: [PATCH 3/5] fixed bugs where bot would try to mine water and added safety protections - bot will no longer mine down if its in water or if there is water below the block its standing on - bot will no longer dig down if its going to fall into water or lava or a drop more than 5 blocks --- src/agent/library/skills.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index 765c86d..d6f6e72 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -1354,12 +1354,23 @@ export async function digDown(bot, distance = 10) { for (let i = 0; i < distance; i++) { const targetBlock = bot.blockAt(bot.entity.position.offset(0, -1, 0)); + const belowBlock = bot.blockAt(bot.entity.position.offset(0, -2, 0)); + + // Check for lava, water, or a fall of more than 5 blocks below the bot + if (!targetBlock || targetBlock.name === 'lava' || targetBlock.name === 'water' || + (belowBlock && (belowBlock.name === 'lava' || belowBlock.name === 'water' || belowBlock.position.y < bot.entity.position.y - 5))) { + console.log('not safe to dig block at position:', bot.entity.position.offset(0, -1, 0)); + log('not safe to dig block at position:' + bot.entity.position.offset(0, -1, 0)) + return false; + } + if (targetBlock && bot.canDigBlock(targetBlock)) { await bot.dig(targetBlock); await bot.waitForTicks(10); // wait for a short period to avoid issues - await goToPosition(bot, bot.entity.position.x, bot.entity.position.y - 1, bot.entity.position.z); + await bot.entity.position.offset(0, -1, 0); } else { - log('Cannot dig block at position:', bot.entity.position.offset(0, -1, 0)); + console.log('Cannot dig block at position:', bot.entity.position.offset(0, -1, 0)); + log('Cannot dig block at position:' + bot.entity.position.offset(0, -1, 0)) return false; } } From d75c7304fd81c8f8a579116bb12076d9e2c961db Mon Sep 17 00:00:00 2001 From: Lawtro <98205608+Lawtro37@users.noreply.github.com> Date: Wed, 22 Jan 2025 12:31:50 +1000 Subject: [PATCH 4/5] change danger log message --- src/agent/library/skills.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index d6f6e72..8b71acc 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -1359,8 +1359,8 @@ export async function digDown(bot, distance = 10) { // Check for lava, water, or a fall of more than 5 blocks below the bot if (!targetBlock || targetBlock.name === 'lava' || targetBlock.name === 'water' || (belowBlock && (belowBlock.name === 'lava' || belowBlock.name === 'water' || belowBlock.position.y < bot.entity.position.y - 5))) { - console.log('not safe to dig block at position:', bot.entity.position.offset(0, -1, 0)); - log('not safe to dig block at position:' + bot.entity.position.offset(0, -1, 0)) + console.log('Dug down i blocks, but reached (lava/water/dangerous fall)'); + log('Dug down i blocks, but reached (lava/water/dangerous fall)') return false; } From fbc2734e5259403664340fe147474c0b7f0022d1 Mon Sep 17 00:00:00 2001 From: Lawtro <98205608+Lawtro37@users.noreply.github.com> Date: Wed, 22 Jan 2025 13:35:18 +1000 Subject: [PATCH 5/5] fixed fall protection and tweaked other things --- src/agent/library/skills.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index 8b71acc..8566f55 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -1356,21 +1356,37 @@ export async function digDown(bot, distance = 10) { const targetBlock = bot.blockAt(bot.entity.position.offset(0, -1, 0)); const belowBlock = bot.blockAt(bot.entity.position.offset(0, -2, 0)); - // Check for lava, water, or a fall of more than 5 blocks below the bot + // Check for lava, water if (!targetBlock || targetBlock.name === 'lava' || targetBlock.name === 'water' || - (belowBlock && (belowBlock.name === 'lava' || belowBlock.name === 'water' || belowBlock.position.y < bot.entity.position.y - 5))) { - console.log('Dug down i blocks, but reached (lava/water/dangerous fall)'); - log('Dug down i blocks, but reached (lava/water/dangerous fall)') + (belowBlock && (belowBlock.name === 'lava' || belowBlock.name === 'water'))) { + console.log(`Dug down ${i} blocks, but reached ${belowBlock ? belowBlock.name : '(lava/water)'}`); + log(bot, `Dug down ${i} blocks, but reached ${belowBlock ? belowBlock.name : '(lava/water)'}`) return false; } - if (targetBlock && bot.canDigBlock(targetBlock)) { - await bot.dig(targetBlock); + // Check for a fall of more than 5 blocks below the bot + let isSafe = false; + for (let j = 1; j <= 5; j++) { + const belowBlock = bot.blockAt(bot.entity.position.offset(0, -j-1, 0)); + if (!belowBlock || belowBlock.name !== 'air') { + isSafe = true; + break; + } + } + + if (!targetBlock || !isSafe) { + console.log(`Dug down ${i} blocks, but reached fall`); + log(bot, `Dug down ${i} blocks, but reached fall`); + return false; + } + + if (bot.canDigBlock(targetBlock)) { + await breakBlockAt(bot, bot.entity.position.x, bot.entity.position.y - 1, bot.entity.position.z); await bot.waitForTicks(10); // wait for a short period to avoid issues await bot.entity.position.offset(0, -1, 0); } else { console.log('Cannot dig block at position:', bot.entity.position.offset(0, -1, 0)); - log('Cannot dig block at position:' + bot.entity.position.offset(0, -1, 0)) + log(bot, 'Cannot dig block at position:' + bot.entity.position.offset(0, -1, 0)) return false; } }