2024-01-25 13:25:36 -08:00
import * as world from '../library/world.js' ;
import * as mc from '../../utils/mcdata.js' ;
2025-01-09 12:43:29 -06:00
import { getCommandDocs } from './index.js' ;
2024-12-03 22:58:04 -06:00
import convoManager from '../conversation.js' ;
2023-11-07 09:44:56 -06:00
const pad = ( str ) => {
return '\n' + str + '\n' ;
}
2024-01-09 22:50:22 -06:00
// queries are commands that just return strings and don't affect anything in the world
export const queryList = [
2023-11-07 09:44:56 -06:00
{
name : "!stats" ,
2024-01-14 14:35:23 -06:00
description : "Get your bot's location, health, hunger, and time of day." ,
2023-11-07 12:00:55 -06:00
perform : function ( agent ) {
2023-12-28 09:20:26 -08:00
let bot = agent . bot ;
let res = 'STATS' ;
2024-01-14 14:35:23 -06:00
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 ) } ` ;
2024-11-16 17:50:45 -08:00
// Gameplay
2024-05-14 21:05:39 -05:00
res += ` \n - Gamemode: ${ bot . game . gameMode } ` ;
2024-01-14 14:35:23 -06:00
res += ` \n - Health: ${ Math . round ( bot . health ) } / 20 ` ;
res += ` \n - Hunger: ${ Math . round ( bot . food ) } / 20 ` ;
2024-01-25 13:25:36 -08:00
res += ` \n - Biome: ${ world . getBiomeName ( bot ) } ` ;
2024-05-14 21:05:39 -05:00
let weather = "Clear" ;
2024-01-24 17:24:52 -06:00
if ( bot . rainState > 0 )
weather = "Rain" ;
if ( bot . thunderState > 0 )
weather = "Thunderstorm" ;
res += ` \n - Weather: ${ weather } ` ;
2024-01-14 14:35:23 -06:00
// 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
2025-01-05 15:52:04 -06:00
res += '\n- ' + world . getSurroundingBlocks ( bot ) . join ( '\n- ' )
res += ` \n - First Solid Block Above Head: ${ world . getFirstBlockAboveHead ( bot , null , 32 ) } ` ;
2024-01-14 14:35:23 -06:00
2023-12-28 09:20:26 -08:00
if ( bot . time . timeOfDay < 6000 ) {
2024-01-14 14:35:23 -06:00
res += '\n- Time: Morning' ;
2023-12-28 09:20:26 -08:00
} else if ( bot . time . timeOfDay < 12000 ) {
2024-01-14 14:35:23 -06:00
res += '\n- Time: Afternoon' ;
2023-12-28 09:20:26 -08:00
} else {
2024-01-14 14:35:23 -06:00
res += '\n- Time: Night' ;
2023-12-28 09:20:26 -08:00
}
2024-02-25 14:21:44 -06:00
2024-11-19 22:27:45 -06:00
// get the bot's current action
let action = agent . actions . currentActionLabel ;
if ( agent . isIdle ( ) )
action = 'Idle' ;
res += ` \- Current Action: ${ action } ` ;
let players = world . getNearbyPlayerNames ( bot ) ;
2024-12-08 20:58:59 -06:00
let bots = convoManager . getInGameAgents ( ) . filter ( b => b !== agent . name ) ;
players = players . filter ( p => ! bots . includes ( p ) ) ;
2024-11-19 22:27:45 -06:00
2024-12-08 20:58:59 -06:00
res += '\n- Nearby Human Players: ' + ( players . length > 0 ? players . join ( ', ' ) : 'None.' ) ;
res += '\n- Nearby Bot Players: ' + ( bots . length > 0 ? bots . join ( ', ' ) : 'None.' ) ;
2024-08-22 15:57:20 -05:00
res += '\n' + agent . bot . modes . getMiniDocs ( ) + '\n' ;
2023-12-28 09:20:26 -08:00
return pad ( res ) ;
2023-11-07 09:44:56 -06:00
}
} ,
{
name : "!inventory" ,
description : "Get your bot's inventory." ,
2023-11-07 12:00:55 -06:00
perform : function ( agent ) {
2023-12-28 09:20:26 -08:00
let bot = agent . bot ;
2024-01-25 13:25:36 -08:00
let inventory = world . getInventoryCounts ( bot ) ;
2023-12-28 09:20:26 -08:00
let res = 'INVENTORY' ;
for ( const item in inventory ) {
if ( inventory [ item ] && inventory [ item ] > 0 )
res += ` \n - ${ item } : ${ inventory [ item ] } ` ;
}
2024-05-14 22:57:14 -05:00
if ( res === 'INVENTORY' ) {
2024-11-19 22:27:45 -06:00
res += ': Nothing' ;
2023-12-28 09:20:26 -08:00
}
2024-05-14 22:57:14 -05:00
else if ( agent . bot . game . gameMode === 'creative' ) {
2024-08-22 15:57:20 -05:00
res += '\n(You have infinite items in creative mode. You do not need to gather resources!!)' ;
2024-05-14 21:05:39 -05:00
}
2024-10-15 17:04:19 -05:00
let helmet = bot . inventory . slots [ 5 ] ;
let chestplate = bot . inventory . slots [ 6 ] ;
let leggings = bot . inventory . slots [ 7 ] ;
let boots = bot . inventory . slots [ 8 ] ;
res += '\nWEARING: ' ;
if ( helmet )
res += ` \n Head: ${ helmet . name } ` ;
if ( chestplate )
res += ` \n Torso: ${ chestplate . name } ` ;
if ( leggings )
res += ` \n Legs: ${ leggings . name } ` ;
if ( boots )
res += ` \n Feet: ${ boots . name } ` ;
if ( ! helmet && ! chestplate && ! leggings && ! boots )
2024-11-19 22:27:45 -06:00
res += 'Nothing' ;
2024-10-15 17:04:19 -05:00
2023-12-28 09:20:26 -08:00
return pad ( res ) ;
2023-11-07 09:44:56 -06:00
}
} ,
{
2024-02-16 11:57:48 -06:00
name : "!nearbyBlocks" ,
2023-11-07 09:44:56 -06:00
description : "Get the blocks near the bot." ,
2023-11-07 12:00:55 -06:00
perform : function ( agent ) {
2023-12-28 09:20:26 -08:00
let bot = agent . bot ;
let res = 'NEARBY_BLOCKS' ;
2024-01-25 13:25:36 -08:00
let blocks = world . getNearbyBlockTypes ( bot ) ;
2023-12-28 09:20:26 -08:00
for ( let i = 0 ; i < blocks . length ; i ++ ) {
res += ` \n - ${ blocks [ i ] } ` ;
}
if ( blocks . length == 0 ) {
res += ': none' ;
2024-11-16 18:54:25 -08:00
}
else {
// Environmental Awareness
2024-11-19 00:07:36 -08:00
res += '\n- ' + world . getSurroundingBlocks ( bot ) . join ( '\n- ' )
res += ` \n - First Solid Block Above Head: ${ world . getFirstBlockAboveHead ( bot , null , 32 ) } ` ;
2023-12-28 09:20:26 -08:00
}
return pad ( res ) ;
2023-11-07 09:44:56 -06:00
}
} ,
{
name : "!craftable" ,
description : "Get the craftable items with the bot's inventory." ,
2023-11-07 12:00:55 -06:00
perform : function ( agent ) {
2024-11-05 15:27:59 -08:00
let craftable = world . getCraftableItems ( agent . bot ) ;
2023-12-28 09:20:26 -08:00
let res = 'CRAFTABLE_ITEMS' ;
2024-11-05 15:27:59 -08:00
for ( const item of craftable ) {
res += ` \n - ${ item } ` ;
2023-12-28 09:20:26 -08:00
}
if ( res == 'CRAFTABLE_ITEMS' ) {
res += ': none' ;
}
return pad ( res ) ;
2023-11-07 09:44:56 -06:00
}
} ,
{
name : "!entities" ,
description : "Get the nearby players and entities." ,
2023-11-07 12:00:55 -06:00
perform : function ( agent ) {
2023-12-28 09:20:26 -08:00
let bot = agent . bot ;
let res = 'NEARBY_ENTITIES' ;
2024-11-05 12:17:10 -06:00
let players = world . getNearbyPlayerNames ( bot ) ;
2024-12-08 20:58:59 -06:00
let bots = convoManager . getInGameAgents ( ) . filter ( b => b !== agent . name ) ;
players = players . filter ( p => ! bots . includes ( p ) ) ;
2024-11-05 12:17:10 -06:00
for ( const player of players ) {
2024-11-19 22:27:45 -06:00
res += ` \n - Human player: ${ player } ` ;
2023-12-28 09:20:26 -08:00
}
2024-11-05 12:17:10 -06:00
for ( const bot of bots ) {
2024-11-19 22:27:45 -06:00
res += ` \n - Bot player: ${ bot } ` ;
2024-11-05 12:17:10 -06:00
}
2024-01-25 13:25:36 -08:00
for ( const entity of world . getNearbyEntityTypes ( bot ) ) {
2024-10-10 22:17:39 -05:00
if ( entity === 'player' || entity === 'item' )
continue ;
res += ` \n - entities: ${ entity } ` ;
2023-12-28 09:20:26 -08:00
}
if ( res == 'NEARBY_ENTITIES' ) {
res += ': none' ;
}
return pad ( res ) ;
2023-11-07 09:44:56 -06:00
}
} ,
2024-01-23 18:01:38 -06:00
{
name : "!modes" ,
2024-08-22 15:57:20 -05:00
description : "Get all available modes and their docs and see which are on/off." ,
2024-01-23 18:01:38 -06:00
perform : function ( agent ) {
2024-08-22 15:57:20 -05:00
return agent . bot . modes . getDocs ( ) ;
2024-01-23 18:01:38 -06:00
}
2024-04-27 23:28:34 -05:00
} ,
{
name : '!savedPlaces' ,
description : 'List all saved locations.' ,
perform : async function ( agent ) {
2024-04-27 23:36:58 -05:00
return "Saved place names: " + agent . memory _bank . getKeys ( ) ;
2024-04-27 23:28:34 -05:00
}
2025-01-05 19:27:44 -08:00
} ,
{
name : '!getCraftingPlan' ,
description : "Provides a comprehensive crafting plan for a specified item. This includes a breakdown of required ingredients, the exact quantities needed, and an analysis of missing ingredients or extra items needed based on the bot's current inventory." ,
params : {
targetItem : {
type : 'string' ,
description : 'The item that we are trying to craft'
} ,
quantity : {
type : 'int' ,
description : 'The quantity of the item that we are trying to craft' ,
optional : true ,
domain : [ 1 , Infinity , '[)' ] , // Quantity must be at least 1,
default : 1
}
} ,
perform : function ( agent , targetItem , quantity = 1 ) {
let bot = agent . bot ;
// Fetch the bot's inventory
const curr _inventory = world . getInventoryCounts ( bot ) ;
const target _item = targetItem ;
let existingCount = curr _inventory [ target _item ] || 0 ;
var prefixMessage = '' ;
if ( existingCount > 0 ) {
curr _inventory [ target _item ] -= existingCount ;
prefixMessage = ` You already have ${ existingCount } ${ target _item } in your inventory. If you need to craft more, \n ` ;
}
// Generate crafting plan
var craftingPlan = mc . getDetailedCraftingPlan ( target _item , quantity , curr _inventory ) ;
craftingPlan = prefixMessage + craftingPlan ;
console . log ( '\n\n\n\n\n\n\n\n\n\n\n' ) ;
console . log ( craftingPlan ) ;
return pad ( craftingPlan ) ;
2025-02-04 15:33:35 -06:00
} ,
2025-01-07 13:41:14 -06:00
{
name : '!help' ,
description : 'Lists all available commands and their descriptions.' ,
perform : async function ( agent ) {
2025-01-09 12:43:29 -06:00
return getCommandDocs ( ) ;
2025-01-05 19:27:44 -08:00
}
} ,
2024-01-25 13:25:36 -08:00
] ;