From 6ff374739d8b19fb399c89e4126254c5d513dc59 Mon Sep 17 00:00:00 2001 From: GenerelSchwerz Date: Sun, 14 Apr 2024 02:42:56 -0400 Subject: [PATCH] better debug --- README.md | 115 ++++++++++++++++++++++++++++++++++++++++++++-- src/autoJumper.ts | 53 ++++++++++----------- 2 files changed, 137 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 82a7d97..12d8dd0 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,117 @@ # mineflayer-auto-jump + + +## Installation + +```bash + +npm install mineflayer-auto-jump + +``` + +## Usage + + + +```js + +const mineflayer = require('mineflayer') +const {loader: autoJump} = require('@nxg-org/mineflayer-auto-jump') + +const bot = mineflayer.createBot({ + host: 'localhost', + port: 25565, + username: 'player' +}) + +bot.loadPlugin(autoJump) + + +bot.autoJump.enable() // it will now auto jump! + +``` + +## API + +### `autoJump.enable()` + +Enable auto jump + +### `autoJump.disable()` + +Disable auto jump + +### `autoJump.shouldJump()` + +Returns if the bot should jump (if we do not jump right now, there will be an issue). + +### `autoJump.canJump()` + +Returns if the bot is allowed to jump (no jump *needed*, but no detriment to jumping right now). + +### `autoJump.jumpOnAllEdges: boolean` + +If the bot should jump on all edges. This is mainly used for descending slopes, combined with `maxBlockOffset`. + +### `autoJump.jumpIntoWater: boolean` + +If the bot should jump into water. Useful if you want to save time when falling into water instead of just falling off of a block. + +### `autoJump.maxBlockOffset: number` + +The maximum block offset for the bot to consider jumping. It works as `current Y` - `maxBlockOffset` as the threshold for jumping. + +### `autoJump.minimizeFallDmg: boolean` + +If the bot should minimize fall damage. Similar to maxBlockOffset set to 3 except also takes into account water falling (allows for a bit more leniency). + +### `autoJump.debug: boolean` + +If the bot should debug the jump checker. Your console will be spammed. Just report the information to me. + +## Events + +### `autoJump.on('shouldJump', () => {})` + +Emitted when the bot should jump. + + + + -### Note: jan 14th -I have no idea why I structured the code like this. It looks like shit. Why the hell did I split it up? :sadge: -I'll clean it up later. \ No newline at end of file diff --git a/src/autoJumper.ts b/src/autoJumper.ts index 658ff99..0234e20 100644 --- a/src/autoJumper.ts +++ b/src/autoJumper.ts @@ -18,6 +18,22 @@ export class JumpChecker extends BaseSimulator implements JumpCheckerOpts { super(new EntityPhysics(bot.registry)); } + public debugInfo() { + console.debug( + `[AUTOJUMP] DEBUG INFO:\n` + + `don't jump since can't clear: ${this.dontJumpSinceCantClear()}\n` + + `should jump from collision: ${this.shouldJumpFromCollision()}\n` + + `should jump to avoid danger: ${this.shouldJumpToAvoidDanger()}\n` + + `should jump into water: (jumpOnAllEdges=${this.jumpOnAllEdges}, jumpIntoWater=${this.jumpIntoWater}) ${ + !this.jumpOnAllEdges && this.jumpIntoWater ? this.shouldJumpIntoWater() : false + }\n` + + `should jump since next block empty and available block: ${this.shouldJumpSinceNextBlockEmptyAndAvailableBlock()}\n` + + `should jump since block edge (jumpOnAllEdges=${this.jumpOnAllEdges}): ${ + this.jumpOnAllEdges ? this.shouldJumpSinceBlockEdge() : false + }` + ); + } + public shouldJump() { if ( this.bot.getControlState("back") || @@ -26,20 +42,8 @@ export class JumpChecker extends BaseSimulator implements JumpCheckerOpts { this.bot.getControlState("right") // && this.bot.entity.onGround ) { if (this.debug) { - - console.log( - "bad:", - this.dontJumpSinceCantClear(), - "good:", - this.shouldJumpFromCollision(), - this.shouldJumpToAvoidDanger(), - !this.jumpOnAllEdges && this.jumpIntoWater ? this.shouldJumpIntoWater() : false, - this.shouldJumpSinceNextBlockEmptyAndAvailableBlock(), - this.jumpOnAllEdges ? this.shouldJumpSinceBlockEdge() : false - ); - tp(this.bot.entity.position, "pos"); - - + this.debugInfo(); + tp(this.bot.entity.position, "pos"); } if (this.dontJumpSinceCantClear()) { return false; @@ -58,16 +62,7 @@ export class JumpChecker extends BaseSimulator implements JumpCheckerOpts { public canJump() { if (this.debug) { - console.log( - "bad:", - this.dontJumpSinceCantClear(), - "good:", - this.shouldJumpFromCollision(), - this.shouldJumpToAvoidDanger(), - !this.jumpOnAllEdges && this.jumpIntoWater ? this.shouldJumpIntoWater() : false, - this.shouldJumpSinceNextBlockEmptyAndAvailableBlock(), - this.jumpOnAllEdges ? this.shouldJumpSinceBlockEdge() : false - ); + this.debugInfo(); tp(this.bot.entity.position, "pos"); } return !this.dontJumpSinceCantClear(); @@ -148,13 +143,15 @@ export class JumpChecker extends BaseSimulator implements JumpCheckerOpts { (state, ticks) => { return state.isCollidedHorizontally; }, - (state) => { flag = true }, + (state) => { + flag = true; + }, (state, ticks) => {}, ectx, this.bot.world, maxAge ); - return flag + return flag; } /** @@ -168,7 +165,7 @@ export class JumpChecker extends BaseSimulator implements JumpCheckerOpts { /** * If we fall, check: - * + * * - if we fall too far, don't jump. * - if we fall into water, don't jump (handled elsewhere) * - if we do jump, we'll end up on a good block (higher than if we didn't jump) @@ -239,7 +236,7 @@ export class JumpChecker extends BaseSimulator implements JumpCheckerOpts { /** * Jump if we're about to fall into lava. - * + * * This can be extended for other various dangers. (TODO) */ protected shouldJumpToAvoidDanger(): boolean {