mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-04 06:15:32 +02:00
Merge branch 'main' into replicate-api
This commit is contained in:
commit
34dd196891
7 changed files with 24 additions and 16 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"minecraft_version": "1.20.4",
|
||||
"host": "localhost",
|
||||
"host": "127.0.0.1",
|
||||
"port": 55916,
|
||||
"auth": "offline",
|
||||
"allow_insecure_coding": false
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -463,12 +463,14 @@ 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));
|
||||
}
|
||||
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)}.`);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue