mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-21 21:52:07 +02:00
use goalfollow but await before returning
This commit is contained in:
parent
aa3924a819
commit
94283e6ec6
2 changed files with 6 additions and 5 deletions
|
@ -102,7 +102,7 @@ export class Coder {
|
|||
this.agent.bot.abort_code = true;
|
||||
this.agent.bot.collectBlock.cancelTask();
|
||||
this.agent.bot.pathfinder.stop();
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
this.current_code = '';
|
||||
this.abort_code = false;
|
||||
|
|
|
@ -198,7 +198,7 @@ export async function goToPlayer(bot, username) {
|
|||
|
||||
export async function followPlayer(bot, username) {
|
||||
/**
|
||||
* Follow the given player endlessly.
|
||||
* Follow the given player endlessly. Will not return until the code is manually stopped.
|
||||
* @param {MinecraftBot} bot, reference to the minecraft bot.
|
||||
* @param {string} username, the username of the player to follow.
|
||||
* @returns {Promise<boolean>} true if the player was found, false otherwise.
|
||||
|
@ -210,10 +210,11 @@ export async function followPlayer(bot, username) {
|
|||
return false;
|
||||
|
||||
bot.pathfinder.setMovements(new pf.Movements(bot));
|
||||
while (!bot.abort) {
|
||||
bot.pathfinder.setGoal(new pf.goals.GoalFollow(player, 2), true);
|
||||
|
||||
while (!bot.abort_code) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
let pos = player.position;
|
||||
await bot.pathfinder.goto(new pf.goals.GoalNear(pos.x, pos.y, pos.z, 3));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
Loading…
Add table
Reference in a new issue