Started by
UlvardsV
on
Topic category: User side tutorials
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));
}
}
}
}
No luck here - I have a music note custom projectile but it just lists errors for the projectile and procedure.
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?
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.
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.