Merge pull request #53 from kolbytn/lil-fixes

Lil fixes
This commit is contained in:
Max Robinson 2024-04-19 19:00:37 -05:00 committed by GitHub
commit 20da11e76d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 1 deletions

View file

@ -182,6 +182,14 @@ export const actionsList = [
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',
description: 'Stay in the current location no matter what. Pauses all modes.',

View file

@ -912,3 +912,27 @@ export async function tillAndSow(bot, x, y, z, seedType=null) {
}
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;
}

View file

@ -87,7 +87,7 @@ const modes = [
// TODO: check light level instead of nearby torches, block.light is broken
const near_torch = world.getNearestBlock(agent.bot, 'torch', 6);
if (!near_torch) {
let torches = agent.bot.inventory.items().filter(item => item.name.includes('torch'));
let torches = agent.bot.inventory.items().filter(item => item.name === 'torch');
if (torches.length > 0) {
const torch = torches[0];
const pos = agent.bot.entity.position;