Homing Enchantment procedure

Started by HuggyeBear on

Topic category: Help with Minecraft modding (Java Edition)

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.

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.

Joined May 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
can you show a pic of this?
Thu, 12/26/2024 - 18:37

can you show a pic of this?

Joined Feb 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I don't have a picture that…
Thu, 12/26/2024 - 20:57

I don't have a picture that I can currently provide but adding to mindthemoods comment, you would need a local variable for things like the velocity and look angle and then you would use some math to calculate the path towards the XYZ of the entity. This wouldn't support things like pathfinding but it would definitely work.