// bot-tasks/find-materials.js const { GoalBlock } = require('mineflayer-pathfinder').goals; console.log('[TASK] find-materials.js loaded'); module.exports = async function findMaterials(bot, db, sayWithPersona) { console.log('[TASK EXECUTION] find-materials running'); sayWithPersona("you asked me to find materials. I'm trying..."); if (!bot.allowDestruction) { sayWithPersona("i'm not supposed to break things unless you tell me to."); return; } try { // For now, hardcoded material search — will eventually be inferred from task/command const keywords = ['log', 'coal', 'iron_ore', 'tree', 'water', 'wood', 'potato', 'carrot']; // Expandable list const targetBlock = bot.findBlock({ matching: block => keywords.some(k => block.name.includes(k)), maxDistance: 32 }); if (!targetBlock) { sayWithPersona("you looked around and couldn't find any good materials nearby."); return; } sayWithPersona(`you spotted some ${targetBlock.name}. heading there now.`); bot.pathfinder.setGoal(new GoalBlock(targetBlock.position.x, targetBlock.position.y, targetBlock.position.z)); // Optional: add memory logging db.run( `INSERT OR IGNORE INTO memory (label, data) VALUES (?, ?)`, [`found-${targetBlock.name}`, JSON.stringify(targetBlock.position)], (err) => { if (err) console.error("DB insert failed in find-materials:", err); } ); } catch (err) { console.error("find-materials.js failed:", err); sayWithPersona("you tried to find materials but got lost in thought."); } };