Entity that switches between melee and ranged attacks

Started by leliloni on

Topic category: Help with Minecraft modding (Java Edition)

Joined Mar 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Entity that switches between melee and ranged attacks

I am trying to make a ranged mob that will only shoot at its target when it is further away. If the target comes closer, the mob should attack it with a normal melee attack. Is there a way to do this?

(I am willing to code if there is no other option, but I don‘t have any experiece with it, so I would need a detailed explanation).

Joined Jan 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
So you would create a…
Thu, 02/20/2025 - 00:48

So you would create a procedure using the on entity tick update trigger, doing something like: If the player exists within a radius of (let's say you want its max shooting range to be 20 blocks) 20. Do- set attack target of entity - server player (or player) and then enable it being able to have a ranged weapon. and then you would create a procedure of: If the player exists within a radius of (let's say you want it to do melee within three blocks), 3. and then you would set its main hand item something like a sword or smth. Idk if that will work. but I'll do some testing (It might take a while cause I'm busy) Tell me if you need any more help. screenshots ect!