PrismarineJS / mineflayer

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

Bug: TypeError: Cannot read properties of undefined (reading 'blocksByName') #2972

Closed SonicandTailsCD closed 1 year ago

SonicandTailsCD commented 1 year ago

Versions

Detailed description of a problem

A clear and concise description of what the problem is, with as much context as possible. Well...

TypeError: Cannot read properties of undefined (reading 'blocksByName') at new Movements (/Users/adm/Desktop/Bot/node_modules/mineflayer-pathfinder/lib/movements.js:38:37) at EventEmitter. (/Users/adm/Desktop/Bot/bot.js:18:23) at Object.onceWrapper (node:events:641:28) at EventEmitter.emit (node:events:539:35) at Client. (/Users/adm/Desktop/Bot/node_modules/mineflayer/lib/plugins/health.js:13:11) at Object.onceWrapper (node:events:642:26) at Client.emit (node:events:539:35) at FullPacketParser. (/Users/adm/Desktop/Bot/node_modules/minecraft-protocol/src/client.js:91:12) at FullPacketParser.emit (node:events:527:28) at addChunk (/Users/adm/Desktop/Bot/node_modules/protodef/node_modules/readable-stream/lib/_stream_readable.js:279:12)

Node.js v17.9.0

What are you building? A following script What problem are you trying to solve? Running the script

What did you try yet?

Did you try any method from the API? No.. I have no idea how to :( Did you try any example? Yes, I did Any error from those? Yes, the same error.

Your current code


// Here I tell node.js mineflayer and a few other plugins are required to load
const mineflayer = require('mineflayer')
const { pathfinder, Movements, goals: { GoalNear } } = require('mineflayer-pathfinder')
// Here, we set up the server connection (in this case, my skin plugin server)
const bot = mineflayer.createBot({
    host: 'SonicJavaBots.aternos.me',
    port: '37867',
    username: "SonicandTailsCDb",
    version: '1.18.2'
})

// Now here comes the fun part: the coding. This is the AI, basically.
const RANGE_GOAL = 1 // get within this radius of the player

bot.loadPlugin(pathfinder)
const mcData = require('minecraft-data')(bot.version)
bot.once('spawn', () => {
  const defaultMove = new Movements(bot)

  bot.on('chat', (username, message) => {
    if (username === bot.username) return
    if (message !== 'come') return
    const target = bot.players[username]?.entity
    if (!target) {
      bot.chat("I don't see you !")
      return
    }
    const { x: playerX, y: playerY, z: playerZ } = target.position

    bot.pathfinder.setMovements(defaultMove)
    bot.pathfinder.setGoal(new GoalNear(playerX, playerY, playerZ, RANGE_GOAL))
  })
})

Expected behavior

I expected the bot to join, stay online and when I said "come", the bot would come. Now I would've used command blocks to move the bot and make it follow me, but the server would kick the bot after a while.

Additional context

Add any other context about the problem here. No thanks.

extremeheat commented 1 year ago

Did you make sure your dependencies are up to date? You can do so with npm update --depth 9999

SonicandTailsCD commented 1 year ago

I'll check right away!

SonicandTailsCD commented 1 year ago

So, I just ran the command. I'm starting the server to find out if that worked.

SonicandTailsCD commented 1 year ago

Nope! Still crashed.

extremeheat commented 1 year ago

cc @IceTank, I don't see anything obviously wrong here.

extremeheat commented 1 year ago

Delete your node_modules folder, your package-lock.json and install your dependencies again.

If that does not work, run npm list --prod --depth=1 and provide the output of that command

SonicandTailsCD commented 1 year ago

Alright, thanks! I'll do that right away :)

SonicandTailsCD commented 1 year ago

Okay! I ran npm update and that didn't work. (It did reinstall the packages tho). Here's the requested command output: npm WARN config production Use--omit=devinstead. sonicbot@1.0.0 /Users/adm/Desktop/Bot ├── chalk@5.2.0 ├─┬ mineflayer-pathfinder@1.10.0 │ ├── minecraft-data@2.221.0 │ ├── prismarine-block@1.16.3 │ ├── prismarine-entity@2.2.0 │ ├── prismarine-item@1.12.1 │ ├── prismarine-nbt@2.2.1 │ ├── prismarine-physics@1.6.0 │ └── vec3@0.1.8 ├─┬ mineflayer@4.8.1 │ ├── minecraft-data@3.30.0 │ ├── minecraft-protocol@1.41.1 │ ├── prismarine-biome@1.3.0 │ ├── prismarine-block@1.16.3 deduped │ ├── prismarine-chat@1.8.0 │ ├── prismarine-chunk@1.33.0 │ ├── prismarine-entity@2.2.0 deduped │ ├── prismarine-item@1.12.1 deduped │ ├── prismarine-nbt@2.2.1 deduped │ ├── prismarine-physics@1.6.0 deduped │ ├── prismarine-recipe@1.3.1 │ ├── prismarine-registry@1.7.0 │ ├── prismarine-windows@2.6.1 │ ├── prismarine-world@3.6.1 │ ├── protodef@1.15.0 │ ├── typed-emitter@1.4.0 │ └── vec3@0.1.8 deduped └─┬ prismarine-viewer@1.24.0 ├── @tweenjs/tween.js@18.6.4 ├── compression@1.7.4 ├── express@4.18.2 ├── minecraft-data@3.30.0 deduped ├── prismarine-block@1.16.3 deduped ├── prismarine-chunk@1.33.0 deduped ├── prismarine-world@3.6.1 deduped ├── socket.io-client@4.6.1 ├── socket.io@4.6.1 ├── three.meshline@1.4.0 ├── three@0.128.0 └── vec3@0.1.8 deduped

extremeheat commented 1 year ago

npm un mineflayer-pathfinder npm install mineflayer-pathfinder

This is caused by using an outdated major version of pathfinder.

SonicandTailsCD commented 1 year ago

Hm... let's see

SonicandTailsCD commented 1 year ago

Thanks bud! This worked :)