diff --git a/src/PathfinderHandling.ts b/src/PathfinderHandling.ts index fa60c3a..0aa24ed 100644 --- a/src/PathfinderHandling.ts +++ b/src/PathfinderHandling.ts @@ -1,3 +1,4 @@ +// @ts-nocheck import { Bot, BotEvents } from 'mineflayer' import { AStar as AAStar } from './abstract/algorithms/astar' import { AStar, Path, PathProducer } from './mineflayer-specific/algs' @@ -46,7 +47,6 @@ import { Task } from '@nxg-org/mineflayer-util-plugin' import { reconstructPath } from './abstract/algorithms' import { closestPointOnLineSegment, getScaffoldCount } from './utils' import { World } from './mineflayer-specific/world/worldInterface' -import { InteractType } from './mineflayer-specific/movements/interactionUtils' export interface PathfinderOptions { partialPathProducer: boolean @@ -58,7 +58,7 @@ const DEFAULT_PATHFINDER_OPTS: PathfinderOptions = { partialPathLength: 50 } -const EMPTY_VEC = new Vec3(0, 0, 0) +// const EMPTY_VEC = new Vec3(0, 0, 0) /** * These are the default movement types and their respective executors. @@ -109,10 +109,10 @@ interface PathGeneratorResult { astarContext: AAStar } -interface PerformOpts { - errorOnReset?: boolean - errorOnAbort?: boolean -} +// interface PerformOpts { +// errorOnReset?: boolean +// errorOnAbort?: boolean +// } interface HandlerOpts { world?: CacheSyncWorld @@ -239,7 +239,7 @@ export class PathfinderHandler { } async interrupt (timeout = 1000, cancelCalculation = true, reasonStr?: ResetReason): Promise { - console.log('INTERRUPT CALLED') + console.log('INTERRUPT CALLED') if (this._currentProducer == null) return console.log('no producer') this.abortCalculation = cancelCalculation @@ -437,7 +437,7 @@ export class PathfinderHandler { // utility for identifying where partial paths merge - async perform () {} + async perform (): Promise {} // path getting utilities @@ -486,7 +486,7 @@ export class PathfinderHandler { if (result.status === 'success') { cleanup() this.bot.emit('pathGenerated', result) - console.log('locality %', (MovementHandler.count / MovementHandler.totCount) * 100) + console.log('locality %', (MovementHandler.count / MovementHandler.totCount) * 100) MovementHandler.count = 0 MovementHandler.totCount = 0 yield { result, astarContext } @@ -495,7 +495,7 @@ export class PathfinderHandler { if (this.abortCalculation) { cleanup() - result.status === 'canceled' + result.status = 'canceled' yield { result, astarContext } return { result, astarContext } } @@ -570,7 +570,7 @@ export class PathfinderHandler { await this.cleanupBot() this.world.cleanup?.() - console.log('CLEANUP CALLED') + console.log('CLEANUP CALLED') if (this.userAborted) this.bot.emit('goalAborted', goal) else this.bot.emit('goalFinished', goal) @@ -583,39 +583,37 @@ export class PathfinderHandler { } } +// eslint-disable-next-line @typescript-eslint/no-unused-vars class Perform { public currentIndex = 0 - public curPath: Move[] = []; + public curPath: Move[] = [] constructor (private readonly bot: Bot, private readonly handler: PathfinderHandler, public readonly goal: goals.Goal) {} async perform (): Promise { while (this.currentIndex < this.curPath.length) { - const move = this.curPath[this.currentIndex] - const executor = this.handler.movements.get(move.moveType.constructor as BuildableMoveProvider) - if (executor == null) throw new Error('No executor for move type.') - - // this.handler.currentMove = move - // this.handler.currentExecutor = executor - - try { - await executor.perform(move, this.currentIndex, this.curPath); - } catch (err) { - if (err instanceof AbortError) { - return - } else if (err instanceof ResetError) { - return - }else if (err instanceof CancelError) { - this.identRecover(); - return - } else { - throw err - } + const move = this.curPath[this.currentIndex] + const executor = this.handler.movements.get(move.moveType.constructor as BuildableMoveProvider) + if (executor == null) throw new Error('No executor for move type.') + + // this.handler.currentMove = move + // this.handler.currentExecutor = executor + + try { + await executor.perform(move, this.currentIndex, this.curPath) + } catch (err) { + if (err instanceof AbortError) { + return + } else if (err instanceof ResetError) { + return + } else if (err instanceof CancelError) { + void this.identRecover() + return + } else { + throw err } + } } - - - } async identRecover (): Promise {} @@ -632,9 +630,6 @@ class Perform { // due to the nature of our partial paths, all new paths must be longer than the current path. if (newPath.length < this.curPath.length) throw new Error('new path is shorter than current path') - - - for (let i = this.curPath.length - 1; i >= 0; i--) { const move = this.curPath[i] @@ -644,16 +639,13 @@ class Perform { // if i is greater than current index, then merge is clean as we have not passed the overlap index. if (i > this.currentIndex) { - // include current node - this.curPath = this.curPath.slice(0, i+1).concat(newPath.slice(1)) - } - // we are already perfoming the move where overlap occurs. - else if (i == this.currentIndex) { + // include current node + this.curPath = this.curPath.slice(0, i + 1).concat(newPath.slice(1)) + } else if (i === this.currentIndex) { + // we are already perfoming the move where overlap occurs. if (this.curPath[i].exitPos.equals(newPath[0].entryPos)) this.curPath = this.curPath.slice(0, i).concat(newPath) else throw new Error('overlap is not clean') - } - // TODO: handle - else if (i < this.currentIndex) throw new Error('overlap is not clean') + } else if (i < this.currentIndex) throw new Error('overlap is not clean') } } } diff --git a/src/ThePathfinder.ts b/src/ThePathfinder.ts index 1c92812..a9d20da 100644 --- a/src/ThePathfinder.ts +++ b/src/ThePathfinder.ts @@ -11,7 +11,6 @@ import { BuildableMoveProvider, MovementHandler, MovementOptions, - MovementSetup, ExecutorMap, MovementExecutor, DEFAULT_MOVEMENT_OPTS @@ -38,7 +37,7 @@ import { IdleMovementExecutor } from './mineflayer-specific/movements/movementExecutors' import { DropDownOpt, ForwardJumpUpOpt, StraightAheadOpt } from './mineflayer-specific/post/optimizers' -import { BuildableOptimizer, OptimizationSetup, MovementOptimizer, OptimizationMap, Optimizer } from './mineflayer-specific/post' +import { BuildableOptimizer, MovementOptimizer, OptimizationMap, Optimizer } from './mineflayer-specific/post' import { ContinuousPathProducer, PartialPathProducer } from './mineflayer-specific/pathProducers' import { Block, HandlerOpts, ResetReason } from './types' import { Task } from '@nxg-org/mineflayer-util-plugin' @@ -113,9 +112,6 @@ interface PerformOpts { errorOnAbort?: boolean } - - - /** * Eventually, I want all pathfinder logic entirely off thread. * @@ -240,7 +236,7 @@ export class ThePathfinder { } async interrupt (timeout = 1000, cancelCalculation = true, reasonStr?: ResetReason): Promise { - console.log('INTERRUPT CALLED') + console.log('INTERRUPT CALLED') if (this._currentProducer == null) return console.log('no producer') this.abortCalculation = cancelCalculation @@ -316,7 +312,7 @@ export class ThePathfinder { if (place.vec.equals(pos)) { switch (place.type) { case 'solid': - console.log('if true, we are ignoring', block.boundingBox === 'block') + console.log('if true, we are ignoring', block.boundingBox === 'block') return block.boundingBox === 'block' case 'water': return BlockInfo.waters.has(block.type) @@ -485,7 +481,7 @@ export class ThePathfinder { if (result.status === 'success') { cleanup() this.bot.emit('pathGenerated', result) - console.log('locality %', (MovementHandler.count / MovementHandler.totCount) * 100) + console.log('locality %', (MovementHandler.count / MovementHandler.totCount) * 100) MovementHandler.count = 0 MovementHandler.totCount = 0 yield { result, astarContext } @@ -494,7 +490,7 @@ export class ThePathfinder { if (this.abortCalculation) { cleanup() - result.status === 'canceled' + result.status = 'canceled' yield { result, astarContext } return { result, astarContext } } @@ -529,7 +525,7 @@ export class ThePathfinder { * @param {goals.Goal | null} goal */ async goto (goal: goals.Goal, performOpts: PerformOpts = {}): Promise { - console.log('GOTO CALLED') + console.log('GOTO CALLED') if (goal == null) { await this.cancel() await this.executeTask.promise @@ -538,7 +534,7 @@ export class ThePathfinder { } if (!this.executeTask.done) { - console.log('cancelling others') + console.log('cancelling others') this.wantedGoal = goal await this.cancel() await this.executeTask.promise @@ -567,7 +563,7 @@ export class ThePathfinder { void this.cancel() }, forAll: () => { - console.log('cleaned up') + console.log('cleaned up') resolve() } }) @@ -576,14 +572,13 @@ export class ThePathfinder { } do { - let madeIt = false; + let madeIt = false do { setupWait() - console.log('reset I believe', doForever) + console.log('reset I believe', doForever) let task: Promise | null = null let res1 = null - for await (const res of this.getPathTo(goal)) { if (res.result.status !== 'success') { @@ -605,11 +600,10 @@ export class ThePathfinder { } if (task === null) { // technically, perform should keep track of the current index. So this *should* be fine. - task = this.perform(res1, goal) - task.then(() => { + task = this.perform(res1, goal).then(() => { task = null res1 = null - console.log('cleared task!') + console.log('cleared task!') }) } } @@ -636,7 +630,7 @@ export class ThePathfinder { } if (this.resetReason == null) { - console.log('finished!', this.bot.entity.position, this.bot.listeners('entityMoved'), this.bot.listeners('entityGone')) + console.log('finished!', this.bot.entity.position, this.bot.listeners('entityMoved'), this.bot.listeners('entityGone')) await this.cleanupBot() manualCleanup() setupWait() @@ -644,7 +638,7 @@ export class ThePathfinder { break } - console.log('resetting!', this.resetReason, this.abortCalculation, this.userAborted) + console.log('resetting!', this.resetReason, this.abortCalculation, this.userAborted) await this.cleanupBot() manualCleanup() } @@ -699,7 +693,7 @@ export class ThePathfinder { async perform (path: Path, goal: goals.Goal, entry = 0): Promise { if (entry > 10) throw new Error('Too many failures, exiting performing.') - console.log('ENTER PERFORM') + console.log('ENTER PERFORM') let currentIndex = 0 const movementHandler = path.context.movementProvider as MovementHandler const movements = movementHandler.getMovements() @@ -725,14 +719,14 @@ export class ThePathfinder { // if the movement has already been completed (another movement has already completed it), skip it. if (executor.isAlreadyCompleted(move, tickCount, goal)) { - console.log('skipping', move.moveType.constructor.name, 'at index', currentIndex + 1, 'of', path.path.length) + console.log('skipping', move.moveType.constructor.name, 'at index', currentIndex + 1, 'of', path.path.length) currentIndex++ continue } - console.log('performing', move.moveType.constructor.name, 'at index', currentIndex + 1, 'of', path.path.length) - console.log( + console.log('performing', move.moveType.constructor.name, 'at index', currentIndex + 1, 'of', path.path.length) + console.log( 'toPlace', move.toPlace.map((p) => p.vec), 'toBreak', @@ -767,7 +761,7 @@ export class ThePathfinder { } currentIndex += adding as number - console.log('done with move', move.exitPos, this.bot.entity.position, this.bot.entity.position.distanceTo(move.exitPos)) + console.log('done with move', move.exitPos, this.bot.entity.position, this.bot.entity.position.distanceTo(move.exitPos)) } catch (err) { // immediately exit since we want to abort the entire path. if (err instanceof AbortError) { @@ -780,7 +774,7 @@ export class ThePathfinder { // await this.cleanupBot() break } else if (err instanceof CancelError) { - console.log('canceled') + console.log('canceled') // await this.cleanupBot() // allow recovery if movement intentionall canceled. // await this.recovery(move, path, goal, entry) @@ -790,7 +784,7 @@ export class ThePathfinder { } await this.cleanupBot() - console.log('FINISHED PERFORM') + console.log('FINISHED PERFORM') } // TODO: implement recovery for any movement and goal. @@ -876,7 +870,7 @@ export class ThePathfinder { // this.bot.chat(this.world.getCacheSize()) this.world.cleanup?.() - console.log('CLEANUP CALLED') + console.log('CLEANUP CALLED') if (this.userAborted) this.bot.emit('goalAborted', goal) else this.bot.emit('goalFinished', goal) diff --git a/src/abstract/algorithms/astar.ts b/src/abstract/algorithms/astar.ts index 651b5b0..d0a69b5 100644 --- a/src/abstract/algorithms/astar.ts +++ b/src/abstract/algorithms/astar.ts @@ -70,7 +70,7 @@ export class AStar implements Algorithm // for debugging. private lastAmt: number = 0 makeResult (status: PathStatus, node: PathNode): Path> { - console.log( + console.log( status, // this.goal, performance.now() - this.startTime, diff --git a/src/mineflayer-specific/exceptions.ts b/src/mineflayer-specific/exceptions.ts index db2e97d..8fef232 100644 --- a/src/mineflayer-specific/exceptions.ts +++ b/src/mineflayer-specific/exceptions.ts @@ -2,21 +2,21 @@ import { ResetReason } from '../types' export class CancelError extends Error { constructor (...args: any[]) { - console.log('CancelError', args) + console.log('CancelError', args) super('Movement canceled: ' + args.join(' ')) } } export class AbortError extends Error { constructor (...args: any[]) { - console.log('AbortError', args) + console.log('AbortError', args) super('Movement aborted: ' + args.join(' ')) } } export class ResetError extends Error { constructor (public readonly reason: ResetReason, ...args: any[]) { - console.log('ResetError', reason, args) + console.log('ResetError', reason, args) super('Movement timed out: ' + args.join(' ')) } } diff --git a/src/mineflayer-specific/movements/interactionUtils.ts b/src/mineflayer-specific/movements/interactionUtils.ts index 732334d..6abe6e8 100644 --- a/src/mineflayer-specific/movements/interactionUtils.ts +++ b/src/mineflayer-specific/movements/interactionUtils.ts @@ -86,7 +86,7 @@ export abstract class InteractHandler { (this as any).move = move } - abstract needToPerform(bot: Bot): boolean; + abstract needToPerform (bot: Bot): boolean abstract getItem (bot: Bot, block?: Block): Item | null abstract perform (bot: Bot, item: Item | null, opts?: InteractOpts): Promise @@ -172,7 +172,6 @@ export abstract class InteractHandler { } export class PlaceHandler extends InteractHandler { - static reach = 4 private _placeTask?: Promise @@ -251,12 +250,11 @@ export class PlaceHandler extends InteractHandler { } } - needToPerform(bot: Bot): boolean { + needToPerform (bot: Bot): boolean { // check if block at position is already what we want it to be const blockInfo = bot.pathfinder.world.getBlockInfo(this.vec) if (blockInfo.isInvalid) return true - switch (this.type) { case 'water': { return !(blockInfo.liquid && BlockInfo.waters.has(blockInfo.type)) @@ -269,7 +267,7 @@ export class PlaceHandler extends InteractHandler { } } - return true; + return true } async performInfo (bot: Bot, ticks = 15, scale = 0.5): Promise { @@ -460,19 +458,17 @@ export class PlaceHandler extends InteractHandler { await bot.lookAt(rayRes.intersect, this.settings.forceLook) } - // console.log(i, works.ticks, works.tickAllowance, works.shiftTick, rayRes.intersect, this.faceToVec(rayRes.face)); // console.log(bot.entity.position, bot.entity.velocity); const invalidPlacement = botBB.intersects(posBl) if (invalidPlacement) { - console.log("invalid placement", bot.entity.position, invalidPlacement, botBB, posBl); + console.log('invalid placement', bot.entity.position, invalidPlacement, botBB, posBl) // console.log(botBB, posBl); await bot.lookAt(rayRes.intersect, this.settings.forceLook) throw new CancelError('Invalid placement') } - let finished = false let sneaking = false const direction = this.faceToVec(rayRes.face) @@ -519,7 +515,7 @@ export class PlaceHandler extends InteractHandler { this._done = true this.performing = false delete this._placeTask - console.log('done in ', performance.now() - start, 'ms') + console.log('done in ', performance.now() - start, 'ms') } async abort (bot: Bot): Promise { @@ -548,7 +544,6 @@ export class PlaceHandler extends InteractHandler { } export class BreakHandler extends InteractHandler { - static reach = 4 private _breakTask?: Promise @@ -581,7 +576,7 @@ export class BreakHandler extends InteractHandler { } } - needToPerform(bot: Bot): boolean { + needToPerform (bot: Bot): boolean { // check if block at position is already what we want it to be const blockInfo = bot.pathfinder.world.getBlockInfo(this.vec) @@ -590,9 +585,7 @@ export class BreakHandler extends InteractHandler { if (blockInfo.block?.boundingBox === 'empty' && !BlockInfo.liquids.has(blockInfo.type)) return false - return true; - - + return true } async performInfo (bot: Bot, ticks = 15): Promise { diff --git a/src/mineflayer-specific/movements/movementExecutor.ts b/src/mineflayer-specific/movements/movementExecutor.ts index 3dafec4..7cf1866 100644 --- a/src/mineflayer-specific/movements/movementExecutor.ts +++ b/src/mineflayer-specific/movements/movementExecutor.ts @@ -136,11 +136,10 @@ export abstract class MovementExecutor extends Movement { if (this.aborted) throw new AbortError('Movement aborted.') } - /** * TODO: potentially buggy code. Check. */ - public async perform(thisMove: Move, currentIndex: number, path: Move[]): Promise { + public async perform (thisMove: Move, currentIndex: number, path: Move[]): Promise { this.currentMove = thisMove if (this.aborted) throw new AbortError('Movement aborted.') if (this.resetReason != null) throw this.resetReason // new ResetError('Movement is resetting.') @@ -149,7 +148,7 @@ export abstract class MovementExecutor extends Movement { let result: boolean | number = false await new Promise((resolve, reject) => { - const listener = async () => { + const listener = async (): Promise => { if (this.aborted) { reject(new AbortError('Movement aborted.')) } @@ -159,18 +158,18 @@ export abstract class MovementExecutor extends Movement { if (result === false) { result = await this._performPerTick(thisMove, tickCount, currentIndex, path) - } + } - if ((result as boolean) === true) { + if (result as boolean) { this.bot.off('physicsTick', listener) resolve() } } - this.bot.on('physicsTick', listener); + this.bot.on('physicsTick', listener) }) let tickCount = 0 - + while (result === false) { result = await this._performPerTick(thisMove, tickCount, currentIndex, path) tickCount++ @@ -428,7 +427,7 @@ export abstract class MovementExecutor extends Movement { async interactNeeded (ticks = 1): Promise { for (const breakTarget of this.currentMove.toBreak) { if (breakTarget !== this._cI && !breakTarget.done) { - if (!breakTarget.needToPerform(this.bot)) continue; + if (!breakTarget.needToPerform(this.bot)) continue const res = await breakTarget.performInfo(this.bot, ticks) // console.log("break", res, res.raycasts.length > 0); if (res.ticks < Infinity) return breakTarget @@ -437,7 +436,7 @@ export abstract class MovementExecutor extends Movement { for (const place of this.currentMove.toPlace) { if (place !== this._cI && !place.done) { - if (!place.needToPerform(this.bot)) continue; + if (!place.needToPerform(this.bot)) continue const res = await place.performInfo(this.bot, ticks) // console.log("place", res, res.raycasts.length > 0); if (res.ticks < Infinity) return place diff --git a/src/mineflayer-specific/movements/movementExecutors.ts b/src/mineflayer-specific/movements/movementExecutors.ts index b8e5b17..5fdfb24 100644 --- a/src/mineflayer-specific/movements/movementExecutors.ts +++ b/src/mineflayer-specific/movements/movementExecutors.ts @@ -78,7 +78,7 @@ export class NewForwardExecutor extends MovementExecutor { } async performInit (thisMove: Move, currentIndex: number, path: Move[]): Promise { - console.log('ForwardMove', thisMove.exitPos, thisMove.toPlace.length, thisMove.toBreak.length) + console.log('ForwardMove', thisMove.exitPos, thisMove.toPlace.length, thisMove.toBreak.length) this.bot.clearControlStates() @@ -88,7 +88,7 @@ export class NewForwardExecutor extends MovementExecutor { await this.postInitAlignToPath(thisMove) } else { const offset = this.bot.entity.position.minus(thisMove.exitPos).plus(this.bot.entity.position) - console.log('here!', thisMove.exitPos, this.bot.entity.position, offset) + console.log('here!', thisMove.exitPos, this.bot.entity.position, offset) await this.postInitAlignToPath(thisMove, { lookAt: offset }) } } @@ -163,7 +163,7 @@ export class NewForwardExecutor extends MovementExecutor { } else if (this.cI == null) { const test = await this.interactNeeded(5) if (test != null) { - console.log('performing interaction') + console.log('performing interaction') void this.performInteraction(test) return false } @@ -178,7 +178,7 @@ export class NewForwardExecutor extends MovementExecutor { this.canJump(thisMove, currentIndex, path)) || this.bot.entity.position.y < Math.round(thisMove.entryPos.y) - 1 ) { - console.log(this.bot.entity.position, thisMove.entryPos) + console.log(this.bot.entity.position, thisMove.entryPos) throw new CancelError('ForwardMove: not on ground') } @@ -212,7 +212,7 @@ export class ForwardExecutor extends MovementExecutor { const placementVecs = this.toPlace().map((p) => AABB.fromBlock(p.vec)) const near = placementVecs.some((p) => p.distanceToVec(eyePos) < PlaceHandler.reach + 2) - console.log( + console.log( placementVecs.map((p) => p.distanceToVec(eyePos)), near, this.currentMove?.toPlace.length === 0 && !near @@ -329,7 +329,7 @@ export class ForwardExecutor extends MovementExecutor { // else this.bot.setControlState("sprint", true); } else { const offset = this.bot.entity.position.minus(thisMove.exitPos).plus(this.bot.entity.position) - console.log('here!', thisMove.exitPos, this.bot.entity.position, offset) + console.log('here!', thisMove.exitPos, this.bot.entity.position, offset) // void this.lookAt(offset); await this.postInitAlignToPath(thisMove, { lookAt: offset, sprint: true }) // this.bot.setControlState('forward', false) @@ -581,16 +581,16 @@ export class ForwardJumpExecutor extends MovementExecutor { // this.bot.setControlState("sprint", false); let info = await thisMove.toPlace[0].performInfo(this.bot, 0) if (info.raycasts.length === 0) { - console.log('info') + console.log('info') void this.postInitAlignToPath(thisMove, { lookAt: thisMove.entryPos }) await this.performInteraction(thisMove.toPlace[0]) } else { - console.log('no info') + console.log('no info') // this.bot.setControlState("forward", false); await this.performInteraction(thisMove.toPlace[0], { info }) } - console.log('did first place!') + console.log('did first place!') this.bot.setControlState('jump', true) await this.postInitAlignToPath(thisMove, { lookAt: thisMove.entryPos }) @@ -621,7 +621,7 @@ export class ForwardJumpExecutor extends MovementExecutor { } async performInit (thisMove: Move, currentIndex: number, path: Move[]): Promise { - console.log('performing jump movement!') + console.log('performing jump movement!') this.flag = false this.bot.clearControlStates() @@ -645,7 +645,7 @@ export class ForwardJumpExecutor extends MovementExecutor { this.jumpInfo = this.shitter.findJumpPoint(thisMove.exitPos) - console.log('jump info', this.jumpInfo) + console.log('jump info', this.jumpInfo) if (this.jumpInfo === null) { debug(this.bot, 'no jump info') this.bot.setControlState('forward', true) @@ -935,7 +935,7 @@ export class StraightUpExecutor extends MovementExecutor { let bb1Good let bb2Good if ((this.bot.entity as any).isInWater as boolean) { - console.log('in water') + console.log('in water') const bb1bl = this.getBlockInfo(thisMove.entryPos, 0, 0, 0) bb1 = [AABB.fromBlockPos(thisMove.entryPos)] bb1Good = bb1bl.liquid @@ -955,24 +955,24 @@ export class StraightUpExecutor extends MovementExecutor { bb2Good = bb2bl.physical } - // console.log( - // bb1Good, - // bb2Good, - // Math.max(...bb1.map((b) => b.maxY)), - // Math.max(...bb2.map((b) => b.maxY)), - // bb0, - // bb1, - // bb2, - // bb1.some((b) => b.collides(bb0)), - // bb2.some((b) => b.collides(bb0)), - // thisMove.exitPos - // ) + // console.log( + // bb1Good, + // bb2Good, + // Math.max(...bb1.map((b) => b.maxY)), + // Math.max(...bb2.map((b) => b.maxY)), + // bb0, + // bb1, + // bb2, + // bb1.some((b) => b.collides(bb0)), + // bb2.some((b) => b.collides(bb0)), + // thisMove.exitPos + // ) if ((bb1.some((b) => b.collides(bb0)) && bb1Good) || (bb2.some((b) => b.collides(bb0)) && bb2Good)) { - console.log('yay, counted!', similarDirection, this.bot.entity.position.xzDistanceTo(target)) + console.log('yay, counted!', similarDirection, this.bot.entity.position.xzDistanceTo(target)) if (similarDirection) return true else if (this.bot.entity.position.xzDistanceTo(target) < 0.2) return true // this.isLookingAtYaw(target) - console.log('we are here!') + console.log('we are here!') } return false @@ -1090,7 +1090,7 @@ export class ParkourForwardExecutor extends MovementExecutor { this.bot.on('physicsTick', listener) }) - console.log('cheat', early, counter) + console.log('cheat', early, counter) return counter } @@ -1124,7 +1124,7 @@ export class ParkourForwardExecutor extends MovementExecutor { const test0 = this.shitterTwo.simForwardMove(target) const test1 = this.shitterTwo.simJumpFromEdge(bbs, target) - console.log('align', test0, test1, test2, this.bot.entity.onGround) + console.log('align', test0, test1, test2, this.bot.entity.onGround) // if (!this.bot.entity.onGround) return false; if (this.bot.entity.onGround) { @@ -1167,12 +1167,12 @@ export class ParkourForwardExecutor extends MovementExecutor { const goingToFall = leavingBlockLevel(this.bot, this.world, this.stepAmt, ctx) - console.log(goingToFall, this.bot.entity.position) + console.log(goingToFall, this.bot.entity.position) if (!goingToFall && this.backUpTarget != null && bb.containsVec(this.backUpTarget)) { this.reachedBackup = true const dist = this.bot.entity.position.xzDistanceTo(this.backUpTarget) - console.log('here1', this.bot.entity.position, this.backUpTarget, dist) + console.log('here1', this.bot.entity.position, this.backUpTarget, dist) await this.lookAtPathPos(targetEyeVec) this.bot.setControlState('forward', true) @@ -1184,7 +1184,7 @@ export class ParkourForwardExecutor extends MovementExecutor { this.backUpTarget = this.shitterTwo.findBackupVertex(bbs, target) // // const dist = this.bot.entity.position.xzDistanceTo(this.backUpTarget) - console.log('here2', this.backUpTarget, this.bot.entity.position) + console.log('here2', this.backUpTarget, this.bot.entity.position) // behold, our first cheat. @@ -1193,13 +1193,13 @@ export class ParkourForwardExecutor extends MovementExecutor { const early = await this.cheatCode(2) const currentY = this.bot.entity.position.y - console.log('new pos', this.bot.entity.position, early) + console.log('new pos', this.bot.entity.position, early) this.bot.entity.onGround = true this.bot.entity.position.y = oldY const res = this.shitterTwo.simForwardMove(target) - console.log('res', res, early) + console.log('res', res, early) if (res) { this.bot.setControlState('forward', true) this.bot.setControlState('sprint', true) @@ -1216,17 +1216,17 @@ export class ParkourForwardExecutor extends MovementExecutor { } else if (goingToFall && this.backUpTarget != null && this.reachedBackup) { const oldY = this.bot.entity.position.y - console.log('here5', this.bot.entity.position) + console.log('here5', this.bot.entity.position) const early = await this.cheatCode() const currentY = this.bot.entity.position.y - console.log('new pos', this.bot.entity.position, early) + console.log('new pos', this.bot.entity.position, early) printBotControls(this.bot) this.bot.entity.onGround = true this.bot.entity.position.y = oldY const res = this.shitterTwo.simForwardMove(target) - console.log('res', res, early) + console.log('res', res, early) if (res) { this.bot.setControlState('forward', true) this.bot.setControlState('sprint', true) @@ -1247,7 +1247,7 @@ export class ParkourForwardExecutor extends MovementExecutor { } } else if (!this.reachedBackup && this.backUpTarget != null) { const dist = this.bot.entity.position.xzDistanceTo(this.backUpTarget) - console.log('here3', this.bot.entity.position, this.backUpTarget) + console.log('here3', this.bot.entity.position, this.backUpTarget) void this.lookAtPathPos(this.backUpTarget) this.bot.setControlState('forward', true) @@ -1261,7 +1261,7 @@ export class ParkourForwardExecutor extends MovementExecutor { // // throw new CancelError('ParkourForward: Not making this jump.') // } else { this.bot.clearControlStates() - console.log('here4', this.bot.entity.position, this.backUpTarget) + console.log('here4', this.bot.entity.position, this.backUpTarget) void this.lookAtPathPos(targetEyeVec) this.bot.setControlState('forward', true) @@ -1291,7 +1291,7 @@ export class ParkourForwardExecutor extends MovementExecutor { // TODO: Fix this. Good thing I've done this before. >:) performPerTick (thisMove: Move, tickCount: number, currentIndex: number, path: Move[]): boolean | Promise { - console.log('in per tick', tickCount) + console.log('in per tick', tickCount) // printBotControls(this.bot) const targetEyeVec = this.shitterTwo.findGoalVertex(AABB.fromBlockPos(thisMove.exitPos)) @@ -1299,7 +1299,7 @@ export class ParkourForwardExecutor extends MovementExecutor { // this.bot.clearControlStates() if (this.executing) { this.bot.setControlState('jump', false) - console.log(this.bot.entity.position) + console.log(this.bot.entity.position) void this.postInitAlignToPath(thisMove, { lookAtYaw: targetEyeVec }) return this.isComplete(thisMove) } diff --git a/src/mineflayer-specific/movements/movementUtils.ts b/src/mineflayer-specific/movements/movementUtils.ts index 49d6c84..671454b 100644 --- a/src/mineflayer-specific/movements/movementUtils.ts +++ b/src/mineflayer-specific/movements/movementUtils.ts @@ -93,7 +93,7 @@ export function leavingBlockLevel (bot: Bot, world: World, ticks = 1, ectx?: EPh const bad = ctx.state.pos.y < bot.entity.position.y -console.trace(minY, minY1, bot.entity.position, ctx.state.pos) + console.trace(minY, minY1, bot.entity.position, ctx.state.pos) if ((minY === Infinity || minY1 === Infinity) || bad) { return true } @@ -253,7 +253,7 @@ export class JumpCalculator { (state, ticks) => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const boundary = sj ? ft + st : ft - const xzVel = state.vel.offset(0, -state.vel.y, 0) + // const xzVel = state.vel.offset(0, -state.vel.y, 0) // console.log(ticks, firstTicks, secondTicks, backTicks) // console.log('checking goal', state.control.get('jump'), state.control.get('forward'), state.control.get('back'), state.control.get('sprint')) // console.log(state.onGround, state.isCollidedHorizontally, state.isCollidedVertically, state.pos) @@ -490,7 +490,7 @@ export class ParkourJumpHelper { const reached0 = JumpSim.getReachedAABB(goalBBs) const reached: SimulationGoal = (state, ticks) => state.onGround && reached0(state, ticks) - console.log('fall off edge init', orgPos) + console.log('fall off edge init', orgPos) const state = this.sim.simulateUntil( reached, () => {}, diff --git a/src/mineflayer-specific/movements/simulators/jumpSim.ts b/src/mineflayer-specific/movements/simulators/jumpSim.ts index 161241c..514b605 100644 --- a/src/mineflayer-specific/movements/simulators/jumpSim.ts +++ b/src/mineflayer-specific/movements/simulators/jumpSim.ts @@ -115,7 +115,7 @@ export class JumpSim extends BaseSimulator { let jump = false let changed = false - console.log('edge jump init', ctx.state.pos) + console.log('edge jump init', ctx.state.pos) return this.simulateUntil( JumpSim.getReachedAABB(goalBlock), JumpSim.getCleanupPosition(goalCorner), diff --git a/src/mineflayer-specific/pathProducers/continuousPathProducer.ts b/src/mineflayer-specific/pathProducers/continuousPathProducer.ts index aafb9f4..def7024 100644 --- a/src/mineflayer-specific/pathProducers/continuousPathProducer.ts +++ b/src/mineflayer-specific/pathProducers/continuousPathProducer.ts @@ -46,7 +46,7 @@ export class ContinuousPathProducer implements PathProducer { const result = this.astarContext.compute() this._currentPath = result.path - console.log('advancing!') + console.log('advancing!') if (global.gc != null && ++this.lastGc % this.gcInterval === 0) { // const starttime = performance.now() diff --git a/src/mineflayer-specific/pathProducers/partialPathProducer.ts b/src/mineflayer-specific/pathProducers/partialPathProducer.ts index 9648b8c..957c935 100644 --- a/src/mineflayer-specific/pathProducers/partialPathProducer.ts +++ b/src/mineflayer-specific/pathProducers/partialPathProducer.ts @@ -136,17 +136,17 @@ export class PartialPathProducer implements PathProducer { console.info('Partial Path cost increased by', cost, 'to', this.latestCost, 'total', this.latestMove?.vec) const time1 = performance.now() - this.lastStartTime - console.log('\nthis iter:', time1) - console.log('itered considered nodes', nodecount, 'nodes/s', (nodecount / time1) * 1000) - console.log('itered seen size', seensize, 'nodes/s', (seensize / time1) * 1000) - console.log('itered move considered', movecount, 'nodes/s', (movecount / time1) * 1000) + console.log('\nthis iter:', time1) + console.log('itered considered nodes', nodecount, 'nodes/s', (nodecount / time1) * 1000) + console.log('itered seen size', seensize, 'nodes/s', (seensize / time1) * 1000) + console.log('itered move considered', movecount, 'nodes/s', (movecount / time1) * 1000) this.lastStartTime = performance.now() const time = performance.now() - this.startTime - console.log('\ntotal', time, 'ms') - console.log('total considered nodes', this.consideredNodeCount, time, (this.consideredNodeCount / time) * 1000, 'nodes/s') - console.log('total seen size', this.latestClosedNodeCount, time, (this.latestClosedNodeCount / time) * 1000, 'nodes/s') - console.log('total move considered', this.latestMoveCount, time, (this.latestMoveCount / time) * 1000, 'nodes/s') + console.log('\ntotal', time, 'ms') + console.log('total considered nodes', this.consideredNodeCount, time, (this.consideredNodeCount / time) * 1000, 'nodes/s') + console.log('total seen size', this.latestClosedNodeCount, time, (this.latestClosedNodeCount / time) * 1000, 'nodes/s') + console.log('total move considered', this.latestMoveCount, time, (this.latestMoveCount / time) * 1000, 'nodes/s') } // console.log(result.path.length, 'found path length', this.lastPath.length, 'total length', this.lastPath.map(p => p.entryPos.toString()), this.lastPath[this.lastPath.length - 1].entryPos) diff --git a/src/mineflayer-specific/world/cacheWorld.ts b/src/mineflayer-specific/world/cacheWorld.ts index b30daa5..8f3a15c 100644 --- a/src/mineflayer-specific/world/cacheWorld.ts +++ b/src/mineflayer-specific/world/cacheWorld.ts @@ -9,7 +9,7 @@ import { AABB } from '@nxg-org/mineflayer-util-plugin' import { RayType } from '../movements/interactionUtils' import pBlock from 'prismarine-block' -import { Movement, MovementOptions } from '../movements' +import { Movement } from '../movements' export class BlockInfo { static initialized = false @@ -282,7 +282,7 @@ export class BlockInfo { } } - public loadAdditionalInfo (movement: Movement) { + public loadAdditionalInfo (movement: Movement): void { if (this.additionalLoaded) return this.additionalLoaded = true if (movement.settings.dontCreateFlow || movement.settings.dontMineUnderFallingBlock) { @@ -382,10 +382,10 @@ export class CacheSyncWorld implements WorldType { updateAgeOnGet: true, dispose: (key, value, reason) => { if (reason === 'set') { - console.log(`${count++} disposed ${key.position.toString()} ${reason}`, this.blockInfos.size) + console.log(`${count++} disposed ${key.position.toString()} ${reason}`, this.blockInfos.size) this.blockInfos.clear() } else if (reason === 'evict') { - console.log('resetting', this.blockInfos.size) + console.log('resetting', this.blockInfos.size) this.blockInfos.clear() this.blockInfos = this.makeLRUCache(size) } diff --git a/src/types.ts b/src/types.ts index 183f379..9faf311 100644 --- a/src/types.ts +++ b/src/types.ts @@ -17,7 +17,6 @@ export interface HandlerOpts { pathfinderSettings?: PathfinderOptions } - export type PathStatus = 'noPath' | 'timeout' | 'partial' | 'success' | 'partialSuccess' | 'canceled' export type ResetReason = 'blockUpdate' | 'chunkLoad' | 'goalUpdated' diff --git a/src/utils.ts b/src/utils.ts index 5677489..42d7ab3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,20 +3,20 @@ import { Vec3 } from 'vec3' import { BlockInfo } from './mineflayer-specific/world/cacheWorld' export function printBotControls (bot: Bot): void { -console.trace('forward', bot.getControlState('forward')) -console.trace('back', bot.getControlState('back')) -console.trace('left', bot.getControlState('left')) -console.trace('right', bot.getControlState('right')) -console.trace('jump', bot.getControlState('jump')) -console.trace('sprint', bot.getControlState('sprint')) -console.trace('sneak', bot.getControlState('sneak')) + console.trace('forward', bot.getControlState('forward')) + console.trace('back', bot.getControlState('back')) + console.trace('left', bot.getControlState('left')) + console.trace('right', bot.getControlState('right')) + console.trace('jump', bot.getControlState('jump')) + console.trace('sprint', bot.getControlState('sprint')) + console.trace('sneak', bot.getControlState('sneak')) } export const debug = (bot: Bot | undefined, ...args: any[]): void => { if (bot != null) { bot.chat(args.join(' ')) } -console.trace(...args) + console.trace(...args) } export const getScaffoldCount = (bot: Bot): number => {