PrismarineJS / mineflayer-pathfinder

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

Bot randomly fails to place blocks when scaffolding #296

Open DEVTomatoCake opened 1 year ago

DEVTomatoCake commented 1 year ago

scafolding (for search)

When a bot is bridging to a goal and has to place blocks (e.g. when traveling over void) it sometimes randomly fails to place a block but continues to move, which often causes it to fall down (and place blocks mid-air, #181).

I was able to reduce the occurences of this issue by removing https://github.com/PrismarineJS/mineflayer-pathfinder/blob/56a02b9af715029f884cd392aa7f0836e0284c03/index.js#L500 It seems like nothing is really affected by this change except the bot is bridging slower, which is imo a fair trade off for it to not fall. Is there another recommended solution for this issue? Ideal solution would be to fully pause (or find another way) until the block was placed successfully, but it seems like that's not working currently.

IceTank commented 1 year ago

That line is suppose to make it fail less. The issue I see with removing this line is that the bot might in some cases not stop crouching.

DEVTomatoCake commented 1 year ago

The bot always unsneaked for me when it had to jump - but as I said, another solution is probably better.

Muph0 commented 1 year ago

The bot has also big problems when scaffolding vertically.

The bot triggers a jump here while checking if it is in correct height. https://github.com/PrismarineJS/mineflayer-pathfinder/blob/56a02b9af715029f884cd392aa7f0836e0284c03/index.js#L486-L489

Then it gets to placing the block like this: https://github.com/PrismarineJS/mineflayer-pathfinder/blob/56a02b9af715029f884cd392aa7f0836e0284c03/index.js#L490-L497

Two big problems here:

That is because if we look at the implementation of the block placemet, couple of calls down the stack (bot.placeBlock() --> bot._placeBlockWithOptions() --> bot._genericPlace()) we can see this, just before the packet is sent:

plugins/generic_place.js

if (options.forceLook !== 'ignore') {
  await bot.lookAt(referenceBlock.position.offset(dx, dy, dz), options.forceLook)
}

I'm guessing that the lookAt is playing some head movement animation, so we're waiting for this before the packet is sent. By this time, it would be a sheer luck to have the bot in a correct position for the block placemet.

TLDR

The bot stands in its way when placing a block because it is waiting for too long before sending the place packet. It falls back down and obstructs the block placement.

IceTank commented 1 year ago

Yes, equip can take time to select the item, but only when the item is not already in any of the hotbar slots. Placeblock should also send the packet in the same tick if the force look option is trueish. Look will set the bot looking direction and return the promise in the same tick if the force look option is true. Maybe a better approach would be to only start jumping if the item has been equipped. But someone would have to test how well that works.