From 578fcf99ba851e09de8898891c63717a384957be Mon Sep 17 00:00:00 2001 From: MaxRobinsonTheGreat Date: Fri, 2 Feb 2024 11:54:17 -0600 Subject: [PATCH] added moveAway and stay commands --- src/agent/commands/actions.js | 15 ++++++++++++++ src/agent/library/skills.js | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/agent/commands/actions.js b/src/agent/commands/actions.js index 21150db..94e5114 100644 --- a/src/agent/commands/actions.js +++ b/src/agent/commands/actions.js @@ -79,6 +79,14 @@ export const actionsList = [ 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', 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) => { 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); + }) } ]; diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index ee6c734..0bf3d0b 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -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} 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} 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) { /** * Sleep in the nearest bed.