From ee7c71578677c4429442daa8ca3ece29e720f65e Mon Sep 17 00:00:00 2001 From: MaxRobinsonTheGreat Date: Thu, 10 Oct 2024 22:17:39 -0500 Subject: [PATCH] small fixes to unstuck/skills --- src/agent/commands/queries.js | 4 +++- src/agent/library/skills.js | 16 +++++++++++++--- src/agent/modes.js | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/agent/commands/queries.js b/src/agent/commands/queries.js index 322efb5..457a6a3 100644 --- a/src/agent/commands/queries.js +++ b/src/agent/commands/queries.js @@ -114,7 +114,9 @@ export const queryList = [ res += `\n- player: ${entity}`; } for (const entity of world.getNearbyEntityTypes(bot)) { - res += `\n- mob: ${entity}`; + if (entity === 'player' || entity === 'item') + continue; + res += `\n- entities: ${entity}`; } if (res == 'NEARBY_ENTITIES') { res += ': none'; diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index 788cd4e..a7643c7 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -138,6 +138,7 @@ export async function smeltItem(bot, itemName, num=1) { if (bot.entity.position.distanceTo(furnaceBlock.position) > 4) { await goToNearestBlock(bot, 'furnace', 4, furnaceRange); } + bot.modes.pause('unstuck'); await bot.lookAt(furnaceBlock.position); console.log('smelting...'); @@ -181,7 +182,6 @@ export async function smeltItem(bot, itemName, num=1) { let total = 0; let collected_last = true; let smelted_item = null; - bot.modes.pause('unstuck'); await new Promise(resolve => setTimeout(resolve, 200)); while (total < num) { await new Promise(resolve => setTimeout(resolve, 10000)); @@ -330,10 +330,17 @@ export async function defendSelf(bot, range=9) { let enemy = world.getNearestEntityWhere(bot, entity => mc.isHostile(entity), range); while (enemy) { await equipHighestAttack(bot); - if (bot.entity.position.distanceTo(enemy.position) > 4 && enemy.name !== 'creeper' && enemy.name !== 'phantom') { + if (bot.entity.position.distanceTo(enemy.position) >= 4 && enemy.name !== 'creeper' && enemy.name !== 'phantom') { try { bot.pathfinder.setMovements(new pf.Movements(bot)); - await bot.pathfinder.goto(new pf.goals.GoalFollow(enemy, 2), true); + await bot.pathfinder.goto(new pf.goals.GoalFollow(enemy, 3.5), true); + } catch (err) {/* might error if entity dies, ignore */} + } + if (bot.entity.position.distanceTo(enemy.position) <= 2) { + try { + bot.pathfinder.setMovements(new pf.Movements(bot)); + let inverted_goal = new pf.goals.GoalInvert(new pf.goals.GoalFollow(enemy, 2)); + await bot.pathfinder.goto(inverted_goal, true); } catch (err) {/* might error if entity dies, ignore */} } bot.pvp.attack(enemy); @@ -1046,6 +1053,9 @@ export async function avoidEnemies(bot, distance=16) { if (bot.interrupt_code) { break; } + if (enemy && bot.entity.position.distanceTo(enemy.position) < 3) { + await attackEntity(bot, enemy, false); + } } bot.pathfinder.stop(); log(bot, `Moved ${distance} away from enemies.`); diff --git a/src/agent/modes.js b/src/agent/modes.js index c5e1c33..2e47fb3 100644 --- a/src/agent/modes.js +++ b/src/agent/modes.js @@ -101,8 +101,9 @@ const modes = [ } if (this.stuck_time > this.max_stuck_time) { say(agent, 'I\'m stuck!'); + this.stuck_time = 0; execute(this, agent, async () => { - const crashTimeout = setTimeout(() => { throw new Error('Bot was stuck and could not get unstuck.'); }, 10000); + const crashTimeout = setTimeout(() => { agent.cleanKill("Got stuck and couldn't get unstuck") }, 10000); await skills.moveAway(bot, 5); clearTimeout(crashTimeout); });