mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-21 21:52:07 +02:00
craftable and attack player commands
This commit is contained in:
parent
f98ae6905f
commit
bc511cac1a
3 changed files with 43 additions and 7 deletions
|
@ -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.',
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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).
|
||||
|
|
Loading…
Add table
Reference in a new issue