Skip to content

Commit

Permalink
better debug
Browse files Browse the repository at this point in the history
  • Loading branch information
GenerelSchwerz committed Apr 14, 2024
1 parent 46fe70e commit 6ff3747
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 31 deletions.
115 changes: 112 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,117 @@
# mineflayer-auto-jump

<!-- Generate documentation -->

## Installation

```bash

npm install mineflayer-auto-jump

```

## Usage

<!-- refer to the source files in this project for reference -->

```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.



<!--
export interface JumpCheckerOpts {
jumpOnAllEdges: boolean;
jumpIntoWater: boolean;
maxBlockOffset: number;
minimizeFallDmg: boolean;
debug: boolean;
}
export const DefaultHandlerKeys: JumpCheckerOpts = {
jumpOnAllEdges: false,
jumpIntoWater: false,
maxBlockOffset: 0,
minimizeFallDmg: false,
debug: false
};
export interface AutoJumperOpts {
enabled: boolean;
}
export const DefaultKeys: AutoJumperOpts = {
enabled: false,
};
interface AutoJumperEvents {
shouldJump: () => void;
}
export type AutoJumperEmitter = StrictEventEmitter<EventEmitter, AutoJumperEvents>;
-->


### 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.
53 changes: 25 additions & 28 deletions src/autoJumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") ||
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6ff3747

Please sign in to comment.