Skip to content

Commit

Permalink
placing block goal added
Browse files Browse the repository at this point in the history
  • Loading branch information
GenerelSchwerz committed Feb 14, 2024
1 parent 3fd66b8 commit 634db76
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const bot = createBot({
// port: 25497

// host: "node2.endelon-hosting.de", port: 31997
host: 'Ic3TankD2HO.aternos.me',
port: 44656
host: 'node2.meowbot.de',
port: 5000
// host: "us1.node.minecraft.sneakyhub.com",
// port: 25607,
});
Expand Down
6 changes: 4 additions & 2 deletions src/ThePathfinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ export class ThePathfinder {

async cancel (allowRetry = false, timeout = 1000): Promise<void> {
this.cancelCalculation = true
this.allowRetry = allowRetry

if (this.currentExecutor == null) return console.log('no executor')
if (this.currentMove == null) throw new Error('No current move, but there is a current executor.')

if (allowRetry) await this.currentExecutor.abort(this.currentMove, { timeout, resetting: allowRetry })
await this.currentExecutor.abort(this.currentMove, { timeout, resetting: allowRetry })

console.log('tried cancel frfr')
// calling cleanupAll is not necessary as the end of goto already calls it.
}

Expand Down Expand Up @@ -320,6 +322,7 @@ export class ThePathfinder {

async * getPathFromTo (startPos: Vec3, startVel: Vec3, goal: goals.Goal, settings = this.defaultMoveSettings): PathGenerator {
this.cancelCalculation = false
this.allowRetry = false;
this.currentGoal = goal
const move = Move.startMove(new IdleMovement(this.bot, this.world), startPos.clone(), startVel.clone(), this.getScaffoldCount())

Expand Down Expand Up @@ -438,7 +441,6 @@ export class ThePathfinder {
const movementHandler = path.context.movementProvider as MovementHandler
const movements = movementHandler.getMovements()

this.allowRetry = false

// eslint-disable-next-line no-labels
outer: while (currentIndex < path.path.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/mineflayer-specific/movements/movementExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export abstract class MovementExecutor extends Movement {
* TODO: Implement.
*/
public async abort (move: Move = this.currentMove, settings: AbortOpts = {}): Promise<void> {
if (this.cancelled) return
if (this.cancelled || this.resetting) return

const timeout = settings.timeout ?? 1000
const resetting = settings.resetting ?? false
Expand Down
4 changes: 2 additions & 2 deletions src/mineflayer-specific/movements/movementExecutors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ export class ForwardExecutor extends MovementExecutor {
throw new CancelError('ForwardMove: not on ground')
}
if ((this.bot.entity as any).isCollidedHorizontally as boolean) {
// if (this.bot.entity.velocity.offset(0, -this.bot.entity.velocity.y, 0).norm() < 0.02)
// throw new CancelError("ForwardMove: collided horizontally");
if (this.bot.entity.velocity.offset(0, -this.bot.entity.velocity.y, 0).norm() < 0.02)
throw new CancelError("ForwardMove: collided horizontally");
}

const faceForward = await this.faceForward()
Expand Down

0 comments on commit 634db76

Please sign in to comment.