mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-05 06:45:35 +02:00
clear pathfinder on idle, improve coward mode
This commit is contained in:
parent
559af27254
commit
6727b44afc
2 changed files with 6 additions and 3 deletions
|
@ -188,6 +188,7 @@ export class Agent {
|
||||||
});
|
});
|
||||||
this.bot.on('idle', () => {
|
this.bot.on('idle', () => {
|
||||||
this.bot.clearControlStates();
|
this.bot.clearControlStates();
|
||||||
|
this.bot.pathfinder.stop(); // clear any lingering pathfinder
|
||||||
this.bot.modes.unPauseAll();
|
this.bot.modes.unPauseAll();
|
||||||
this.coder.executeResume();
|
this.coder.executeResume();
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,7 +15,8 @@ async function autoLight(bot) {
|
||||||
let nearest_torch = world.getNearestBlock(bot, 'torch', 6);
|
let nearest_torch = world.getNearestBlock(bot, 'torch', 6);
|
||||||
if (!nearest_torch) {
|
if (!nearest_torch) {
|
||||||
let has_torch = bot.inventory.items().find(item => item.name === 'torch');
|
let has_torch = bot.inventory.items().find(item => item.name === 'torch');
|
||||||
if (has_torch) {
|
const curr_block = agent.bot.blockAt(pos);
|
||||||
|
if (has_torch && curr_block.name === 'air') {
|
||||||
try {
|
try {
|
||||||
log(bot, `Placing torch at ${bot.entity.position}.`);
|
log(bot, `Placing torch at ${bot.entity.position}.`);
|
||||||
return await placeBlock(bot, 'torch', bot.entity.position.x, bot.entity.position.y, bot.entity.position.z);
|
return await placeBlock(bot, 'torch', bot.entity.position.x, bot.entity.position.y, bot.entity.position.z);
|
||||||
|
@ -771,7 +772,7 @@ export async function avoidEnemies(bot, distance=16) {
|
||||||
* @example
|
* @example
|
||||||
* await skills.avoidEnemies(bot, 8);
|
* await skills.avoidEnemies(bot, 8);
|
||||||
**/
|
**/
|
||||||
|
bot.modes.pause('self_preservation'); // prevents damage-on-low-health from interrupting the bot
|
||||||
let enemy = world.getNearestEntityWhere(bot, entity => mc.isHostile(entity), distance);
|
let enemy = world.getNearestEntityWhere(bot, entity => mc.isHostile(entity), distance);
|
||||||
while (enemy) {
|
while (enemy) {
|
||||||
const follow = new pf.goals.GoalFollow(enemy, distance+1); // move a little further away
|
const follow = new pf.goals.GoalFollow(enemy, distance+1); // move a little further away
|
||||||
|
@ -781,9 +782,10 @@ export async function avoidEnemies(bot, distance=16) {
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||||||
enemy = world.getNearestEntityWhere(bot, entity => mc.isHostile(entity), distance);
|
enemy = world.getNearestEntityWhere(bot, entity => mc.isHostile(entity), distance);
|
||||||
if (bot.interrupt_code) {
|
if (bot.interrupt_code) {
|
||||||
return false;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bot.pathfinder.stop();
|
||||||
log(bot, `Moved ${distance} away from enemies.`);
|
log(bot, `Moved ${distance} away from enemies.`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue