mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-22 06:02:07 +02:00
commit
20da11e76d
3 changed files with 33 additions and 1 deletions
|
@ -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.',
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue