PrismarineJS / mineflayer

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

Velocity of other entities don't get updated correctly #3289

Open zardoy opened 7 months ago

zardoy commented 7 months ago

Versions

Detailed description of a problem

Velocity of other entities don't get updated in some cases. For example if you push another player the bot.entities["id"].velocity.z or x won't be 0 even if it stays on the same place. However bot.entity.velocity does always seem to work correctly. Is this a known limitation?

rom1504 commented 7 months ago

https://github.com/PrismarineJS/mineflayer/blob/298d4425424f94907c5602bfd6011ee6030b5ae2/lib/plugins/entities.js#L272 update is happening there

Idk if there are other packets or if the client is supposed to run the physics based on previous positions

GenerelSchwerz commented 7 months ago

I did some looking into this and entities are updated via rel_entity_move, which provides the positional data and not velocity iirc.

zardoy commented 7 months ago

entities are updated via rel_entity_move, which provides the positional data and not velocity

And also stable api does not fire any event in this case so it's unclear how to get an event of updating the velocity

rom1504 commented 7 months ago

So sounds like mineflayer would need to recompute the velocity if you want it to be continuously updated

On Mon, Jan 22, 2024, 2:18 PM Vitaly @.***> wrote:

entities are updated via rel_entity_move, which provides the positional data and not velocity

And also stable api does not fire any event in this case so it's unclear how to get an event of updating the velocity

— Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/3289#issuecomment-1903990168, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437UVATEIVGGXTCGYRJDYPZRLBAVCNFSM6AAAAABCFCGHECVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBTHE4TAMJWHA . You are receiving this because you commented.Message ID: @.***>

GenerelSchwerz commented 7 months ago

entities are updated via rel_entity_move, which provides the positional data and not velocity

And also stable api does not fire any event in this case so it's unclear how to get an event of updating the velocity

That isn't completely true: https://github.com/PrismarineJS/mineflayer/blob/298d4425424f94907c5602bfd6011ee6030b5ae2/lib/plugins/entities.js#L288 exposed "entityMoved" that would allow you to calculate the velocity differential. However, I recall attempting to do what you are trying to do; this event fires every 100ms, meaning velocity cannot be correctly calculated per tick.

zardoy commented 7 months ago

exposed "entityMoved" that would allow you to calculate the velocity differential. However, I recall attempting to do what you are trying to do; this event fires every 100ms, meaning velocity cannot be correctly calculated per tick.

Sorry I didn't notice that question was for me. I wanted it to use to display entities with different colors based on its velocity (like idle, walking or sprinting) on minimap. entityMoved would be enough for me if I could get the correct velocity of any entity. Or you mean I should calculate it myself by using this event?

GenerelSchwerz commented 7 months ago

exposed "entityMoved" that would allow you to calculate the velocity differential. However, I recall attempting to do what you are trying to do; this event fires every 100ms, meaning velocity cannot be correctly calculated per tick.

Sorry I didn't notice that question was for me. I wanted it to use to display entities with different colors based on its velocity (like idle, walking or sprinting) on minimap. entityMoved would be enough for me if I could get the correct velocity of any entity. Or you mean I should calculate it myself by using this event?

To my knowledge, and I have tried pretty extensively at doing what you described (see https://github.com/nxg-org/mineflayer-tracker), it is impossible to get an accurate velocity of entities server side without interpolation that would constantly need to be corrected. (Namely for players, their yaw/pitch cannot be predicted). You can use the average positional changes you receive from entityMoved to create your own pseudo-velocity that would be able to differentiate between standing, walking, and moving, but you cannot use it to predict the next physics step forward of server entities.

If you have questions about the code I linked (as it has no README), I can explain what I do to predict probable velocities of entities given in the discord.

zardoy commented 6 months ago

I forgot to say that I've successfully integrated your module but it allows you only to get the approximate velocity and still don't understand how to get the state of the player (e.g. walking, sprinting and so on)