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

How can I intercept a velocity packet from the server? #743

Closed ghost closed 5 years ago

ghost commented 5 years ago

Can I listen for a setVelocity packet from the server?

And check the vector that the server is telling the bot to set its velocity to?

rom1504 commented 5 years ago

the velocity is already available as bot.entity.velocity

ghost commented 5 years ago

@rom1504 isn't that a client-side thing?

I am specifically interested in intercepting the knockback package sent by the server.

I'm assuming the server's plugins use Bukkit's Player#setVelocity(Vector) to tell the player how they should be knocked back.

I'd like to be able to add a listener for the packet generated by this to see the values the server plugins are telling my bot to set its velocity to.

rom1504 commented 5 years ago

No it's not, that value is set by the entity_velocity packet which mineflayer listen on to set bot.entity.velocity

On Mon, Nov 12, 2018, 03:08 George notifications@github.com wrote:

@rom1504 https://github.com/rom1504 isn't that a client-side thing?

I am specifically interested in intercepting the knockback package sent by the server.

I'm assuming the server's plugins use Bukkit's Player#setVelocity(Vector) to tell the player how they should be knocked back.

I'd like to be able to add a listener for the packet generated by this to see the values the server plugins are telling my bot to set its velocity to.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/743#issuecomment-437730458, or mute the thread https://github.com/notifications/unsubscribe-auth/ACPN_v_bhAnToX3B7zgR8IE3F06RMgUTks5uuNg6gaJpZM4YYuxj .

ghost commented 5 years ago

@rom1504 is there an event that gets fired when the server changes that value?

Also, I couldn't find any documentation on it. Entity#velocity is an empty section in the documentation.

Do you know what "type" bot.entity.velocity has?

ghost commented 5 years ago

Am I allowed to access the bot._client object from my own code? it looks kind of sneaky with that underscore

bot._client.on('entity_velocity', (packet) => {
    // entity velocity
    const entity = fetchEntity(packet.entityId)
    const notchVel = new Vec3(packet.velocityX, packet.velocityY, packet.velocityZ)
    entity.velocity.update(conv.fromNotchVelocity(notchVel))
})
rom1504 commented 5 years ago

You can, and if you manage to get something useful that mineflayer doesn't currently provide, please pr it in mineflayer code so everybody can use it ;)

On Mon, Nov 12, 2018, 10:24 George notifications@github.com wrote:

Am I allowed to access the bot._client object from my own code? it looks kind of sneaky with that underscore

bot._client.on('entity_velocity', (packet) => { // entity velocity const entity = fetchEntity(packet.entityId) const notchVel = new Vec3(packet.velocityX, packet.velocityY, packet.velocityZ) entity.velocity.update(conv.fromNotchVelocity(notchVel)) })

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/743#issuecomment-437811279, or mute the thread https://github.com/notifications/unsubscribe-auth/ACPN_nMOA3PD98nOBo-xOv7lTjJIWZMeks5uuT44gaJpZM4YYuxj .