Почему функция крафта в mineflayer не работает?
Я создаю mineflayer бота с gpt но недавно столкнулся с проблемой - функция крафта просто отказывается работать, а в интернете нет ни одного нормального гайда на эту тему:
function craft(recipeName, count) {
const recipes = bot.recipesFor(recipeName); // Получаем рецепт
console.log("Найденные рецепты для крафта:", recipes);
if (recipes.length === 0) {
history.push({ role: "system", content: 'Рецепт не найден!' });
console.log("Рецепт не найден!");
return;
}
const recipe = recipes[0]; // Получаем первый рецепт
console.log("Требуемые ингредиенты рецепта:", recipe.ingredients);
// Проверка, что у бота есть все необходимые материалы
const materialsAvailable = Array.isArray(recipe.ingredients) && recipe.ingredients.every(ingredient => {
const inventoryItem = bot.inventory.items().find(item => item.name === ingredient.name);
return inventoryItem && inventoryItem.count >= ingredient.count;
});
if (!materialsAvailable) {
console.log(bot.inventory.items());
console.log('У бота недостаточно материалов для крафта.');
history.push({ role: "system", content: 'У бота недостаточно материалов для крафта.' });
return;
}
// Открытие крафтового меню (внутреннего окна бота)
bot.openCraftingTable((err, craftingTable) => {
if (err) {
console.log("Ошибка при открытии крафтового меню:", err);
return;
}
console.log("Крафтовое меню открыто.");
// Заполнение крафтовой сетки (4 слота)
const grid = craftingTable.slots.slice(0, 4); // Получаем первые 4 слота для ингредиентов
recipe.ingredients.forEach((ingredient, index) => {
const inventoryItem = bot.inventory.items().find(item => item.name === ingredient.name);
if (inventoryItem) {
bot.putInSlot(grid[index], inventoryItem, (err) => {
if (err) {
console.log("Ошибка при размещении ингредиента в сетке:", err);
}
});
}
});
// Запуск крафта
craftingTable.craft(recipe, count, (err) => {
if (err) {
console.log("Ошибка при крафте:", err);
history.push({ role: "system", content: 'Ошибка при крафте!' });
} else {
console.log("Крафт завершён успешно.");
history.push({ role: "system", content: 'Крафт завершён успешно.' });
}
});
});
}
Вот полный код: https://pastebin.com/huXnA5Ht Ожидалось что бот скрафтит верстак из предметов в его инвентаре но вот вывод консоли:
Получено сообщение: скрафти верстак
Ответ от GPT: {
"id": "chatcmpl-AShOfyCrt2ftKY7IGZz1AJ716Crx7",
"object": "chat.completion",
"created": 1731403365,
"model": "gpt-4o-mini-2024-07-18",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"function_call": {
"name": "craft",
"arguments": "{\"item\":\"crafting_table\",\"amount\":1}"
},
"refusal": null
},
"logprobs": null,
"finish_reason": "function_call"
}
],
"usage": {
"prompt_tokens": 703,
"completion_tokens": 20,
"total_tokens": 723,
"prompt_tokens_details": {
"cached_tokens": 0,
"audio_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 0,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
}
},
"system_fingerprint": "fp_9b78b61c52"
}
crafting_table
1
Найденные рецепты для крафта: []
Рецепт не найден!
GPTChel крафтит: crafting_table
^C