PrismarineJS / mineflayer-pvp

Adds support for basic PVP and PVE to Mineflayer bots.
MIT License
51 stars 20 forks source link

TypeError: Cannot read property 'y' of undefined #22

Closed d-513 closed 3 years ago

d-513 commented 3 years ago

My full code:

import mineflayer from "mineflayer";
import viewer from "prismarine-viewer";
import nconf from "nconf";
import pvp from "mineflayer-pvp";
import pathfinder from "mineflayer-pathfinder"

nconf.argv().env().file("config.json").defaults({
  prefix: "!",
});

const types = {
  ENDERMAN: 20,
};

console.log("Creating bot...");
const bot = mineflayer.createBot({
  username: nconf.get("username"),
  password: nconf.get("password"),
  host: nconf.get("host"),
  port: nconf.get("port"),
});

bot.loadPlugin(pathfinder.pathfinder)
bot.loadPlugin(pvp.plugin);

bot.on("chat", (username, message) => {
  //if(username === bot.username) return
  if (message.startsWith("exp")) {
    bot.chat("Zaczynam expic endermany");
    console.log(username, message);
    const recurse = () => {
      const enderman = bot.nearestEntity(
        (e) => e.entityType === types.ENDERMAN
      );
      console.log(enderman);
      bot.pvp.attack(enderman)
      bot.on("stoppedAttacking", recurse)
    };
    recurse();
  }
});

bot.once("spawn", () => {
  console.log("Spawned!");
  viewer.mineflayer(bot, { port: 5000, firstPerson: true });
});

When typing 'exp' in chat, the bot crashes with this error:

TypeError: Cannot read property 'y' of undefined
    at Movements.getBlock (/config/workspace/mc_exp_bot/node_modules/mineflayer-pathfinder/lib/movements.js:81:21)
    at Movements.safeToBreak (/config/workspace/mc_exp_bot/node_modules/mineflayer-pathfinder/lib/movements.js:101:16)
    at Movements.safeOrBreak (/config/workspace/mc_exp_bot/node_modules/mineflayer-pathfinder/lib/movements.js:113:15)
    at Movements.getMoveForward (/config/workspace/mc_exp_bot/node_modules/mineflayer-pathfinder/lib/movements.js:178:18)
    at Movements.getNeighbors (/config/workspace/mc_exp_bot/node_modules/mineflayer-pathfinder/lib/movements.js:339:12)
    at AStar.compute (/config/workspace/mc_exp_bot/node_modules/mineflayer-pathfinder/lib/astar.js:76:40)
    at Object.bot.pathfinder.getPathTo (/config/workspace/mc_exp_bot/node_modules/mineflayer-pathfinder/index.js:39:84)
    at Bot.monitorMovement (/config/workspace/mc_exp_bot/node_modules/mineflayer-pathfinder/index.js:210:26)
    at Bot.emit (events.js:326:22)
    at Timeout.doPhysics [as _onTimeout] (/config/workspace/mc_exp_bot/node_modules/mineflayer/lib/plugins/physics.js:62:13)

I have carefull read the error, but can't see how it relates to my code. I think this is an internal bug, but I don't know.

ENV: ubuntu docker container with node 12

TheDudeFromCI commented 3 years ago

This bug is caused by the pathfinder plugin dependency. https://github.com/PrismarineJS/mineflayer-pathfinder/issues/53

d-513 commented 3 years ago

Thanks, closing