以下是nodejs中的所有代码
const mineflayer = require('mineflayer')
const { pathfinder, Movements, goals } = require('mineflayer-pathfinder');
const GoalFollow = goals.GoalFollow
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
class bot{
constructor(name, ip, port){
this.name = name;
this.ip = ip;
this.port = port
this.minebot = mineflayer.createBot({
host: this.ip,
username: this.name,
port: this.port
})
this.minebot.on('spawn', () => {
for(let i = 0; i < 1; i++){
this.minebot.chat(this.name);
this.followPlayer('Squisheyyy')
}
})
this.minebot.on('kicked', () => {
console.log('Connection closed, retrying');
new bot(this.name, this.ip, this.port);
delete this;
});
this.minebot.on('error', () => {
console.log('Connection closed, retrying');
new bot(this.name, this.ip, this.port);
delete this;
});
}
followPlayer(name){
const playerCI = this.minebot.players[name];
if(!playerCI){
bot.chat('I dont see him');
return;
}
const mcData = require('minecraft-data')(this.minebot.version);
const movements = new Movements(this.minebot, mcData);
this.minebot.pathfinder.setMovements(movements);
const goal = new GoalFollow(playerCI.entity, 1);
this.minebot.pathfinder.setGoal(goal, true);
}
}
new bot('bot', 'ip', PORT)下面是这个问题的行this.minebot.pathfinder.setMovements(movements);错误:TypeError: Cannot read properties of undefined (reading 'setMovements')
它说探路者是未定义的,IDE还告诉我,‘探路者’是在代码的顶部声明的,但它的值从来没有被读取过,我看过一些视频,这应该是可行的,但它就是不能工作,可能是因为我在一个对象中。
我现在使用的是最新版本的雷飞机。
发布于 2022-02-03 00:37:16
探路者是一个雷炸机插件,这意味着它必须加载。我忘了写
this.mineflayer.loadPlugin(pathfinder)https://stackoverflow.com/questions/70962410
复制相似问题