Skip to content

Commit 2912fc3

Browse files
committed
poor man's line dedupe
1 parent 94f6f67 commit 2912fc3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/main/java/mekanism/client/render/lib/Outlines.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.minecraft.client.renderer.block.model.BakedQuad;
1212
import net.minecraft.client.resources.model.BakedModel;
1313
import net.minecraft.core.Direction;
14+
import net.minecraft.util.Mth;
1415
import net.minecraft.util.RandomSource;
1516
import net.minecraft.world.level.block.state.BlockState;
1617
import net.minecraft.world.phys.Vec3;
@@ -89,10 +90,28 @@ private void addLine(double x1, double y1, double z1, double x2, double y2, doub
8990
nY = nY / nLen;
9091
nZ = nZ / nLen;
9192

92-
lines.add(new Line((float) x1, (float) y1, (float) z1, (float) x2, (float) y2, (float) z2, (float) nX, (float) nY, (float) nZ));
93+
Line line = new Line((float) x1, (float) y1, (float) z1, (float) x2, (float) y2, (float) z2, (float) nX, (float) nY, (float) nZ);
94+
if (!lines.contains(line)) {
95+
lines.add(line);
96+
}
9397
}
9498

9599
}
96100

97-
public record Line(float x1, float y1, float z1, float x2, float y2, float z2, float nX, float nY, float nZ) {}
101+
public record Line(float x1, float y1, float z1, float x2, float y2, float z2, float nX, float nY, float nZ) {
102+
103+
@SuppressWarnings("SuspiciousNameCombination")
104+
@Override
105+
public boolean equals(Object obj) {
106+
if (obj == this) {
107+
return true;
108+
}
109+
if (obj == null || obj.getClass() != Line.class) {
110+
return false;
111+
}
112+
Line other = (Line) obj;
113+
return (Mth.equal(x1, other.x1) && Mth.equal(y1, other.y1) && Mth.equal(z1, other.z1) && Mth.equal(x2, other.x2) && Mth.equal(y2, other.y2) && Mth.equal(z2, other.z2)) ||
114+
(Mth.equal(x1, other.x2) && Mth.equal(y1, other.y2) && Mth.equal(z1, other.z2) && Mth.equal(x2, other.x1) && Mth.equal(y2, other.y1) && Mth.equal(z2, other.z1));
115+
}
116+
}
98117
}

0 commit comments

Comments
 (0)