diff --git a/settings.json b/settings.json index 9d0490a..4ee3b10 100644 --- a/settings.json +++ b/settings.json @@ -1,6 +1,6 @@ { "minecraft_version": "1.20.4", - "host": "localhost", + "host": "127.0.0.1", "port": 55916, "auth": "offline", "allow_insecure_coding": false diff --git a/src/agent/commands/actions.js b/src/agent/commands/actions.js index f409211..12ccacb 100644 --- a/src/agent/commands/actions.js +++ b/src/agent/commands/actions.js @@ -229,8 +229,8 @@ export const actionsList = [ 'quantity': '(number) The quantity of the goal to set. Default is 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); + agent.bot.emit('idle'); // to trigger the goal return 'Set goal: ' + agent.npc.data.curr_goal.name; } } diff --git a/src/agent/commands/queries.js b/src/agent/commands/queries.js index 99f5fa9..aa60b0b 100644 --- a/src/agent/commands/queries.js +++ b/src/agent/commands/queries.js @@ -17,10 +17,11 @@ export const queryList = [ 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"; + let weather = "Clear"; if (bot.rainState > 0) weather = "Rain"; if (bot.thunderState > 0) @@ -57,9 +58,12 @@ export const queryList = [ if (inventory[item] && inventory[item] > 0) res += `\n- ${item}: ${inventory[item]}`; } - if (res == 'INVENTORY') { + if (res === 'INVENTORY') { res += ': none'; } + else if (agent.bot.game.gameMode === 'creative') { + res += '\n(You have infinite items in creative mode)'; + } return pad(res); } }, diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index 4889357..56f31f1 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -463,11 +463,13 @@ export async function breakBlockAt(bot, x, y, z) { bot.pathfinder.setMovements(movements); await bot.pathfinder.goto(new pf.goals.GoalNear(pos.x, pos.y, pos.z, 4)); } - await bot.tool.equipForBlock(block); - const itemId = bot.heldItem ? bot.heldItem.type : null - if (!block.canHarvest(itemId)) { - log(bot, `Don't have right tools to break ${block.name}.`); - return false; + if (bot.gameMode !== 'creative') { + await bot.tool.equipForBlock(block); + const itemId = bot.heldItem ? bot.heldItem.type : null + if (!block.canHarvest(itemId)) { + log(bot, `Don't have right tools to break ${block.name}.`); + return false; + } } await bot.dig(block, true); log(bot, `Broke ${block.name} at x:${x.toFixed(1)}, y:${y.toFixed(1)}, z:${z.toFixed(1)}.`); diff --git a/src/agent/npc/controller.js b/src/agent/npc/controller.js index 7636dcc..d65107c 100644 --- a/src/agent/npc/controller.js +++ b/src/agent/npc/controller.js @@ -39,8 +39,6 @@ export class NPCContoller { } init() { - if (this.data === null) return; - for (let file of readdirSync('src/agent/npc/construction')) { if (file.endsWith('.json')) { try { @@ -68,6 +66,7 @@ export class NPCContoller { } 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 await new Promise((resolve) => setTimeout(resolve, 5000)); if (!this.agent.isIdle()) return; @@ -81,12 +80,15 @@ export class NPCContoller { } async setGoal(name=null, quantity=1) { + this.data.curr_goal = null; this.last_goals = {}; if (name) { this.data.curr_goal = {name: name, quantity: quantity}; return; } - + + if (!this.data.do_set_goal) return; + let past_goals = {...this.last_goals}; for (let goal in this.data.goals) { if (past_goals[goal.name] === undefined) past_goals[goal.name] = true; diff --git a/src/agent/npc/data.js b/src/agent/npc/data.js index b590d15..b5de0eb 100644 --- a/src/agent/npc/data.js +++ b/src/agent/npc/data.js @@ -4,8 +4,8 @@ export class NPCData { this.curr_goal = null; this.built = {}; this.home = null; - this.do_routine = true; - this.do_set_goal = true; + this.do_routine = false; + this.do_set_goal = false; } toObject() { @@ -24,8 +24,8 @@ export class NPCData { } static fromObject(obj) { - if (!obj) return null; let npc = new NPCData(); + if (!obj) return npc; if (obj.goals) { npc.goals = []; for (let goal of obj.goals) { diff --git a/src/models/local.js b/src/models/local.js index f56c043..dd3af34 100644 --- a/src/models/local.js +++ b/src/models/local.js @@ -1,7 +1,7 @@ export class Local { constructor(model_name, url) { 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.embedding_endpoint = '/api/embeddings'; }