PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.96k stars 904 forks source link

help #2815

Closed ChamsBypass closed 1 year ago

ChamsBypass commented 1 year ago
const mineflayer = require('mineflayer');
const color = require('chalk');
const config = require('./config.json');
const v = require('vec3')
const { pathfinder, Movements } = require('mineflayer-pathfinder');
const { GoalNear } = require('mineflayer-pathfinder').goals;
const bot = mineflayer.createBot({ username: name ,host:host,port:port,version:'1.12.2'}); //there reals strings but i replace
bot.loadPlugin(pathfinder)
bot.on('login',() => {
  setTimeout(() => {
    bot.chat('/login password password');
    const customMoves = new Movements(bot);
    bot.pathfinder.setMovements(customMoves); 
    bot.pathfinder.setGoal(new GoalNear(-1042.228, 32, 690.588, 1));
    let npc = bot.entities['§3Anarchy'];
    bot.activateEntity(npc);
  }, 1000);
})
    await bot.lookAt(entity.position.offset(0, 1, 0), false)
                            ^

TypeError: Cannot read properties of undefined (reading 'position')
    at EventEmitter.activateEntity (C:\Users\comp\node_modules\mineflayer\lib\plugins\inventory.js:205:29)
    at Timeout._onTimeout (C:\Users\comp\Documents\bot\bot.js:17:9)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)

Why?

extremeheat commented 1 year ago

bot.activateEntity is being called with a null argument. Make sure it's not null and it should work.

As a tip, you can format code by clicking on the code button on the editor next time

ChamsBypass commented 1 year ago

thanks