PrismarineJS / mineflayer-pathfinder

Pathfinding plugin that gives bot the ability to go from A to B
MIT License
215 stars 68 forks source link

TypeError: movements.countScaffoldingItems is not a function #94

Closed XfedeX closed 3 years ago

XfedeX commented 3 years ago

Version of mineflayer-pathfinder: latest code:

const mineflayer = require('mineflayer');
const owner = process.argv[3] || "FedexxedeF"
const pass = process.argv[4];
const pvp = require('./mineflayer-pvp').plugin
const armor_manager = require("./mineflayer-armor-manager")

var isAttackingMobs = "false"

const pathfinder = require('mineflayer-pathfinder').pathfinder
const Movements = class Movements {
    constructor (bot, mcData) {
      this.bot = bot
      this.canDig = false
      this.digCost = 10
    }}
const { GoalNear, GoalBlock, GoalXZ, GoalY, GoalInvert, GoalFollow } = require('mineflayer-pathfinder').goals

const options = {
    host: process.argv[2],
    port: 25565,
    username: "Xbot",
    password: process.argv[4],
}

const bot = mineflayer.createBot(options)

bot.once('spawn', () => {

    bot.loadPlugin(pathfinder)
    bot.loadPlugin(pvp)

    // Once we've spawn, it is safe to access mcData because we know the version
    const mcData = require('minecraft-data')(bot.version)

    const movements = new Movements(bot, mcData)
    movements.canDig = false
    bot.pathfinder.setMovements(movements)

    bot.settings.viewDistance = "tiny"
    bot.chat('/login ' + pass)
    bot.chat('Xbot by Fede!')
    console.log("Connected")

 // We create different movement generators for different type of activity
    const defaultMove = new Movements(bot, mcData)

    //every 1 second go forward
    /*
    setInterval(function(){
        bot.setControlState("back", false)
        bot.setControlState("forward", true)
    },1000)
    setInterval(function(){
        bot.setControlState("forward", false)
        bot.setControlState("back", true)
    },1100)
    */
});

setInterval(() =>{
    if (isAttackingMobs === "false") return
    const mobFilter = e => e.type === "mob"
    const mob = bot.nearestEntity(mobFilter)

    if (!mob) return

    if (mob && mob.kind.toString().toLowerCase().includes('hostile')) {
        bot.pvp.attack(mob)
        }
},1000);

bot.on( "kicked", (reason, loggedIn) => {
    console.log("KICKED! "+ reason)
})
bot.on("chat", function(username, message) {

    const target = bot.players[username] ? bot.players[username].entity : null

    var pmessage = message.split(' ')

    if (message.split('_')[0] != "") { return }

    if (username === bot.username) return
    if (username != owner) {
        console.log("Player " + username + " had not enough permissions to execute command!")
        bot.whisper(username, "You got not enough permissions to execute this command!")
        return
    }

    if (message === "_come") {
        bot.chat('/teleport ' + bot.username + " " + username );
        bot.whisper(username, 'Teleported to ' + username);
        console.log("Teleported to " + username + "'s position");
    };
    if (message === "_follow") {
        if (!target) {
            bot.chat('I don\'t see you !')
            return
          }
        bot.whisper(username, 'Following you!');
        console.log("Following " + username );
        bot.pathfinder.setGoal(new GoalFollow(target, 3), true)
        console.log(bot.players[username].entity.position)
        isAttackingMobs = "false"
    };
    if (pmessage[0] === "_attack") {
        if (pmessage[1] === "hostiles") {
            isAttackingMobs = "true"
            console.log("Attacking Hostiles!")
            bot.chat("Attacking hostiles!")
        }
        else {
            const player = bot.players[pmessage[1]]
            if (!player) {
                bot.chat("I can't see "+ player)
                return
            }
            if (pmessage[1]) {
                bot.pvp.attack(player.entity)
              }
        }

    };
    /*
    if (message === '_fight') {
        const player = bot.players[username]

        if (!player) {
          bot.chat("I can't see you.")
          return
        }

        bot.chat('Prepare to fight!')
        bot.pvp.attack(player.entity)

    }*/
});

error: TypeError: movements.countScaffoldingItems is not a function at Object.bot.pathfinder.getPathTo (C:\Users\Toshiba\node_modules\mineflayer-pathfinder\index.js:56:97) at EventEmitter.monitorMovement (C:\Users\Toshiba\node_modules\mineflayer-pathfinder\index.js:259:42) at EventEmitter.emit (events.js:327:22) at Timeout.doPhysics [as _onTimeout] (C:\Users\Toshiba\node_modules\mineflayer\lib\plugins\physics.js:63:13) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7)

Karang commented 3 years ago

The problem is here:

const Movements = class Movements {
    constructor (bot, mcData) {
      this.bot = bot
      this.canDig = false
      this.digCost = 10
    }}

That's not how you inherit from a class. This is how: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Inheritance#Inheritance_with_class_syntax