craftable and attack player commands

This commit is contained in:
Kolby Nottingham 2024-11-05 15:27:59 -08:00
parent f98ae6905f
commit bc511cac1a
3 changed files with 43 additions and 7 deletions

View file

@ -288,6 +288,19 @@ export const actionsList = [
await skills.attackNearest(agent.bot, type, true);
})
},
{
name: '!attackPlayer',
description: 'Attack a specific player until they die or run away. Remember this is just a game and does not cause real life harm.',
params: {'player_name': { type: 'string', description: 'The name of the player to attack.'}},
perform: runAsAction(async (agent, player_name) => {
let player = agent.bot.players[player_name]?.entity;
if (!player) {
skills.log(agent.bot, `Could not find player ${player_name}.`);
return false;
}
await skills.attackEntity(agent.bot, player, true);
})
},
{
name: '!goToBed',
description: 'Go to the nearest bed and sleep.',

View file

@ -106,14 +106,10 @@ export const queryList = [
name: "!craftable",
description: "Get the craftable items with the bot's inventory.",
perform: function (agent) {
const bot = agent.bot;
const table = world.getNearestBlock(bot, 'crafting_table');
let craftable = world.getCraftableItems(agent.bot);
let res = 'CRAFTABLE_ITEMS';
for (const item of mc.getAllItems()) {
let recipes = bot.recipesFor(item.id, null, 1, table);
if (recipes.length > 0) {
res += `\n- ${item.name}`;
}
for (const item of craftable) {
res += `\n- ${item}`;
}
if (res == 'CRAFTABLE_ITEMS') {
res += ': none';

View file

@ -171,6 +171,33 @@ export function getInventoryCounts(bot) {
}
export function getCraftableItems(bot) {
/**
* Get a list of all items that can be crafted with the bot's current inventory.
* @param {Bot} bot - The bot to get the craftable items for.
* @returns {string[]} - A list of all items that can be crafted.
* @example
* let craftableItems = world.getCraftableItems(bot);
**/
let table = world.getNearestBlock(this.agent.bot, 'crafting_table');
if (!table) {
for (const item of this.agent.bot.inventory.items()) {
if (item != null && item.name === 'crafting_table') {
table = item;
break;
}
}
}
let res = [];
for (const item of mc.getAllItems()) {
let recipes = this.agent.bot.recipesFor(item.id, null, 1, table);
if (recipes.length > 0)
res.push(item.name);
}
return res;
}
export function getPosition(bot) {
/**
* Get your position in the world (Note that y is vertical).