Skip to content

Commit

Permalink
provide cleanup code on goals specifically to allow for more compliat…
Browse files Browse the repository at this point in the history
…ed goal behavior
  • Loading branch information
GenerelSchwerz committed Feb 8, 2024
1 parent 02aec94 commit 3f7023d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ThePathfinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export class ThePathfinder {
await this.perform(newPath, goal)
}
}
await this.cleanupAll()
await this.cleanupAll(goal)
}

private async postProcess (pathInfo: Path<Move, Algorithm<Move>>): Promise<Path<Move, Algorithm<Move>>> {
Expand Down Expand Up @@ -397,8 +397,9 @@ export class ThePathfinder {
// await this.bot.waitForTicks(1);
}

async cleanupAll (): Promise<void> {
async cleanupAll (goal: goals.Goal): Promise<void> {
await this.cleanupBot()
await goal.onFinish(this.bot);
this.bot.chat(this.world.getCacheSize())
this.world.clearCache()
this.executing = false
Expand Down
2 changes: 2 additions & 0 deletions src/mineflayer-specific/goals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { Goal as AGoal } from '../abstract'
import { Move } from './move'
import { World } from './world/worldInterface'
import { AABB } from '@nxg-org/mineflayer-util-plugin'
import { Bot } from 'mineflayer'

/**
* The abstract goal definition used by the pathfinder.
*/
export abstract class Goal implements AGoal<Move> {
abstract isEnd (node: Move): boolean
abstract heuristic (node: Move): number
async onFinish (bot: Bot): Promise<void> {}
}

/**
Expand Down

0 comments on commit 3f7023d

Please sign in to comment.