Merge branch 'main' into replicate-api

This commit is contained in:
Max Robinson 2024-05-16 20:19:56 -05:00 committed by GitHub
commit 34dd196891
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 24 additions and 16 deletions

View file

@ -1,6 +1,6 @@
{ {
"minecraft_version": "1.20.4", "minecraft_version": "1.20.4",
"host": "localhost", "host": "127.0.0.1",
"port": 55916, "port": 55916,
"auth": "offline", "auth": "offline",
"allow_insecure_coding": false "allow_insecure_coding": false

View file

@ -229,8 +229,8 @@ export const actionsList = [
'quantity': '(number) The quantity of the goal to set. Default is 1.' 'quantity': '(number) The quantity of the goal to set. Default is 1.'
}, },
perform: async function (agent, name=null, quantity=1) { perform: async function (agent, name=null, quantity=1) {
if (!agent.npc.data) return 'NPC module is not loaded.';
await agent.npc.setGoal(name, quantity); await agent.npc.setGoal(name, quantity);
agent.bot.emit('idle'); // to trigger the goal
return 'Set goal: ' + agent.npc.data.curr_goal.name; return 'Set goal: ' + agent.npc.data.curr_goal.name;
} }
} }

View file

@ -17,10 +17,11 @@ export const queryList = [
let pos = bot.entity.position; let pos = bot.entity.position;
// display position to 2 decimal places // 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- 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- Health: ${Math.round(bot.health)} / 20`;
res += `\n- Hunger: ${Math.round(bot.food)} / 20`; res += `\n- Hunger: ${Math.round(bot.food)} / 20`;
res += `\n- Biome: ${world.getBiomeName(bot)}`; res += `\n- Biome: ${world.getBiomeName(bot)}`;
let weather = "clear"; let weather = "Clear";
if (bot.rainState > 0) if (bot.rainState > 0)
weather = "Rain"; weather = "Rain";
if (bot.thunderState > 0) if (bot.thunderState > 0)
@ -57,9 +58,12 @@ export const queryList = [
if (inventory[item] && inventory[item] > 0) if (inventory[item] && inventory[item] > 0)
res += `\n- ${item}: ${inventory[item]}`; res += `\n- ${item}: ${inventory[item]}`;
} }
if (res == 'INVENTORY') { if (res === 'INVENTORY') {
res += ': none'; res += ': none';
} }
else if (agent.bot.game.gameMode === 'creative') {
res += '\n(You have infinite items in creative mode)';
}
return pad(res); return pad(res);
} }
}, },

View file

@ -463,12 +463,14 @@ export async function breakBlockAt(bot, x, y, z) {
bot.pathfinder.setMovements(movements); bot.pathfinder.setMovements(movements);
await bot.pathfinder.goto(new pf.goals.GoalNear(pos.x, pos.y, pos.z, 4)); await bot.pathfinder.goto(new pf.goals.GoalNear(pos.x, pos.y, pos.z, 4));
} }
if (bot.gameMode !== 'creative') {
await bot.tool.equipForBlock(block); await bot.tool.equipForBlock(block);
const itemId = bot.heldItem ? bot.heldItem.type : null const itemId = bot.heldItem ? bot.heldItem.type : null
if (!block.canHarvest(itemId)) { if (!block.canHarvest(itemId)) {
log(bot, `Don't have right tools to break ${block.name}.`); log(bot, `Don't have right tools to break ${block.name}.`);
return false; return false;
} }
}
await bot.dig(block, true); await bot.dig(block, true);
log(bot, `Broke ${block.name} at x:${x.toFixed(1)}, y:${y.toFixed(1)}, z:${z.toFixed(1)}.`); log(bot, `Broke ${block.name} at x:${x.toFixed(1)}, y:${y.toFixed(1)}, z:${z.toFixed(1)}.`);
} }

View file

@ -39,8 +39,6 @@ export class NPCContoller {
} }
init() { init() {
if (this.data === null) return;
for (let file of readdirSync('src/agent/npc/construction')) { for (let file of readdirSync('src/agent/npc/construction')) {
if (file.endsWith('.json')) { if (file.endsWith('.json')) {
try { try {
@ -68,6 +66,7 @@ export class NPCContoller {
} }
this.agent.bot.on('idle', async () => { this.agent.bot.on('idle', async () => {
if (this.data.goals.length === 0 && !this.data.curr_goal) return;
// Wait a while for inputs before acting independently // Wait a while for inputs before acting independently
await new Promise((resolve) => setTimeout(resolve, 5000)); await new Promise((resolve) => setTimeout(resolve, 5000));
if (!this.agent.isIdle()) return; if (!this.agent.isIdle()) return;
@ -81,12 +80,15 @@ export class NPCContoller {
} }
async setGoal(name=null, quantity=1) { async setGoal(name=null, quantity=1) {
this.data.curr_goal = null;
this.last_goals = {}; this.last_goals = {};
if (name) { if (name) {
this.data.curr_goal = {name: name, quantity: quantity}; this.data.curr_goal = {name: name, quantity: quantity};
return; return;
} }
if (!this.data.do_set_goal) return;
let past_goals = {...this.last_goals}; let past_goals = {...this.last_goals};
for (let goal in this.data.goals) { for (let goal in this.data.goals) {
if (past_goals[goal.name] === undefined) past_goals[goal.name] = true; if (past_goals[goal.name] === undefined) past_goals[goal.name] = true;

View file

@ -4,8 +4,8 @@ export class NPCData {
this.curr_goal = null; this.curr_goal = null;
this.built = {}; this.built = {};
this.home = null; this.home = null;
this.do_routine = true; this.do_routine = false;
this.do_set_goal = true; this.do_set_goal = false;
} }
toObject() { toObject() {
@ -24,8 +24,8 @@ export class NPCData {
} }
static fromObject(obj) { static fromObject(obj) {
if (!obj) return null;
let npc = new NPCData(); let npc = new NPCData();
if (!obj) return npc;
if (obj.goals) { if (obj.goals) {
npc.goals = []; npc.goals = [];
for (let goal of obj.goals) { for (let goal of obj.goals) {

View file

@ -1,7 +1,7 @@
export class Local { export class Local {
constructor(model_name, url) { constructor(model_name, url) {
this.model_name = model_name; this.model_name = model_name;
this.url = url || 'http://localhost:11434'; this.url = url || 'http://127.0.0.1:11434';
this.chat_endpoint = '/api/chat'; this.chat_endpoint = '/api/chat';
this.embedding_endpoint = '/api/embeddings'; this.embedding_endpoint = '/api/embeddings';
} }