Skip to content

bot.registry is undefined and causes the pathfinder plugin to fail loading #350

@hunterzolomon1

Description

@hunterzolomon1

i've read every stackoverflow.com posts and even found one with the same issue as me but nobody had answered it.

all i understood was that the way to fix this is to wait like 3 - 4 seconds so the bot will take time to initialize bot.registry

i even tried this but nothing happened
i've had no issue like this before these days and this code was working without errors

const mineflayer = require('mineflayer')
const pathfinder = require('mineflayer-pathfinder')
const bot = mineflayer.createBot({ username: 'myBot', host:"localhost", port:1 })

bot.once('spawn', () => {
  const mcData = require('minecraft-data')(bot.version)

bot.loadPlugin(pathfinder.pathfinder)
})

error:

C:\Users\zolomon\Desktop\workspaces\workspace 9 minecraft\node_modules\mineflayer-pathfinder\index.js:16
  const waterType = bot.registry.blocksByName.water.id
                                 ^

TypeError: Cannot read properties of undefined (reading 'blocksByName')
    at inject (C:\Users\zolomon\Desktop\workspaces\workspace 9 minecraft\node_modules\mineflayer-pathfinder\index.js:16:34)
    at EventEmitter.loadPlugin (C:\Users\zolomon\Desktop\workspaces\workspace 9 minecraft\node_modules\mineflayer\lib\plugin_loader.js:25:7)
    at EventEmitter.<anonymous> (C:\Users\zolomon\Desktop\workspaces\workspace 9 minecraft\test.js:8:5)
    at Object.onceWrapper (node:events:632:28)
    at EventEmitter.emit (node:events:530:35)
    at Client.<anonymous> (C:\Users\zolomon\Desktop\workspaces\workspace 9 minecraft\node_modules\mineflayer\lib\plugins\health.js:13:11)
    at Object.onceWrapper (node:events:633:26)
    at Client.emit (node:events:530:35)
    at emitPacket (C:\Users\zolomon\Desktop\workspaces\workspace 9 minecraft\node_modules\minecraft-protocol\src\client.js:84:12)
    at FullPacketParser.<anonymous> (C:\Users\zolomon\Desktop\workspaces\workspace 9 minecraft\node_modules\minecraft-protocol\src\client.js:113:9)

Node.js v22.14.0

i also found that when my bot joins my lan world there must be a registry property defined for my bot but now there's not anymore

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions