const { GoalNear } = require('mineflayer-pathfinder').goals; const memory = require('../lib/memory'); module.exports = async function eatFood(bot, db, sayWithPersona) { try { const foodItem = bot.inventory.items().find(i => i.name.includes('bread') || i.name.includes('apple') || i.name.includes('carrot') ); if (foodItem) { await bot.equip(foodItem, 'hand'); await bot.consume(); sayWithPersona("you were hungry, so you ate something. yum."); return; } sayWithPersona("you're starving and have no food. checking a chest..."); memory.getMemory(db, 'food-chest', async (err, pos) => { if (err || !pos) { sayWithPersona("you have no idea where food is. you're doomed."); return; } bot.pathfinder.setGoal(new GoalNear(pos.x, pos.y, pos.z, 1)); const checkChest = setTimeout(async () => { try { const chestBlock = bot.blockAt(bot.entity.position.offset(1, 0, 0)); const chest = await bot.openChest(chestBlock); const food = chest.containerItems().find(item => item.name.includes('bread') || item.name.includes('apple') ); if (food) { await chest.withdraw(food.type, null, 1); sayWithPersona("you snagged food from the chest. eating now..."); await bot.equip(food, 'hand'); await bot.consume(); } else { sayWithPersona("you checked the food chest, but it's empty. awesome."); } chest.close(); clearTimeout(checkChest); } catch (e) { sayWithPersona("you fumbled the chest like a fool."); console.error("eat-food chest error:", e); } }, 4000); }); } catch (err) { console.error("eat-food.js failed:", err); sayWithPersona("you tried to eat but failed... somehow."); } };