Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix collect blocks that require tools #132

Merged
merged 2 commits into from
Dec 17, 2023

Conversation

MaxRobinsonTheGreat
Copy link
Contributor

Currently the bot will not collect blocks that require tools (stone, obsidian, etc) even when it has the correct tools. This was because the canHarvest check was being given the equipped item object instead of the id. This has been fixed. I was using this to test:

const mineflayer = require("mineflayer")
const bot = mineflayer.createBot({
  host: 'localhost',
  username: 'Player',
})

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

// Listen for when a player says "collect [something]" in chat
bot.on('chat', async (username, message) => {
    const args = message.split(' ')
    if (args[0] !== 'collect') return
  
    // Get the correct block type
    const blockType = bot.registry.blocksByName[args[1]]
    if (!blockType) {
      bot.chat("I don't know any blocks with that name.")
      return
    }
  
    bot.chat('Collecting the nearest ' + blockType.name)
  
    // Try and find that block type in the world
    const block = bot.findBlock({
      matching: blockType.id,
      maxDistance: 64
    })
  
    if (!block) {
      bot.chat("I don't see that block nearby.")
      return
    }
  
    // Collect the block if we found one
    await bot.collectBlock.collect(block);
    bot.chat('Done.')
  })

To test, give the bot a pickaxe and ask it to collect stone.
I think this fixes #129

@SilkePilon
Copy link
Contributor

Looks good

@rom1504 rom1504 merged commit 5dbaed7 into PrismarineJS:master Dec 17, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

3 participants