mineflayer
mineflayer copied to clipboard
Issues with bot.dig
- [ ] 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