mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-21 22:53:45 +02:00
crash when fail to stop, improve digging
This commit is contained in:
parent
f203b7ca4e
commit
913b39b0b6
2 changed files with 23 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue