aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/xmrvizzy/skyblocker/utils/Vertexer.java
diff options
context:
space:
mode:
authorKevin <92656833+kevinthegreat1@users.noreply.github.com>2023-09-05 19:45:14 -0400
committerGitHub <noreply@github.com>2023-09-05 19:45:14 -0400
commitedf217cd8d3f2344700ae44416031ae3d695bf77 (patch)
treea5f6269f3567fe28a410b8fd93c89801ba0c14c6 /src/main/java/me/xmrvizzy/skyblocker/utils/Vertexer.java
parentd6d50160c9a1e5145119d4b06bcd74e9c662238e (diff)
parent30a7b733b0c5a0e7b5002dfd68ec6ece04c02ecc (diff)
downloadSkyblocker-edf217cd8d3f2344700ae44416031ae3d695bf77.tar.gz
Skyblocker-edf217cd8d3f2344700ae44416031ae3d695bf77.tar.bz2
Skyblocker-edf217cd8d3f2344700ae44416031ae3d695bf77.zip
Merge pull request #274 from kevinthegreat1/utils-cleanup
Utils cleanup
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/utils/Vertexer.java')
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/utils/Vertexer.java164
1 files changed, 0 insertions, 164 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/Vertexer.java b/src/main/java/me/xmrvizzy/skyblocker/utils/Vertexer.java
deleted file mode 100644
index cf6d90b6..00000000
--- a/src/main/java/me/xmrvizzy/skyblocker/utils/Vertexer.java
+++ /dev/null
@@ -1,164 +0,0 @@
-package me.xmrvizzy.skyblocker.utils;
-
-import me.xmrvizzy.skyblocker.utils.color.LineColor;
-import me.xmrvizzy.skyblocker.utils.color.QuadColor;
-import net.minecraft.client.render.VertexConsumer;
-import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.util.math.Box;
-import net.minecraft.util.math.Direction;
-import net.minecraft.util.math.MathHelper;
-// import net.minecraft.util.math.Matrix3f;
-// import net.minecraft.util.math.Matrix4f;
-// import net.minecraft.util.math.Vec3f;
-import org.joml.Matrix3f;
-import org.joml.Matrix4f;
-import org.joml.Vector3f;
-import org.apache.commons.lang3.ArrayUtils;
-
-public class Vertexer {
-
- public static final int CULL_BACK = 0;
- public static final int CULL_FRONT = 1;
- public static final int CULL_NONE = 2;
-
- public static void vertexBoxQuads(MatrixStack matrices, VertexConsumer vertexConsumer, Box box, QuadColor quadColor, Direction... excludeDirs) {
- float x1 = (float) box.minX;
- float y1 = (float) box.minY;
- float z1 = (float) box.minZ;
- float x2 = (float) box.maxX;
- float y2 = (float) box.maxY;
- float z2 = (float) box.maxZ;
-
- int cullMode = excludeDirs.length == 0 ? CULL_BACK : CULL_NONE;
-
- if (!ArrayUtils.contains(excludeDirs, Direction.DOWN)) {
- vertexQuad(matrices, vertexConsumer, x1, y1, z1, x2, y1, z1, x2, y1, z2, x1, y1, z2, cullMode, quadColor);
- }
-
- if (!ArrayUtils.contains(excludeDirs, Direction.WEST)) {
- vertexQuad(matrices, vertexConsumer, x1, y1, z2, x1, y2, z2, x1, y2, z1, x1, y1, z1, cullMode, quadColor);
- }
-
- if (!ArrayUtils.contains(excludeDirs, Direction.EAST)) {
- vertexQuad(matrices, vertexConsumer, x2, y1, z1, x2, y2, z1, x2, y2, z2, x2, y1, z2, cullMode, quadColor);
- }
-
- if (!ArrayUtils.contains(excludeDirs, Direction.NORTH)) {
- vertexQuad(matrices, vertexConsumer, x1, y1, z1, x1, y2, z1, x2, y2, z1, x2, y1, z1, cullMode, quadColor);
- }
-
- if (!ArrayUtils.contains(excludeDirs, Direction.SOUTH)) {
- vertexQuad(matrices, vertexConsumer, x2, y1, z2, x2, y2, z2, x1, y2, z2, x1, y1, z2, cullMode, quadColor);
- }
-
- if (!ArrayUtils.contains(excludeDirs, Direction.UP)) {
- vertexQuad(matrices, vertexConsumer, x1, y2, z2, x2, y2, z2, x2, y2, z1, x1, y2, z1, cullMode, quadColor);
- }
- }
-
- public static void vertexQuad(MatrixStack matrices, VertexConsumer vertexConsumer, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4, int cullMode, QuadColor quadColor) {
- int[] color = quadColor.getAllColors();
-
- if (cullMode != CULL_FRONT) {
- vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x1, y1, z1).color(color[0], color[1], color[2], color[3]).next();
- vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x2, y2, z2).color(color[4], color[5], color[6], color[7]).next();
- vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x3, y3, z3).color(color[8], color[9], color[10], color[11]).next();
- vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x4, y4, z4).color(color[12], color[13], color[14], color[15]).next();
- }
-
- if (cullMode != CULL_BACK) {
- vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x4, y4, z4).color(color[0], color[1], color[2], color[3]).next();
- vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x3, y3, z3).color(color[4], color[5], color[6], color[7]).next();
- vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x2, y2, z2).color(color[8], color[9], color[10], color[11]).next();
- vertexConsumer.vertex(matrices.peek().getPositionMatrix(), x1, y1, z1).color(color[12], color[13], color[14], color[15]).next();
- }
- }
-
- public static void vertexBoxLines(MatrixStack matrices, VertexConsumer vertexConsumer, Box box, QuadColor quadColor, Direction... excludeDirs) {
- float x1 = (float) box.minX;
- float y1 = (float) box.minY;
- float z1 = (float) box.minZ;
- float x2 = (float) box.maxX;
- float y2 = (float) box.maxY;
- float z2 = (float) box.maxZ;
-
- boolean exDown = ArrayUtils.contains(excludeDirs, Direction.DOWN);
- boolean exWest = ArrayUtils.contains(excludeDirs, Direction.WEST);
- boolean exEast = ArrayUtils.contains(excludeDirs, Direction.EAST);
- boolean exNorth = ArrayUtils.contains(excludeDirs, Direction.NORTH);
- boolean exSouth = ArrayUtils.contains(excludeDirs, Direction.SOUTH);
- boolean exUp = ArrayUtils.contains(excludeDirs, Direction.UP);
-
- int[] color = quadColor.getAllColors();
-
- if (!exDown) {
- vertexLine(matrices, vertexConsumer, x1, y1, z1, x2, y1, z1, LineColor.single(color[0], color[1], color[2], color[3]));
- vertexLine(matrices, vertexConsumer, x2, y1, z1, x2, y1, z2, LineColor.single(color[4], color[5], color[6], color[7]));
- vertexLine(matrices, vertexConsumer, x2, y1, z2, x1, y1, z2, LineColor.single(color[8], color[9], color[10], color[11]));
- vertexLine(matrices, vertexConsumer, x1, y1, z2, x1, y1, z1, LineColor.single(color[12], color[13], color[14], color[15]));
- }
-
- if (!exWest) {
- if (exDown) vertexLine(matrices, vertexConsumer, x1, y1, z1, x1, y1, z2, LineColor.single(color[0], color[1], color[2], color[3]));
- vertexLine(matrices, vertexConsumer, x1, y1, z2, x1, y2, z2, LineColor.single(color[4], color[5], color[6], color[7]));
- vertexLine(matrices, vertexConsumer, x1, y1, z1, x1, y2, z1, LineColor.single(color[8], color[9], color[10], color[11]));
- if (exUp) vertexLine(matrices, vertexConsumer, x1, y2, z1, x1, y2, z2, LineColor.single(color[12], color[13], color[14], color[15]));
- }
-
- if (!exEast) {
- if (exDown) vertexLine(matrices, vertexConsumer, x2, y1, z1, x2, y1, z2, LineColor.single(color[0], color[1], color[2], color[3]));
- vertexLine(matrices, vertexConsumer, x2, y1, z2, x2, y2, z2, LineColor.single(color[4], color[5], color[6], color[7]));
- vertexLine(matrices, vertexConsumer, x2, y1, z1, x2, y2, z1, LineColor.single(color[8], color[9], color[10], color[11]));
- if (exUp) vertexLine(matrices, vertexConsumer, x2, y2, z1, x2, y2, z2, LineColor.single(color[12], color[13], color[14], color[15]));
- }
-
- if (!exNorth) {
- if (exDown) vertexLine(matrices, vertexConsumer, x1, y1, z1, x2, y1, z1, LineColor.single(color[0], color[1], color[2], color[3]));
- if (exEast) vertexLine(matrices, vertexConsumer, x2, y1, z1, x2, y2, z1, LineColor.single(color[4], color[5], color[6], color[7]));
- if (exWest) vertexLine(matrices, vertexConsumer, x1, y1, z1, x1, y2, z1, LineColor.single(color[8], color[9], color[10], color[11]));
- if (exUp) vertexLine(matrices, vertexConsumer, x1, y2, z1, x2, y2, z1, LineColor.single(color[12], color[13], color[14], color[15]));
- }
-
- if (!exSouth) {
- if (exDown) vertexLine(matrices, vertexConsumer, x1, y1, z2, x2, y1, z2, LineColor.single(color[0], color[1], color[2], color[3]));
- if (exEast) vertexLine(matrices, vertexConsumer, x2, y1, z2, x2, y2, z2, LineColor.single(color[4], color[5], color[6], color[7]));
- if (exWest) vertexLine(matrices, vertexConsumer, x1, y1, z2, x1, y2, z2, LineColor.single(color[8], color[9], color[10], color[11]));
- if (exUp) vertexLine(matrices, vertexConsumer, x1, y2, z2, x2, y2, z2, LineColor.single(color[12], color[13], color[14], color[15]));
- }
-
- if (!exUp) {
- vertexLine(matrices, vertexConsumer, x1, y2, z1, x2, y2, z1, LineColor.single(color[0], color[1], color[2], color[3]));
- vertexLine(matrices, vertexConsumer, x2, y2, z1, x2, y2, z2, LineColor.single(color[4], color[5], color[6], color[7]));
- vertexLine(matrices, vertexConsumer, x2, y2, z2, x1, y2, z2, LineColor.single(color[8], color[9], color[10], color[11]));
- vertexLine(matrices, vertexConsumer, x1, y2, z2, x1, y2, z1, LineColor.single(color[12], color[13], color[14], color[15]));
- }
- }
-
- public static void vertexLine(MatrixStack matrices, VertexConsumer vertexConsumer, float x1, float y1, float z1, float x2, float y2, float z2, LineColor lineColor) {
- Matrix4f model = matrices.peek().getPositionMatrix();
- Matrix3f normal = matrices.peek().getNormalMatrix();
-
- // Vec3f normalVec = getNormal(normal, x1, y1, z1, x2, y2, z2);
- Vector3f normalVec = getNormal(normal, x1, y1, z1, x2, y2, z2);
-
- int[] color1 = lineColor.getColor(x1, y1, z1, 0);
- int[] color2 = lineColor.getColor(x2, y2, z2, 1);
-
- // vertexConsumer.vertex(model, x1, y1, z1).color(color1[0], color1[1], color1[2], color1[3]).normal(normal, normalVec.getX(), normalVec.getY(), normalVec.getZ()).next();
- vertexConsumer.vertex(model, x1, y1, z1).color(color1[0], color1[1], color1[2], color1[3]).normal(normal, normalVec.x(), normalVec.y(), normalVec.z()).next();
- // vertexConsumer.vertex(model, x2, y2, z2).color(color2[0], color2[1], color2[2], color2[3]).normal(normal, normalVec.getX(), normalVec.getY(), normalVec.getZ()).next();
- vertexConsumer.vertex(model, x2, y2, z2).color(color2[0], color2[1], color2[2], color2[3]).normal(normal, normalVec.x(), normalVec.y(), normalVec.z()).next();
- }
-
- // public static Vec3f getNormal(Matrix3f normal, float x1, float y1, float z1, float x2, float y2, float z2) {
- public static Vector3f getNormal(Matrix3f normal, float x1, float y1, float z1, float x2, float y2, float z2) {
- float xNormal = x2 - x1;
- float yNormal = y2 - y1;
- float zNormal = z2 - z1;
- float normalSqrt = MathHelper.sqrt(xNormal * xNormal + yNormal * yNormal + zNormal * zNormal);
-
- // return new Vec3f(xNormal / normalSqrt, yNormal / normalSqrt, zNormal / normalSqrt);
- return new Vector3f(xNormal / normalSqrt, yNormal / normalSqrt, zNormal / normalSqrt);
- }
-
-} \ No newline at end of file