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

Check entities by internal id if nothing is found by network id #430

Closed ArcticZeroo closed 7 years ago

ArcticZeroo commented 8 years ago

When connecting to the server us.mineplex.com, the bot instantly crashes as https://github.com/PrismarineJS/mineflayer/blob/master/lib/plugins/entities.js#L164 returns undefined for some custom spawned entities (not sure which). I was able to successfully connect the bot to the server with no apparent issues, but only after completely commenting out the 'spawn_entity_living' event.

Gjum commented 8 years ago

Can you post the packet contents please? It also contains the position with which you could figure out which entity is causing the issue.

ArcticZeroo commented 8 years ago

@Gjum this may be a rather basic question (haven't used this API too much) but... how? I don't see an event to log packets. Would I have to use the minecraft-protocol API?

Gjum commented 8 years ago

You can just add a console.log in that method you linked, and print the received packet.

ArcticZeroo commented 8 years ago

@Gjum I believe that this is the packet:

{ entityId: 13890616, type: 30, x: 0, y: -150, z: 0, yaw: 0, pitch: 0, headPitch: 0, velocityX: 0, velocityY: 0, velocityZ: 0, metadata: [ { type: 0, key: 10, value: 16 }, { type: 0, key: 3, value: 1 }, { type: 4, key: 2, value: '§r§a§lMineplex Player Servers' }, { type: 1, key: 1, value: 300 }, { type: 0, key: 0, value: 32 } ] }

(I got exactly 21 of these and I'm not sure if all of them were sent in one packet or what, I'll actually make a counter to check if they are in 1 sec)

EDIT: This is a separate packet, just checked.

Gjum commented 8 years ago

type: 30

Well there's no known entity with ID 30, see http://wiki.vg/Entities#Mobs

So either the server sends unexpected data (possibly to just display the nametag, to make a hologram message), or the entity list is incomplete.

ArcticZeroo commented 8 years ago

@Gjum I see, I'll contact a dev for the server and try to get to the bottom of this! Otherwise I'll just set an if statement for entities that aren't id 30 :P

Gjum commented 8 years ago

@rom1504 what would be a good fallback behaviour for unknown entity types?

roblabla commented 8 years ago

How does the notchian client react to unknown eid? On Jun 2, 2016 10:17 PM, "Gjum" notifications@github.com wrote:

@rom1504 https://github.com/rom1504 what would be a good fallback behaviour for unknown entity types?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/430#issuecomment-223408989, or mute the thread https://github.com/notifications/unsubscribe/ABBRBiKEL5mLI5QcV4GPVtCLs66GXp4zks5qHzpHgaJpZM4IstBO .

rom1504 commented 8 years ago

We should probably add an entity with an unknown type (fill the corresponding properties with empty values for example)

rom1504 commented 7 years ago

So apparently bukkit/spigot/whatever in us.mineplex spawn armor stand using the internal id 30. That's a custom behavior.

The "problem" is that the vanilla client understands it.

If we want to replicate the behavior of the vanilla client, we could check entities by their internal id if it cannot be found using the network id.