Homing Enchantment procedure

Started by HuggyeBear on

Topic category: Help with modding (Java Edition)

Last seen on 22:38, 27. Jan 2024
Joined Jan 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Homing Enchantment procedure

I'm trying to make an enchantment that works pretty much like Aimbot, but all that I have found is either outdated, irrelevant, or it only works as an implicit procedure.

Last seen on 22:38, 27. Jan 2024
Joined Jan 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Popular
Fri, 01/19/2024 - 15:55

Popular

Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This isn't impossible, but…
Wed, 01/24/2024 - 15:26

This isn't impossible, but it's going to be a little tricky with MCreator's tools. I imagine the general idea would be something like this:

  • You need a procedure that triggers when an arrow spawns, checks if a player is nearby, and checks if the item in the main or off-hand of the nearest player is a bow with your enchantment.
  • ...And then changes the velocity of the arrow to aim directly towards the nearest non-player entity. Arrows do not take yaw/pitch into account, they only care about their current velocity.
  • This would require both a system to determine the nearest entity that isn't the player that fired it, (you would likely need two local variables, one to keep track of the shooter, and another to determine which entity is nearest after using an entity iterator to check all entities within a certain radius).
  • ...And then a trig function that takes the position of the arrow and the position of the target entity to get the nessasary velocity vector. (Which will be especially complicated by gravity- you also need to take into account gravity when determining the amount of y velocity to aid, otherwise the arrow might go the right direction but hit the ground before it reaches its target.)

Easier said than done, but yeah, not impossible. It'd be somewhat easier if you were using a custom projectile weapon, in that case you could just have the projectile adjust its velocity to aim towards the nearest non-shooter entity. I did something similar to this for homing arrows.