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

Bot walks very slow & doesn't mine #54

Open
nabilhayek opened this issue Mar 25, 2021 · 2 comments
Open

Bot walks very slow & doesn't mine #54

nabilhayek opened this issue Mar 25, 2021 · 2 comments

Comments

@nabilhayek
Copy link

nabilhayek commented Mar 25, 2021

The bot is suppose to find a diamond block and mine it. The code was copied and modified a bit from examples/collector.js to ensure that it wasn't only my code that didn't work.

Code:

const mineflayer = require('mineflayer');
const collectBlock = require('mineflayer-collectblock').plugin;

const bot = mineflayer.createBot({
  host: 'minetime.com',
  username: 'farucci',
  password: 'censored',
});

bot.loadPlugin(collectBlock);

let mcData;
bot.once('spawn', () => {
  mcData = require('minecraft-data')(bot.version);

  //Pull up compass menu
  bot.activateItem();
});

bot.on('windowOpen', async (e) => {
  //Select Prison server
  await bot.clickWindow(1, 1, 0, () => {});
});

bot.on('chat', (username, message) => {
  if (message !== 'me] start') return;

  let count = 1;
  let type = 'diamond_block';

  const blockType = mcData.blocksByName[type];
  if (!blockType) {
    console.log(`"I don't know any blocks named ${type}.`);
    return;
  }

  const blocks = bot.findBlocks({
    matching: blockType.id,
    maxDistance: 64,
    count: count,
  });

  if (blocks.length === 0) {
    console.log("I don't see that block nearby.");
    return;
  }

  const targets = [];
  for (let i = 0; i < Math.min(blocks.length, count); i++) {
    targets.push(bot.blockAt(blocks[i]));
  }

  console.log(`Found ${targets.length} ${type}(s)`);

  bot.collectBlock.collect(targets, (err) => {
    if (err) {
      // An error occurred, report it.
      console.log(err.message);
      console.log(err);
    } else {
      // All blocks have been collected.
      console.log('Done');
    }
  });
});

Video demonstration:

https://youtu.be/3ZULtC2P-Sk

It looks like the bot releases mine button too early

@TheDudeFromCI
Copy link
Member

The slow walking and the mining issues are two separate bugs. The slow walking is likely caused by how the pathfinder plugin is set up. Make sure you're using the latest version and not modifying it to cause that effect.

For the mining issue, this is a known bug that is sometimes triggered when the block breaks before the bot finishes mining it, and the bot gets stuck in a loop trying to mine the air block but cannot.

@pyth0nic
Copy link

pyth0nic commented Jan 3, 2022

The issue seems to be because the bot's world isn't updated with the current state during collectblock. Try doing a collectblock on a single target, when successful, call your collectBlock again with the next target, poping from the list of targets and carry on recursing through until targets is finished.

Haven't had any more sticking issues after the above. (ensure you check if the target to collect still exists)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants