Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Forge 1.16.5] Wierd interaction between entity.knockback and OnAttackedEvent

Recommended Posts

This is a follow up to an earlier post about not being able to use the knockback method. Well, since then I've learned a bit more about the nature of my problem. It turns out that knockback DOES work, but the catch is if I cancel the LivingAttackEvent that I'm calling the code from, then all attempts to modify the velocity of the player are nullified, even if i extract the mojang knockback code and reuse it (which I don't want to do in the long run, for legal reasons). As soon as I stop canceling the event, the knockback works. Unfortunately, I NEED to cancel the event, since its the whole point of the mod. What could be causing this interaction???

Edited by theishiopian
Link to post
Share on other sites

knockback changes the velocity server side. However the player velocity is usually controlled client side. There is a special flag on entities (hurtMarked) that will cause the server to send a velocity update to the client. The attack logic sets this to true. If you cancel that, it doesn't get set to true and your knockback gets lost. Simply doing player.hurtMarked = true after your knockback fixes the issue.

  • Thanks 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.