Updated logic for Idle and Observe.
All checks were successful
Deploy Cletus Bot / deploy (push) Successful in 25s
All checks were successful
Deploy Cletus Bot / deploy (push) Successful in 25s
This commit is contained in:
parent
dcee986a96
commit
d8ee8d6728
4 changed files with 116 additions and 55 deletions
|
|
@ -0,0 +1,41 @@
|
||||||
|
const { getBot } = require('../core/context');
|
||||||
|
const { saveMemory } = require('../memory');
|
||||||
|
const db = require('../db');
|
||||||
|
|
||||||
|
// Define what kinds of blocks to remember. This should probably be a variable later so that I can add to this list.
|
||||||
|
const INTERESTING_BLOCKS = [
|
||||||
|
'coal_ore', 'iron_ore', 'diamond_ore', 'gold_ore', 'emerald_ore',
|
||||||
|
'redstone_ore', 'lapis_ore', 'copper_ore',
|
||||||
|
'oak_log', 'birch_log', 'spruce_log',
|
||||||
|
'crafting_table', 'furnace', 'chest', 'anvil',
|
||||||
|
'enchanting_table', 'lectern', 'bell',
|
||||||
|
'bed', 'beacon', 'portal'
|
||||||
|
];
|
||||||
|
|
||||||
|
module.exports = async function logSurroundings() {
|
||||||
|
const bot = getBot();
|
||||||
|
if (!bot) return;
|
||||||
|
|
||||||
|
const found = bot.findBlocks({
|
||||||
|
matching: block => INTERESTING_BLOCKS.includes(block.name),
|
||||||
|
maxDistance: 12,
|
||||||
|
count: 10
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const pos of found) {
|
||||||
|
const block = bot.blockAt(pos);
|
||||||
|
if (!block || !block.name) continue;
|
||||||
|
|
||||||
|
const label = `found:${block.name}:${pos.x},${pos.y},${pos.z}`;
|
||||||
|
const memoryData = {
|
||||||
|
name: block.name,
|
||||||
|
position: pos
|
||||||
|
};
|
||||||
|
|
||||||
|
saveMemory(db, label, memoryData);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found.length > 0) {
|
||||||
|
bot.chat(`I noticed ${found.length} interesting blocks nearby.`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -1,14 +1,18 @@
|
||||||
// states/ActOnMemory.js
|
// states/ActOnMemory.js
|
||||||
const { chatWithAI } = require('../lib/ai-helper');
|
const { chatWithAI } = require('../lib/ai-helper');
|
||||||
const { getBot } = require('../core/context');
|
const { getBot, getStateMachine } = require('../core/context');
|
||||||
const config = require('../config.json');
|
const config = require('../config.json');
|
||||||
|
|
||||||
module.exports = async function ActOnMemory() {
|
module.exports = async function ActOnMemory() {
|
||||||
|
const bot = getBot();
|
||||||
console.log('[STATE] ActOnMemory');
|
console.log('[STATE] ActOnMemory');
|
||||||
|
|
||||||
const prompt = 'You just died. Based on what you remember, what should you do next?';
|
const prompt = 'You just died. Based on what you remember, what should you do next?';
|
||||||
const response = await chatWithAI(prompt, config.ai);
|
const response = await chatWithAI(prompt, config.ai);
|
||||||
|
|
||||||
const bot = getBot();
|
|
||||||
bot.chat(response);
|
bot.chat(response);
|
||||||
|
|
||||||
|
setTimeout(async () => {
|
||||||
|
getStateMachine().transition('Idle');
|
||||||
|
|
||||||
|
}, 5000);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
// states/Idle.js
|
// states/Idle.js
|
||||||
const { getBot } = require('../core/context');
|
const { getBot } = require('../core/context');
|
||||||
|
|
||||||
const { GoalNear } = require('mineflayer-pathfinder').goals;
|
const { GoalNear } = require('mineflayer-pathfinder').goals;
|
||||||
const { getHomeZone } = require('../memory/locations');
|
const { getHomeZone } = require('../memory/locations');
|
||||||
const db = require('../db');
|
const db = require('../db');
|
||||||
|
|
@ -8,6 +9,7 @@ module.exports = async function Idle() {
|
||||||
const bot = getBot();
|
const bot = getBot();
|
||||||
console.log('[STATE] Idle');
|
console.log('[STATE] Idle');
|
||||||
|
|
||||||
|
return new Promise(resolve => {
|
||||||
getHomeZone(db, async (err, zone) => {
|
getHomeZone(db, async (err, zone) => {
|
||||||
const fallbackCenter = { x: 100, y: 64, z: 100 };
|
const fallbackCenter = { x: 100, y: 64, z: 100 };
|
||||||
const fallbackBounds = { x: 20, y: 10, z: 20 };
|
const fallbackBounds = { x: 20, y: 10, z: 20 };
|
||||||
|
|
@ -53,6 +55,7 @@ module.exports = async function Idle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
const mob = Object.values(bot.entities).find(e =>
|
const mob = Object.values(bot.entities).find(e =>
|
||||||
e.type === 'mob' &&
|
e.type === 'mob' &&
|
||||||
e.position.distanceTo(bot.entity.position) <= safeRadius &&
|
e.position.distanceTo(bot.entity.position) <= safeRadius &&
|
||||||
|
|
@ -69,5 +72,11 @@ module.exports = async function Idle() {
|
||||||
bot.pathfinder.setGoal(new GoalNear(pos.x, pos.y, pos.z, 1));
|
bot.pathfinder.setGoal(new GoalNear(pos.x, pos.y, pos.z, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
getStateMachine().transition('Observe');
|
||||||
|
resolve();
|
||||||
|
}, 10000 );
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -13,4 +13,11 @@ module.exports = async function Observe() {
|
||||||
const response = await chatWithAI(msg, config.ai);
|
const response = await chatWithAI(msg, config.ai);
|
||||||
|
|
||||||
bot.chat(response);
|
bot.chat(response);
|
||||||
|
|
||||||
|
await logSurroundings();
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
getStateMachine().transition('Idle');
|
||||||
|
}, 10000);
|
||||||
|
|
||||||
};
|
};
|
||||||
Loading…
Reference in a new issue