PrismarineJS / mineflayer-collectblock

A simple utility plugin for Mineflayer that add a higher level API for collecting blocks.
MIT License
39 stars 25 forks source link

BUG: when collecting multipleblocks #101

Open 0xrushi opened 2 years ago

0xrushi commented 2 years ago

Sometimes the bot goes halfway on a tall block and gets stuck there because no path is left. Giving Timeout: Took to long to decide path to goal! and exiting the code.

image

A quick workaround to this to the README code is add a collectGrass() in catch.

// Load collect block
bot.loadPlugin(require('mineflayer-collectblock').plugin)

async function collectGrass() {
  // Find a nearby grass block
  const grass = bot.findBlock({
    matching: mcData.blocksByName.spruce_log.id,
    maxDistance: 64
  })

  if (grass) {
    // If we found one, collect it.
    try {
      await bot.collectBlock.collect(grass)
      collectGrass() // Collect another grass block
    } catch (err) {
      console.log(err) // Handle errors, if any
      collectGrass()
    }
  }
}

// On spawn, start collecting all nearby grass
bot.once('spawn', () => {
  mcData = require('minecraft-data')(bot.version)
  collectGrass()
})

But I think since collectBlock has an option to collect multiple blocks, the collectAll function here https://github.com/rushic24/mineflayer-collectblock/blob/08997f52464c219bb4ce9fd1c5eafa9f3af02482/src/CollectBlock.ts#L18 should handle that single error and continue mining other blocks in the list.