mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-04 14:25:43 +02:00
added moveAway and stay commands
This commit is contained in:
parent
ab340a7b6d
commit
578fcf99ba
2 changed files with 53 additions and 0 deletions
|
@ -79,6 +79,14 @@ export const actionsList = [
|
||||||
await skills.followPlayer(agent.bot, player_name);
|
await skills.followPlayer(agent.bot, player_name);
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: '!moveAway',
|
||||||
|
description: 'Move away from the current location in any direction by a given distance. Ex: !moveAway(2)',
|
||||||
|
params: {'distance': '(number) The distance to move away.'},
|
||||||
|
perform: wrapExecution(async (agent, distance) => {
|
||||||
|
await skills.moveAway(agent.bot, distance);
|
||||||
|
})
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: '!givePlayer',
|
name: '!givePlayer',
|
||||||
description: 'Give the specified item to the given player. Ex: !givePlayer("steve", "stone_pickaxe", 1)',
|
description: 'Give the specified item to the given player. Ex: !givePlayer("steve", "stone_pickaxe", 1)',
|
||||||
|
@ -138,5 +146,12 @@ export const actionsList = [
|
||||||
perform: wrapExecution(async (agent) => {
|
perform: wrapExecution(async (agent) => {
|
||||||
await skills.goToBed(agent.bot);
|
await skills.goToBed(agent.bot);
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '!stay',
|
||||||
|
description: 'Stay in the current location no matter what. Pauses all modes.',
|
||||||
|
perform: wrapExecution(async (agent) => {
|
||||||
|
await skills.stay(agent.bot);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -697,6 +697,44 @@ export async function followPlayer(bot, username) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export async function moveAway(bot, distance) {
|
||||||
|
/**
|
||||||
|
* Move away from current position in any direction.
|
||||||
|
* @param {MinecraftBot} bot, reference to the minecraft bot.
|
||||||
|
* @param {number} distance, the distance to move away.
|
||||||
|
* @returns {Promise<boolean>} true if the bot moved away, false otherwise.
|
||||||
|
* @example
|
||||||
|
* await skills.moveAway(bot, 8);
|
||||||
|
**/
|
||||||
|
const pos = bot.entity.position;
|
||||||
|
let goal = new pf.goals.GoalNear(pos.x, pos.y, pos.z, distance);
|
||||||
|
let inverted_goal = new pf.goals.GoalInvert(goal);
|
||||||
|
bot.pathfinder.setMovements(new pf.Movements(bot));
|
||||||
|
await bot.pathfinder.goto(inverted_goal);
|
||||||
|
let new_pos = bot.entity.position;
|
||||||
|
log(bot, `Moved away from nearest entity to ${new_pos}.`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function stay(bot) {
|
||||||
|
/**
|
||||||
|
* Stay in the current position until interrupted. Disables all modes.
|
||||||
|
* @param {MinecraftBot} bot, reference to the minecraft bot.
|
||||||
|
* @returns {Promise<boolean>} true if the bot stayed, false otherwise.
|
||||||
|
* @example
|
||||||
|
* await skills.stay(bot);
|
||||||
|
**/
|
||||||
|
bot.modes.pause('self_defense');
|
||||||
|
bot.modes.pause('hunting');
|
||||||
|
bot.modes.pause('torch_placing');
|
||||||
|
bot.modes.pause('item_collecting');
|
||||||
|
while (!bot.interrupt_code) {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function goToBed(bot) {
|
export async function goToBed(bot) {
|
||||||
/**
|
/**
|
||||||
* Sleep in the nearest bed.
|
* Sleep in the nearest bed.
|
||||||
|
|
Loading…
Add table
Reference in a new issue