Reverse Knockback (Pull enemies toward you)

Started by theeminer20 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Feb 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Reverse Knockback (Pull enemies toward you)

I am working on a weapons mod, which includes a "Sickle".
I need this sickle to pull hit entities toward the player (reverse knockback).


I want them to be launched in the opposite direction the player is facing. So if the player is looking down and hits the entity, the entity flies upward. I also don't want this to be that strong, just a gentle pull.


I have something working already, but it's based on where the entity is looking; they get launched in that direction.
This is under "living entity is hit with":

Joined Apr 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well this may be…
Fri, 11/07/2025 - 00:43

Well this may be overcomplicated, but here is one thing you could do. Set the X, Y, and Z of the player to different variables. (So basically On player tick update set the variables to those positions) and then make the mob look at said position when it is hit with the sickle, and then get launched where they are looking, AKA get launched toward the player. (However, I must say that I don't really see a use for reverse knockback as that just lets the monster bap you easier.)

Joined Apr 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Oh! I just realized you…
Fri, 11/07/2025 - 00:46

Oh! I just realized you meant they are blasted away from where the player is looking. hmm. I'm afraid that one stumps me. Anyone else?

 

Joined Apr 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Also if you are making the…
Fri, 11/07/2025 - 00:47

Also if you are making the sickle have a cooldown for the wielder. It should be source entity not event entity because event entity would be the one being hit.

Joined Feb 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You were right the first…
Fri, 11/07/2025 - 00:54

You were right the first time; it is reverse knockback, as it pulls the mob toward the player with every hit.

Yes, if you're not too careful, the mob will hit you, but as you can see, I apply one second of weakness to give you a chance to chain attacks before getting hit.

 

I've played with the mechanic as it is, and it's pretty fun; however, sometimes the mob doesn't look at you immediately, or turns its head during the fight, and you can end up flinging it slightly off course, it also throws off the rhythm. On top of that, non-hostile mobs are almost never looking at you, at least immediately.

Joined Feb 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'll play with your…
Fri, 11/07/2025 - 00:55

I'll play with your suggestion a bit later.

Thank you!

Joined Apr 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Np! Hope someone else can…
Fri, 11/07/2025 - 13:21

Np! Hope someone else can fine tune it.

Joined Feb 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Could you do a tutorial for…
Fri, 11/07/2025 - 15:53

Could you do a tutorial for me on how to apply your suggestion?

Joined Apr 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok. So first, make three…
Fri, 11/07/2025 - 16:08

Ok. So first, make three global math variables and just name them "PlayerX, PlayerY, and PlayerZ" (The name does not actually matter.) Then make a procedure that On Player Tick update, sets the variables to the player's x, y, and z coordinates. After you are done with that I will tell you step 2.

Joined Feb 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Alright, let me know if I…
Fri, 11/07/2025 - 16:19

Alright, let me know if I did this right.

Joined Feb 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I FIGURED IT OUT!This code…
Fri, 11/07/2025 - 16:49

I FIGURED IT OUT!
This code now works EXACTLY as I want it to. Thank you very much!

Joined Apr 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Not sure what the "I'm…
Fri, 11/07/2025 - 16:50

Not sure what the "I'm stupid" was about as they are exactly the same...but anyway, now go into the weapon and make a "when entity hit" procedure. Then do "When entity hit, make entity look at" and then, I realized you do not even need to make them look at the player. And then just do the make the entity get pushed to where they are looking. (Cause I don't even know how you did that part but if you get it to work, they should go toward the player.)

Joined Apr 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
OH! Well that works too. …
Fri, 11/07/2025 - 16:51

OH! Well that works too. (Everything on that screen it greek to me.....)

Joined Feb 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The player variables were…
Fri, 11/07/2025 - 16:58

The player variables were not global before (because I'm stupid.)

 

The entity is forced to look at the player and then flung in that direction, all in that split second. There are probably better ways to do this but IT WORKS, and I'm fine with it.