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

message event doesn't contain the position field #1312

Closed nisutec closed 4 years ago

nisutec commented 4 years ago

Versions

Detailed description of a problem

The default “Minecraft ChatMessagePacket“ has three position values.

CHAT = 0 # A player-initiated chat message.
SYSTEM = 1 # The result of running a command.
GAME_INFO = 2 # Displayed above the hotbar in vanilla clients.

At the moment the “message” event will trigger on all three positions. And the “jsonMsg” Object has no type or position identifier to identify a specific message type.

What did you try yet?

I have tried to find an identifier in the “jsonMsg” Object to identify the massage position

Your current code


bot.on('message', function (jsonMsg) {
    console.log(jsonMsg)
    }
})

Expected behavior

A possibility to identify the position of a message to exclude “GAME_INFO” messages from this event.

Additional context

All “jsonMsg” Objects have the same format it is not possible to show differences only with the row json body.

Karang commented 4 years ago

you can get the chat packet event directly and access the position property : https://github.com/PrismarineJS/mineflayer/blob/master/lib/plugins/chat.js#L42

rom1504 commented 4 years ago

https://minecraft-data.prismarine.js.org/?d=protocol#toClient_chat that's the chat packet can you add the position (and maybe sender) field to the mineflayer event so other people will be able to use that too?

nisutec commented 4 years ago

This works thanks for the help @Karang