So I´ve been trying to make a bot that followes my Minecraft character (playerCI = bot.players["Cyberyes"])
, but when I try to start it, I get this error:
Starting... C:\Users\Jakob\Documents\Minecraft\Bot\FirstBot\node_modules\mineflayer-pathfinder\lib\movements.js:35 this.blocksCantBreak.add(mcData.blocksByName.chest.id) ^
TypeError: Cannot read properties of undefined (reading 'blocksByName') at new Movements (C:\Users\Jakob\Documents\Minecraft\Bot\FirstBot\node_modules\mineflayer-pathfinder\lib\movements.js:35:37) at EventEmitter.followPlayer (C:\Users\Jakob\Documents\Minecraft\Bot\FirstBot\main.js:28:23) at Object.onceWrapper (node:events:509:28) at EventEmitter.emit (node:events:402:35) at Client. (C:\Users\Jakob\Documents\Minecraft\Bot\FirstBot\node_modules\mineflayer\lib\plugins\health.js:13:11) at Object.onceWrapper (node:events:510:26) at Client.emit (node:events:402:35) at FullPacketParser. (C:\Users\Jakob\Documents\Minecraft\Bot\FirstBot\node_modules\minecraft-protocol\src\client.js:91:12) at FullPacketParser.emit (node:events:390:28) at addChunk (C:\Users\Jakob\Documents\Minecraft\Bot\FirstBot\node_modules\readable-stream\lib_stream_readable.js:298:12)
This is my Code:
console.log("Starting...")
const mineflayer = require('mineflayer')
const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
const GoalFollow = goals.GoalFollow
var settings = {
username: "Bot",
host: "185.245.96.138",
port: "25592",
version: "1.16.5",
}
const bot = mineflayer.createBot(settings)
bot.loadPlugin(pathfinder)
function followPlayer() {
const playerCI = bot.players['Cyberyes']
if (!playerCI || !playerCI.entity) {
bot.chat("I can't see Cyberyes!")
return
}
const mcData = require('minecraft-data')(bot.version)
const movements = new Movements(bot, mcData)
bot.pathfinder.setMovements(movements)
const goal = new GoalFollow(playerCI.entity, 1)
bot.pathfinder.setGoal(goal, true)
}
bot.once("spawn", followPlayer)
I had the same Error I could Fix this, with a funktion like this My code is in Python, but shouldnt be much diffrent JavaScript
def initMovement():
movements = pathfinder.Movements(bot)
#If you want to Deactivate sth
movements.canDig = False
bot.pathfinder.setMovements(movements)
this funktion is called after the bot is spawned