Mail.ruПочтаМой МирОдноклассникиВКонтактеИгрыЗнакомстваНовостиКалендарьОблакоЗаметкиВсе проекты

Помогите решить проблему в коде, хочу сделать бота-игрока который может копать руды в Minecraft

Владислав Оськин Ученик (71), открыт 1 неделю назад
Код писал Chat Gpt, сто раз его якобы фиксил, в итоге WebStorm всё равно ругается, без понятия че ему надо. Список ошибок под кодом.


const mineflayer = require('mineflayer');
const { Vec3 } = require('vec3');

const bot = mineflayer.createBot({
host: 'localhost',
port: 53295,
username: 'имя_бота'
});

const { Pathfinder } = require('mineflayer-pathfinder');
const pathfinderGoal = new Pathfinder(bot);

bot.on('chat', (username, message) => {
if (message === 'копай') {
bot.chat('окей');

let targetBlock = bot.findBlock({
point: bot.entity.position,
matching: (block) => {
return block.name === 'diamond_ore' ||
block.name === 'redstone_ore' ||
block.name === 'iron_ore' ||
block.name === 'gold_ore' ||
block.name === 'lapis_ore' ||
block.name === 'emerald_ore' ||
block.name === 'coal_ore';
}
});

if (targetBlock) {
const path = pathfinderGoal.findPath(targetBlock.position);
if (path) {
bot.once('path_update', () => {
if (bot.pathfinder.isFinished()) {
const position = new Vec3(targetBlock.position.x + 0.5, targetBlock.position.y + 0.5, targetBlock.position.z + 0.5);
bot.lookAt(position);
bot.dig(targetBlock);
}
});
bot.pathfinder.setGoal(new Pathfinder.GoalBlock(targetBlock.position.x, targetBlock.position.y, targetBlock.position.z));
}
} else {
bot.chat('Не могу найти руды рядом.');
}
}
});



Ошибки:
Interface cannot be instantiated
Invalid number of arguments, expected 0
Unresolved variable name (7 раз)
Unresolved function or method findPath()
Unresolved function or method isFinished()
Promise returned from lookAt is ignored
Promise returned from dig is ignored :37
Unresolved function or method setGoal()
Unresolved type GoalBlock :40
Unresolved variable position :40 (3 раза)
Unresolved variable position :35 (3 раза)
1 ответ
Евгений Кегулихес Профи (897) 1 неделю назад
Интерфейс не может быть создан: Проблема здесь в том, что Pathfinder не является конструктором, который можно создать. Вам нужно использовать Pathfinder, который создается для вашего бота вот так:


 const pathfinder = require('mineflayer-pathfinder').pathfinder; 


Неверное количество аргументов, ожидался 0: Это ошибка возникает из-за того, что вы пытаетесь создать бота с неправильными аргументами. Вместо point вы должны использовать start.
Неопределенная переменная pathfinderGoal: Вы не объявили переменную pathfinderGoal. Вам нужно использовать переменную pathfinder.
Неопределенная переменная pathfinderGoal.findPath: Так как pathfinderGoal не объявлен, у вас нет функции findPath.
Неопределенная переменная bot.pathfinder.isFinished: Путь у вашего бота не является обещанием, поэтому метод isFinished() недоступен. Вместо этого используйте событие goal_reached.
Обещание, возвращенное из lookAt, игнорируется: Вам нужно обработать это обещание с помощью .then(), чтобы избежать этой ошибки.
Обещание, возвращенное из dig, игнорируется: Также обработайте это обещание, чтобы избежать ошибки.
Неопределенная функция или метод setGoal(): Используйте pathfinder.setMovements(bot.mcData) вместо setGoal.
Неопределенный тип GoalBlock: GoalBlock это часть pathfinder, поэтому используйте pathfinder.GoalBlock.
Неопределенная переменная position: Вы должны объявить position как const перед использованием


Горе-Кодер, поeбaлся с твоим кодом, и получил вроде как рабочий:


 const mineflayer = require('mineflayer'); 
const { Vec3 } = require('vec3');
const pathfinder = require('mineflayer-pathfinder').pathfinder;

const bot = mineflayer.createBot({
host: 'localhost',
port: 53295,
username: 'имя_бота'
});

const mcData = require('minecraft-data')(bot.version);

bot.loadPlugin(pathfinder);

bot.on('chat', (username, message) => {
if (message === 'копай') {
bot.chat('окей');

let targetBlock = bot.findBlock({
matching: ['diamond_ore', 'redstone_ore', 'iron_ore', 'gold_ore', 'lapis_ore', 'emerald_ore', 'coal_ore']
});

if (targetBlock) {
const path = bot.pathfinder.getPathTo(targetBlock.position);
if (path) {
bot.pathfinder.setMovements(bot.mcData);
bot.pathfinder.setGoal(new pathfinder.GoalBlock(targetBlock.position.x, targetBlock.position.y, targetBlock.position.z));
bot.once('goal_reached', () => {
const position = new Vec3(targetBlock.position.x + 0.5, targetBlock.position.y + 0.5, targetBlock.position.z + 0.5);
bot.lookAt(position);
bot.dig(targetBlock);
});
}
} else {
bot.chat('Не могу найти руды рядом.');
}
}
});
Похожие вопросы