added activate command

This commit is contained in:
MaxRobinsonTheGreat 2024-04-19 14:02:30 -05:00
parent b9f2f74df4
commit 9a929fc3b2
2 changed files with 32 additions and 0 deletions

View file

@ -182,6 +182,14 @@ export const actionsList = [
await skills.goToBed(agent.bot); await skills.goToBed(agent.bot);
}) })
}, },
{
name: '!activate',
description: 'Activate the nearest object of a given type.',
params: {'type': '(string) The type of object to activate.'},
perform: wrapExecution(async (agent, type) => {
await skills.activateNearestBlock(agent.bot, type);
})
},
{ {
name: '!stay', name: '!stay',
description: 'Stay in the current location no matter what. Pauses all modes.', description: 'Stay in the current location no matter what. Pauses all modes.',

View file

@ -869,3 +869,27 @@ export async function tillAndSow(bot, x, y, z, seedType=null) {
} }
return true; return true;
} }
export async function activateNearestBlock(bot, type) {
/**
* Activate the nearest block of the given type.
* @param {MinecraftBot} bot, reference to the minecraft bot.
* @param {string} type, the type of block to activate.
* @returns {Promise<boolean>} true if the block was activated, false otherwise.
* @example
* await skills.activateNearestBlock(bot, "lever");
* **/
let block = world.getNearestBlock(bot, type, 16);
if (!block) {
log(bot, `Could not find any ${type} to activate.`);
return false;
}
if (bot.entity.position.distanceTo(block.position) > 4.5) {
let pos = block.position;
bot.pathfinder.setMovements(new pf.Movements(bot));
await bot.pathfinder.goto(new pf.goals.GoalNear(pos.x, pos.y, pos.z, 4));
}
await bot.activateBlock(block);
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;
}