diff --git a/src/agent/coder.js b/src/agent/coder.js index d4d842a..f564abb 100644 --- a/src/agent/coder.js +++ b/src/agent/coder.js @@ -210,13 +210,17 @@ export class Coder { async stop() { if (!this.executing) return; + const start = Date.now(); while (this.executing) { this.agent.bot.interrupt_code = true; this.agent.bot.collectBlock.cancelTask(); this.agent.bot.pathfinder.stop(); this.agent.bot.pvp.stop(); - console.log('waiting for code to finish executing... interrupt:', this.agent.bot.interrupt_code); + console.log('waiting for code to finish executing...'); await new Promise(resolve => setTimeout(resolve, 1000)); + if (Date.now() - start > 10 * 1000) { + process.exit(1); // force exit program after 10 seconds of failing to stop + } } } diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index 5fb46f1..906b24b 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -416,9 +416,24 @@ export async function breakBlockAt(bot, x, y, z) { * let position = world.getPosition(bot); * await skills.breakBlockAt(bot, position.x, position.y - 1, position.x); **/ - let current = bot.blockAt(Vec3(x, y, z)); - if (current.name != 'air') - await bot.dig(current, true); + let block = bot.blockAt(Vec3(x, y, z)); + if (block.name !== 'air' && block.name !== 'water' && block.name !== 'lava') { + await bot.tool.equipForBlock(block); + const itemId = bot.heldItem ? bot.heldItem.type : null + if (!block.canHarvest(itemId)) { + log(bot, `Don't have right tools to break ${block.name}.`); + return false; + } + if (bot.entity.position.distanceTo(block.position) > 4.5) { + let pos = block.position; + let movements = new pf.Movements(bot); + movements.canPlaceOn = false; + movements.allow1by1towers = false; + bot.pathfinder.setMovements(); + await bot.pathfinder.goto(new pf.goals.GoalNear(pos.x, pos.y, pos.z, 4)); + } + await bot.dig(block, true); + } return true; }