Skip to content

Commit

Permalink
perf(utils): rework drawParticleLine methods
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Aug 10, 2022
1 parent 1b53981 commit 3e7e4dd
Showing 1 changed file with 16 additions and 8 deletions.
Expand Up @@ -2,27 +2,35 @@

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) {
drawLine(new Vec3(x1, y1, z1), new Vec3(x2, y2, z2), stepLength);
public static void drawLine(Vec3 startPoint, Vec3 endPoint, double stepLength) {
drawLine(startPoint.x, startPoint.y, startPoint.z, endPoint.x, endPoint.y, endPoint.z, stepLength);
}

public static void drawLine(Vec3 startPoint, Vec3 endPoint, double stepLength) {
Vec3 line = startPoint.vectorTo(endPoint);
public static void drawLine(double x1, double y1, double z1, double x2, double y2, double z2, double stepLength) {
double diffX = (x2 - x1);
double diffY = (y2 - y1);
double diffZ = (z2 - z1);

double lineLength = Mth.length(diffX, diffY, diffZ);

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

Vec3 unit = line.normalize();
double projectedStepLengthX = diffX / pointCount;
double projectedStepLengthY = diffY / pointCount;
double projectedStepLengthZ = diffZ / pointCount;

for (long i = 0; i < pointCount; i++) {
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);
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);
}
}

Expand Down

0 comments on commit 3e7e4dd

Please sign in to comment.