TUTORIAL ON HOMING ARROWS

Started by UlvardsV on

Topic category: User side tutorials

Last seen on 12:22, 3. Mar 2024
Joined Feb 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
TUTORIAL ON HOMING ARROWS

Make your ranged item, create a procedure under projectile flying tick, leave it empty and lock the procedure element

 

After this open the locked procedure element and paste this script

Don't forget to add the package and the naming.

import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Entity;

import java.util.List;
import java.util.Comparator;
import java.util.stream.Collectors;

public class FlamelashWhileProjectileFlyingTickProcedure {
    public static void execute(LevelAccessor world, double x, double y, double z, Entity entity, Entity immediatesourceentity) {
        if (entity == null || immediatesourceentity == null) {
            return;
        }
        
		immediatesourceentity.setNoGravity(true);
        double range = 15;
        double speed = 2.82;

        Vec3 center = new Vec3(x, y, z);
        List<Entity> entities = world.getEntitiesOfClass(Entity.class, new AABB(center).inflate(range), e -> e instanceof LivingEntity && e != entity && e != immediatesourceentity);

        entities.sort(Comparator.comparingDouble(entityiterator -> entityiterator.distanceToSqr(center)));

        for (Entity entityiterator : entities) {
            double distance = entityiterator.distanceToSqr(immediatesourceentity);
            Vec3 direction = new Vec3(entityiterator.getX() - immediatesourceentity.getX(), entityiterator.getY() - immediatesourceentity.getY(), entityiterator.getZ() - immediatesourceentity.getZ());

            if (distance > 0) {
                direction = direction.normalize();

                double motionX = direction.x * speed / distance;
                double motionY = direction.y * speed / distance;
                double motionZ = direction.z * speed / distance;

                immediatesourceentity.setDeltaMovement(new Vec3(motionX, motionY, motionZ));
            }
        }
    }
}
Last seen on 19:35, 23. Jan 2024
Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
No luck here - I have a…
Sat, 12/30/2023 - 03:25

No luck here - I have a music note custom projectile but it just lists errors for the projectile and procedure.

Last seen on 20:31, 3. Mar 2024
Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I was hoping to use this but…
Wed, 01/03/2024 - 22:40

I was hoping to use this but it doesn't seem to work, and keeps giving me unable to compile errors. is there a fix?

Last seen on 12:22, 3. Mar 2024
Joined Feb 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You have to add your mods…
Sun, 01/21/2024 - 19:29

You have to add your mods package for example package net.your_mod.procedures;

also you have to change the namings in the code for example FlamelashWhileProjectileFlyingTickProcedure, you will have to change that based on your procedure name.

Last seen on 20:31, 3. Mar 2024
Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I tried that and it worked…
Sun, 01/21/2024 - 19:57

I tried that and it worked to fix the compiling error. However now the procedure isn't being recognized by the thing it's attached to.