Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading 'passengers') #3576

Open
TheRealPerson98 opened this issue Jan 31, 2025 · 8 comments
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f

Comments

@TheRealPerson98
Copy link

Versions

  • mineflayer: Latest
  • server: vanilla/spigot/paper Latest
  • node: 22.13.1

When joining some servers that have books / or nothing sometimes on join u get

lib\plugins\entities.js:841

TypeError: Cannot read properties of undefined (reading 'passengers')
    at Client.<anonymous> (C:\ops/mineflayer\lib\plugins\entities.js:841:17)
    at Client.emit (node:events:517:28)
    at emitPacket (C:\opsminecraft-protocol\src\client.js:84:12)
    at Array.forEach (<anonymous>)
    at FullPacketParser.<anonymous> (C:REDACTEDnode_modules\minecraft-protocol\src\client.js:99:26)
    at FullPacketParser.emit (node:events:517:28)
    at addChunk (C:REDACTEDnode_modules\readable-stream\lib\internal\streams\readable.js:323:12)
    at readableAddChunk (C:REDACTEDnode_modules\readable-stream\lib\internal\streams\readable.js:300:9)
    at Readable.push (C:REDACTEDnode_modules\readable-stream\lib\internal\streams\readable.js:246:10)
    at FullPacketParser._transform (C:REDACTEDnode_modules\protodef\src\serializer.js:89:10)

also a null on getting the servers dim but i don't have that error

closed my pull i don't have the time to dig deeper into the issue

@TheRealPerson98 TheRealPerson98 added possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f labels Jan 31, 2025
@bowoflare
Copy link

I am running into this same issue, do you know any fixes?

@TheRealPerson98
Copy link
Author

I just forked it and added null checks to it bc nothing im doing is using passengers

@notegorkaa
Copy link

which minecraft version?

@mrab54
Copy link

mrab54 commented Feb 2, 2025

I'm seeing this on 1.21 java

@hilbix
Copy link

hilbix commented Feb 3, 2025

Same for MC 1.20.4, Mineflayer 4.26.0, Node.js v18.19.0. Downgrade to 4.25 works:

package.json:

{
  "dependencies":
    { "mineflayer": "=4.25.0"
    }
}

Following code:

#!/usr/bin/env nodejs
'use strict';

const mineflayer = require('mineflayer');
const B = mineflayer.createBot({ host:'127.0.0.1', username:'t', hideErrors:false });
const D = console.error;
B.once('spawn', () => D('spawn', B.version));
B.once('end',   () => process.exit(D('END')));

If I replace the = with ^ in package.json (and then npm update), it crashes within 1 minute. (Note that I have some entities in Minecarts.)

@DatArnoGuy
Copy link
Contributor

This is happening to me too. MC 1.21.4, online mode server, NodeJS v22.13.1, mineflayer 4.26.0

@deinemuttermitbutter
Copy link

happens to me too, nodejs: 22.13.1 ; mineflayer: 4.26.0 ; minecraft: 1.21.4 ; device: raspberry pi

@soswi
Copy link

soswi commented Feb 4, 2025

So it was bugging in my case because a server allowed to ride other players so it didn't know what to do with it. I've rewrited that listener and it works now.

bot._client.on('set_passengers', ({ entityId, passengers }) => {
    if (!passengers || !Array.isArray(passengers)) {
        console.warn("[WARN] `passengers` is undefined or not an array for entityId:", entityId);
        return;
    }

    const passengerEntities = passengers
        .map(passengerId => bot.entities[passengerId] || null) // Chechking if they exist
        .filter(entity => entity !== null); // We get rid of null

    const vehicle = bot.entities[entityId] || null; // Checking if vehicles exist

    for (const passengerEntity of passengerEntities) {
        if (!passengerEntity) continue; // We skip if they don't exist

        const originalVehicle = passengerEntity.vehicle;
        if (originalVehicle && originalVehicle.passengers) {
            const index = originalVehicle.passengers.indexOf(passengerEntity);
            if (index !== -1) {
                originalVehicle.passengers.splice(index, 1);
            }
        }
        passengerEntity.vehicle = vehicle;

        if (vehicle) {
            if (!vehicle.passengers) vehicle.passengers = []; // We make sure that `passengers` exist
            vehicle.passengers.push(passengerEntity);
        }
    }

    if (passengers.includes(bot.entity.id)) {
        const originalVehicle = bot.vehicle;
        if (entityId === -1) {
            bot.vehicle = null;
            bot.emit('dismount', originalVehicle);
        } else {
            bot.vehicle = bot.entities[entityId] || null;
            bot.emit('mount');
        }
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f
Projects
None yet
Development

No branches or pull requests

8 participants