mindcraft/src/agent/commands/queries.js
MaxRobinsonTheGreat 1da78bad76 LOTS OF CHANGES
2024-08-22 15:57:20 -05:00

139 lines
4.8 KiB
JavaScript

import * as world from '../library/world.js';
import * as mc from '../../utils/mcdata.js';
const pad = (str) => {
return '\n' + str + '\n';
}
// queries are commands that just return strings and don't affect anything in the world
export const queryList = [
{
name: "!stats",
description: "Get your bot's location, health, hunger, and time of day.",
perform: function (agent) {
let bot = agent.bot;
let res = 'STATS';
let pos = bot.entity.position;
// display position to 2 decimal places
res += `\n- Position: x: ${pos.x.toFixed(2)}, y: ${pos.y.toFixed(2)}, z: ${pos.z.toFixed(2)}`;
res += `\n- Gamemode: ${bot.game.gameMode}`;
res += `\n- Health: ${Math.round(bot.health)} / 20`;
res += `\n- Hunger: ${Math.round(bot.food)} / 20`;
res += `\n- Biome: ${world.getBiomeName(bot)}`;
let weather = "Clear";
if (bot.rainState > 0)
weather = "Rain";
if (bot.thunderState > 0)
weather = "Thunderstorm";
res += `\n- Weather: ${weather}`;
// let block = bot.blockAt(pos);
// res += `\n- Artficial light: ${block.skyLight}`;
// res += `\n- Sky light: ${block.light}`;
// light properties are bugged, they are not accurate
if (bot.time.timeOfDay < 6000) {
res += '\n- Time: Morning';
} else if (bot.time.timeOfDay < 12000) {
res += '\n- Time: Afternoon';
} else {
res += '\n- Time: Night';
}
let other_players = world.getNearbyPlayerNames(bot);
if (other_players.length > 0) {
res += '\n- Other Players: ' + other_players.join(', ');
}
res += '\n' + agent.bot.modes.getMiniDocs() + '\n';
return pad(res);
}
},
{
name: "!inventory",
description: "Get your bot's inventory.",
perform: function (agent) {
let bot = agent.bot;
let inventory = world.getInventoryCounts(bot);
let res = 'INVENTORY';
for (const item in inventory) {
if (inventory[item] && inventory[item] > 0)
res += `\n- ${item}: ${inventory[item]}`;
}
if (res === 'INVENTORY') {
res += ': none';
}
else if (agent.bot.game.gameMode === 'creative') {
res += '\n(You have infinite items in creative mode. You do not need to gather resources!!)';
}
return pad(res);
}
},
{
name: "!nearbyBlocks",
description: "Get the blocks near the bot.",
perform: function (agent) {
let bot = agent.bot;
let res = 'NEARBY_BLOCKS';
let blocks = world.getNearbyBlockTypes(bot);
for (let i = 0; i < blocks.length; i++) {
res += `\n- ${blocks[i]}`;
}
if (blocks.length == 0) {
res += ': none';
}
return pad(res);
}
},
{
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 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}`;
}
}
if (res == 'CRAFTABLE_ITEMS') {
res += ': none';
}
return pad(res);
}
},
{
name: "!entities",
description: "Get the nearby players and entities.",
perform: function (agent) {
let bot = agent.bot;
let res = 'NEARBY_ENTITIES';
for (const entity of world.getNearbyPlayerNames(bot)) {
res += `\n- player: ${entity}`;
}
for (const entity of world.getNearbyEntityTypes(bot)) {
res += `\n- mob: ${entity}`;
}
if (res == 'NEARBY_ENTITIES') {
res += ': none';
}
return pad(res);
}
},
{
name: "!modes",
description: "Get all available modes and their docs and see which are on/off.",
perform: function (agent) {
return agent.bot.modes.getDocs();
}
},
{
name: '!savedPlaces',
description: 'List all saved locations.',
perform: async function (agent) {
return "Saved place names: " + agent.memory_bank.getKeys();
}
}
];