mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-23 22:52:06 +02:00
wandering for goal, and tool goal fix
This commit is contained in:
parent
16c8192872
commit
214999df2f
2 changed files with 26 additions and 7 deletions
|
@ -175,8 +175,15 @@ export class Agent {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.bot.on('idle', () => {
|
this.bot.on('idle', async () => {
|
||||||
|
// Resume all paused modes
|
||||||
this.bot.modes.unPauseAll();
|
this.bot.modes.unPauseAll();
|
||||||
|
|
||||||
|
// Wait a while for inputs before acting independently
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||||
|
if (!this.isIdle()) return;
|
||||||
|
|
||||||
|
// Resume behavior or persue goal
|
||||||
if (this.coder.resume_func != null)
|
if (this.coder.resume_func != null)
|
||||||
this.coder.executeResume();
|
this.coder.executeResume();
|
||||||
else
|
else
|
||||||
|
|
|
@ -309,6 +309,7 @@ export class ItemGoal {
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
this.goals = [];
|
this.goals = [];
|
||||||
this.nodes = {};
|
this.nodes = {};
|
||||||
|
this.failed = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
setGoals(goals) {
|
setGoals(goals) {
|
||||||
|
@ -321,11 +322,10 @@ export class ItemGoal {
|
||||||
async executeNext() {
|
async executeNext() {
|
||||||
// Get goal by priority
|
// Get goal by priority
|
||||||
let goal = null;
|
let goal = null;
|
||||||
let inventory = world.getInventoryCounts(this.agent.bot);
|
|
||||||
for (let g of this.goals) {
|
for (let g of this.goals) {
|
||||||
if (inventory[g.name] === undefined || inventory[g.name] < g.quantity) {
|
|
||||||
if (this.nodes[g.name] === undefined)
|
if (this.nodes[g.name] === undefined)
|
||||||
this.nodes[g.name] = new ItemWrapper(this, null, g.name);
|
this.nodes[g.name] = new ItemWrapper(this, null, g.name);
|
||||||
|
if (!this.nodes[g.name].isDone(g.quantity)) {
|
||||||
goal = this.nodes[g.name];
|
goal = this.nodes[g.name];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -342,8 +342,20 @@ export class ItemGoal {
|
||||||
if (next.type === 'block' && !world.getNearbyBlockTypes(this.agent.bot).includes(next.source) ||
|
if (next.type === 'block' && !world.getNearbyBlockTypes(this.agent.bot).includes(next.source) ||
|
||||||
next.type === 'hunt' && !world.getNearbyEntityTypes(this.agent.bot).includes(next.source)) {
|
next.type === 'hunt' && !world.getNearbyEntityTypes(this.agent.bot).includes(next.source)) {
|
||||||
next.fails += 1;
|
next.fails += 1;
|
||||||
|
|
||||||
|
// If the bot has failed to obtain the block before, explore
|
||||||
|
if (this.failed.includes(next.name)) {
|
||||||
|
this.failed = this.failed.filter((item) => item !== next.name);
|
||||||
|
this.agent.coder.interruptible = true;
|
||||||
|
await this.agent.coder.execute(async () => {
|
||||||
|
await skills.moveAway(this.agent.bot, 8);
|
||||||
|
}, this.timeout);
|
||||||
|
this.agent.coder.interruptible = false;
|
||||||
|
} else {
|
||||||
|
this.failed.push(next.name);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
this.agent.bot.emit('idle');
|
this.agent.bot.emit('idle');
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue