首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法访问对象内的地雷飞行探测仪

无法访问对象内的地雷飞行探测仪
EN

Stack Overflow用户
提问于 2022-02-02 20:24:36
回答 1查看 105关注 0票数 0

以下是nodejs中的所有代码

代码语言:javascript
复制
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还告诉我,‘探路者’是在代码的顶部声明的,但它的值从来没有被读取过,我看过一些视频,这应该是可行的,但它就是不能工作,可能是因为我在一个对象中。

我现在使用的是最新版本的雷飞机。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-03 00:37:16

探路者是一个雷炸机插件,这意味着它必须加载。我忘了写

代码语言:javascript
复制
this.mineflayer.loadPlugin(pathfinder)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70962410

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档