PrismarineJS / mineflayer-pathfinder

Pathfinding plugin that gives bot the ability to go from A to B
MIT License
213 stars 68 forks source link

Dropping into water/using water bucket to negate fall damage #31

Open Garfield100 opened 4 years ago

Garfield100 commented 4 years ago

Currently the bot isn't able to drop into water, much less use a bucket to avoid fall damage. These would be nice features. I've somewhat successfully added an idea to my code but it fails for small bodies of water when falling from very high up as the bot seems to continue moving in the air and thus not fall on the predicted block. To fix this, I think it would be a good idea to prevent lateral movement when attempting to fall into water. This is what I have currently: (It's terrible but works as a proof of concept)

  getLandingBlock(node, dir) {
    let blockLand = this.getBlock(node, dir.x, -2, dir.z)
    for (let i = 0; i < 100; i++) {
      if (i < this.maxDropDown - 1) {
        if (blockLand.physical || !blockLand.safe) break
        blockLand = this.getBlock(node, dir.x, -2 - i, dir.z)
      }

      let possibleBlockLand = this.getBlock(node, dir.x, -2 - i, dir.z);
      if (possibleBlockLand.liquid && possibleBlockLand.safe) {
        blockLand = possibleBlockLand;
        break;
      }

    }
    return blockLand
  }

I also had to change the if (!blockLand.physical) return checks in getMoveDropDown and getMoveDown to allow liquids. Are they even necessary if getLandingBlock returns only correct blocks anyway?

I'd make a pull request but this is nowhere near good enough yet.

TheDudeFromCI commented 4 years ago

This is a planned feature after the modular pathfinding framework is ready.