Skip to content

Commit

Permalink
feat(utils): drawParticleLine method uses Vec3
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Aug 10, 2022
1 parent 3e87c18 commit 1b53981
Showing 1 changed file with 11 additions and 9 deletions.
Expand Up @@ -2,25 +2,27 @@

import net.minecraft.client.Minecraft;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3;

public class ParticleUtils {

private static final Minecraft MC = Minecraft.getInstance();

public static void drawLine(double x1, double y1, double z1, double x2, double y2, double z2, double stepLength) {
double lineLength = Mth.length((x2 - x1), (y2 - y1), (z2 - z1));
drawLine(new Vec3(x1, y1, z1), new Vec3(x2, y2, z2), stepLength);
}

public static void drawLine(Vec3 startPoint, Vec3 endPoint, double stepLength) {
Vec3 line = startPoint.vectorTo(endPoint);

double lineLength = line.length();
long pointCount = Math.round(lineLength / stepLength);

double projectedStepLengthX = (x2 - x1) / pointCount;
double projectedStepLengthY = (y2 - y1) / pointCount;
double projectedStepLengthZ = (z2 - z1) / pointCount;
Vec3 unit = line.normalize();

for (long i = 0; i < pointCount; i++) {
double x = x1 + projectedStepLengthX * i;
double y = y1 + projectedStepLengthY * i;
double z = z1 + projectedStepLengthZ * i;
MC.level.addParticle(ParticleTypes.ELECTRIC_SPARK, x, y, z, 0.0D, 0.0D, 0.0D);
Vec3 n = startPoint.add(unit.scale(i * stepLength));
MC.level.addParticle(ParticleTypes.ELECTRIC_SPARK, n.x, n.y, n.z, 0.0D, 0.0D, 0.0D);
}
}

Expand Down

0 comments on commit 1b53981

Please sign in to comment.