mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-03-28 14:56:24 +01:00
commit
07ea071ac3
2 changed files with 60 additions and 0 deletions
|
@ -407,6 +407,14 @@ export const actionsList = [
|
|||
return `Converstaion with ${player_name} ended.`;
|
||||
}
|
||||
},
|
||||
{
|
||||
name: '!digDown',
|
||||
description: 'Digs down a specified distance.',
|
||||
params: {'distance': { type: 'int', description: 'Distance to dig down'}},
|
||||
perform: runAsAction(async (agent, distance) => {
|
||||
await skills.digDown(agent.bot, distance)
|
||||
})
|
||||
},
|
||||
// { // commented for now, causes confusion with goal command
|
||||
// name: '!npcGoal',
|
||||
// description: 'Set a simple goal for an item or building to automatically work towards. Do not use for complex goals.',
|
||||
|
|
|
@ -1375,3 +1375,55 @@ export async function activateNearestBlock(bot, type) {
|
|||
log(bot, `Activated ${type} at x:${block.position.x.toFixed(1)}, y:${block.position.y.toFixed(1)}, z:${block.position.z.toFixed(1)}.`);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
export async function digDown(bot, distance = 10) {
|
||||
/**
|
||||
* Digs down a specified distance.
|
||||
* @param {MinecraftBot} bot, reference to the minecraft bot.
|
||||
* @param {int} distance, distance to dig down.
|
||||
* @returns {Promise<boolean>} true if successfully dug down.
|
||||
* @example
|
||||
* await skills.digDown(bot, 10);
|
||||
**/
|
||||
|
||||
for (let i = 0; i < distance; i++) {
|
||||
const targetBlock = bot.blockAt(bot.entity.position.offset(0, -1, 0));
|
||||
const belowBlock = bot.blockAt(bot.entity.position.offset(0, -2, 0));
|
||||
|
||||
// Check for lava, water
|
||||
if (!targetBlock || targetBlock.name === 'lava' || targetBlock.name === 'water' ||
|
||||
(belowBlock && (belowBlock.name === 'lava' || belowBlock.name === 'water'))) {
|
||||
console.log(`Dug down ${i} blocks, but reached ${belowBlock ? belowBlock.name : '(lava/water)'}`);
|
||||
log(bot, `Dug down ${i} blocks, but reached ${belowBlock ? belowBlock.name : '(lava/water)'}`)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for a fall of more than 5 blocks below the bot
|
||||
let isSafe = false;
|
||||
for (let j = 1; j <= 5; j++) {
|
||||
const belowBlock = bot.blockAt(bot.entity.position.offset(0, -j-1, 0));
|
||||
if (!belowBlock || belowBlock.name !== 'air') {
|
||||
isSafe = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!targetBlock || !isSafe) {
|
||||
console.log(`Dug down ${i} blocks, but reached fall`);
|
||||
log(bot, `Dug down ${i} blocks, but reached fall`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bot.canDigBlock(targetBlock)) {
|
||||
await breakBlockAt(bot, bot.entity.position.x, bot.entity.position.y - 1, bot.entity.position.z);
|
||||
await bot.waitForTicks(10); // wait for a short period to avoid issues
|
||||
await bot.entity.position.offset(0, -1, 0);
|
||||
} else {
|
||||
console.log('Cannot dig block at position:', bot.entity.position.offset(0, -1, 0));
|
||||
log(bot, 'Cannot dig block at position:' + bot.entity.position.offset(0, -1, 0))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue