mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-29 19:44:53 +02:00
small fixes to unstuck/skills
This commit is contained in:
parent
cb30485943
commit
ee7c715786
3 changed files with 18 additions and 5 deletions
|
@ -114,7 +114,9 @@ export const queryList = [
|
||||||
res += `\n- player: ${entity}`;
|
res += `\n- player: ${entity}`;
|
||||||
}
|
}
|
||||||
for (const entity of world.getNearbyEntityTypes(bot)) {
|
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') {
|
if (res == 'NEARBY_ENTITIES') {
|
||||||
res += ': none';
|
res += ': none';
|
||||||
|
|
|
@ -138,6 +138,7 @@ export async function smeltItem(bot, itemName, num=1) {
|
||||||
if (bot.entity.position.distanceTo(furnaceBlock.position) > 4) {
|
if (bot.entity.position.distanceTo(furnaceBlock.position) > 4) {
|
||||||
await goToNearestBlock(bot, 'furnace', 4, furnaceRange);
|
await goToNearestBlock(bot, 'furnace', 4, furnaceRange);
|
||||||
}
|
}
|
||||||
|
bot.modes.pause('unstuck');
|
||||||
await bot.lookAt(furnaceBlock.position);
|
await bot.lookAt(furnaceBlock.position);
|
||||||
|
|
||||||
console.log('smelting...');
|
console.log('smelting...');
|
||||||
|
@ -181,7 +182,6 @@ export async function smeltItem(bot, itemName, num=1) {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
let collected_last = true;
|
let collected_last = true;
|
||||||
let smelted_item = null;
|
let smelted_item = null;
|
||||||
bot.modes.pause('unstuck');
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 200));
|
await new Promise(resolve => setTimeout(resolve, 200));
|
||||||
while (total < num) {
|
while (total < num) {
|
||||||
await new Promise(resolve => setTimeout(resolve, 10000));
|
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);
|
let enemy = world.getNearestEntityWhere(bot, entity => mc.isHostile(entity), range);
|
||||||
while (enemy) {
|
while (enemy) {
|
||||||
await equipHighestAttack(bot);
|
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 {
|
try {
|
||||||
bot.pathfinder.setMovements(new pf.Movements(bot));
|
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 */}
|
} catch (err) {/* might error if entity dies, ignore */}
|
||||||
}
|
}
|
||||||
bot.pvp.attack(enemy);
|
bot.pvp.attack(enemy);
|
||||||
|
@ -1046,6 +1053,9 @@ export async function avoidEnemies(bot, distance=16) {
|
||||||
if (bot.interrupt_code) {
|
if (bot.interrupt_code) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (enemy && bot.entity.position.distanceTo(enemy.position) < 3) {
|
||||||
|
await attackEntity(bot, enemy, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bot.pathfinder.stop();
|
bot.pathfinder.stop();
|
||||||
log(bot, `Moved ${distance} away from enemies.`);
|
log(bot, `Moved ${distance} away from enemies.`);
|
||||||
|
|
|
@ -101,8 +101,9 @@ const modes = [
|
||||||
}
|
}
|
||||||
if (this.stuck_time > this.max_stuck_time) {
|
if (this.stuck_time > this.max_stuck_time) {
|
||||||
say(agent, 'I\'m stuck!');
|
say(agent, 'I\'m stuck!');
|
||||||
|
this.stuck_time = 0;
|
||||||
execute(this, agent, async () => {
|
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);
|
await skills.moveAway(bot, 5);
|
||||||
clearTimeout(crashTimeout);
|
clearTimeout(crashTimeout);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue