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

Issues with bot.dig #3434

Open
1 task
Nick403 opened this issue Aug 4, 2024 · 0 comments
Open
1 task

Issues with bot.dig #3434

Nick403 opened this issue Aug 4, 2024 · 0 comments
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f

Comments

@Nick403
Copy link

Nick403 commented Aug 4, 2024

  • The FAQ doesn't contain a resolution to my issue

Versions

  • mineflayer: 1.20.2
  • server: vanilla
  • node: v20.16.0

Detailed description of a problem

I tried to make an auto miner but each time when bot is looking at block it cancels the mining

What did you try yet?

Did you try any method from the API? yes
Did you try any example? Any error from those? yes, i tried but same

Your current code

async function mineOre(username, oreName) {
  if (!oreName) {
    bot.chat("Please specify the ore to mine");
    return;
  }
  console.log(bot.version)

  current_task = `Mining ${oreName} for ${username}`;
  bot.chat(`Started mining ${oreName}`);

  const findOreBlock = () => bot.findBlock({
    matching: mcData.blocksByName[oreName].id,
    maxDistance: 64
  });

  try {
    while (!stopMining) {
      const oreBlock = findOreBlock();
      if (oreBlock && bot.canDigBlock(oreBlock)) {
        await bot.pathfinder.setGoal(new GoalBlock(oreBlock.position.x, oreBlock.position.y, oreBlock.position.z));
        target = bot.lookAt(oreBlock.position.x, oreBlock.position.y+0.3, oreBlock.position.z)

        bot.targetDigBlock = oreBlock; // Set the target block
        await bot.dig(oreBlock, false);
        await bot.collectBlock.collect(oreBlock);
        bot.targetDigBlock = null; 
      } else {
        bot.chat(`Could not find any more ${oreName}`);
        break;
      }
    }
    oreMined(username);
  } catch (err) {
    if (err.message === 'Digging aborted') {
      bot.chat(`Mining ${oreName} was stopped.`);
    } else {
      bot.chat(`Error mining ${oreName}: ${err.message}`);
      console.error(`Error mining ${oreName}:`, err);
    }
    stopTask();
  }
}

Expected behavior

it goes to block and hits:

    if (err.message === 'Digging aborted') {
      bot.chat(`Mining ${oreName} was stopped.`);

I tried to comment it fro digger.js src, but bot does not update view angle for next block and gets stuck in infinite animation

@Nick403 Nick403 added possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f labels Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f
Projects
None yet
Development

No branches or pull requests

1 participant