aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2024-12-01 23:56:47 -0800
committerAaron <51387595+AzureAaron@users.noreply.github.com>2024-12-08 16:10:15 -0500
commitc6f0b752245d38ce5be9c03d944d0c0a0cd23290 (patch)
treef908d6229b33df24fd200e6a096ba0815cd92b7c /src/main/java
parent07831905827fcb53080e0d3e048b1ef992318a8e (diff)
downloadSkyblocker-c6f0b752245d38ce5be9c03d944d0c0a0cd23290.tar.gz
Skyblocker-c6f0b752245d38ce5be9c03d944d0c0a0cd23290.tar.bz2
Skyblocker-c6f0b752245d38ce5be9c03d944d0c0a0cd23290.zip
Optimize rendering boxes
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/hysky/skyblocker/debug/SnapshotDebug.java2
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/StaminaTestHelper.java2
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java53
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java9
4 files changed, 33 insertions, 33 deletions
diff --git a/src/main/java/de/hysky/skyblocker/debug/SnapshotDebug.java b/src/main/java/de/hysky/skyblocker/debug/SnapshotDebug.java
index d9164b1f..9c2653c6 100644
--- a/src/main/java/de/hysky/skyblocker/debug/SnapshotDebug.java
+++ b/src/main/java/de/hysky/skyblocker/debug/SnapshotDebug.java
@@ -1,6 +1,7 @@
package de.hysky.skyblocker.debug;
import de.hysky.skyblocker.utils.render.RenderHelper;
+import de.hysky.skyblocker.utils.waypoint.Waypoint;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.minecraft.SharedConstants;
@@ -25,6 +26,7 @@ public class SnapshotDebug {
private static void renderTest(WorldRenderContext wrc) {
RenderHelper.renderFilledWithBeaconBeam(wrc, new BlockPos(-3, 63, 5), RED, ALPHA, true);
+ RenderHelper.renderOutline(wrc, new BlockPos(-3, 63, 5), RED, 5, true); // Use waypoint default line width
RenderHelper.renderLinesFromPoints(wrc, new Vec3d[] { new Vec3d(-2, 65, 6.5), new Vec3d(3, 65, 6.5) }, RED, ALPHA, LINE_WIDTH, false);
RenderHelper.renderLineFromCursor(wrc, new Vec3d(-2.5, 63.5, 5.5), RED, ALPHA, LINE_WIDTH);
RenderHelper.renderQuad(wrc, new Vec3d[] { new Vec3d(3, 66, 3), new Vec3d(3, 63, 3), new Vec3d(3, 63, 5), new Vec3d(3, 66, 5) }, RED, ALPHA, false);
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/StaminaTestHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/StaminaTestHelper.java
index 3f7dfe56..ee490cf2 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/StaminaTestHelper.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/StaminaTestHelper.java
@@ -262,7 +262,7 @@ public class StaminaTestHelper {
BlockPos playerPos = CLIENT.player.getBlockPos();
for (Box hole : wallHoles) {
float[] color = isHoleIncoming(hole, holeDirections.get(hole), playerPos) ? INCOMING_COLOR : OUTGOING_COLOR;
- RenderHelper.renderFilled(context, new BlockPos((int) hole.minX, (int) hole.minY, (int) hole.minZ), new Vec3d(hole.getLengthX(), hole.getLengthY(), hole.getLengthZ()), color, 0.3f, false);
+ RenderHelper.renderFilled(context, hole, color, 0.3f, false);
}
}
diff --git a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java
index 4a0d82fb..ca7d021f 100644
--- a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java
+++ b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java
@@ -40,7 +40,6 @@ import java.awt.*;
public class RenderHelper {
private static final Identifier TRANSLUCENT_DRAW = Identifier.of(SkyblockerMod.NAMESPACE, "translucent_draw");
- private static final Vec3d ONE = new Vec3d(1, 1, 1);
private static final int MAX_OVERWORLD_BUILD_HEIGHT = 319;
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
private static final BufferAllocator ALLOCATOR = new BufferAllocator(1536);
@@ -56,31 +55,31 @@ public class RenderHelper {
renderBeaconBeam(context, pos, colorComponents);
}
- public static void renderFilled(WorldRenderContext context, Box box, float[] colorComponents, float alpha, boolean throughWalls) {
- renderFilled(context, box.getMinPos(), Boxes.getLengthVec(box), colorComponents, alpha, throughWalls);
+ public static void renderFilled(WorldRenderContext context, BlockPos pos, float[] colorComponents, float alpha, boolean throughWalls) {
+ renderFilled(context, pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1, colorComponents, alpha, throughWalls);
}
- public static void renderFilled(WorldRenderContext context, BlockPos pos, float[] colorComponents, float alpha, boolean throughWalls) {
- renderFilled(context, Vec3d.of(pos), ONE, colorComponents, alpha, throughWalls);
+ public static void renderFilled(WorldRenderContext context, Vec3d pos, Vec3d dimensions, float[] colorComponents, float alpha, boolean throughWalls) {
+ renderFilled(context, pos.x, pos.y, pos.z, pos.x + dimensions.x, pos.y + dimensions.y, pos.z + dimensions.z, colorComponents, alpha, throughWalls);
}
- public static void renderFilled(WorldRenderContext context, BlockPos pos, Vec3d dimensions, float[] colorComponents, float alpha, boolean throughWalls) {
- renderFilled(context, Vec3d.of(pos), dimensions, colorComponents, alpha, throughWalls);
+ public static void renderFilled(WorldRenderContext context, Box box, float[] colorComponents, float alpha, boolean throughWalls) {
+ renderFilled(context, box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ, colorComponents, alpha, throughWalls);
}
- public static void renderFilled(WorldRenderContext context, Vec3d pos, Vec3d dimensions, float[] colorComponents, float alpha, boolean throughWalls) {
+ public static void renderFilled(WorldRenderContext context, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float[] colorComponents, float alpha, boolean throughWalls) {
if (throughWalls) {
- if (FrustumUtils.isVisible(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + dimensions.x, pos.getY() + dimensions.y, pos.getZ() + dimensions.z)) {
- renderFilledInternal(context, pos, dimensions, colorComponents, alpha, true);
+ if (FrustumUtils.isVisible(minX, minY, minZ, maxX, maxY, maxZ)) {
+ renderFilledInternal(context, minX, minY, minZ, maxX, maxY, maxZ, colorComponents, alpha, true);
}
} else {
- if (OcclusionCulling.getRegularCuller().isVisible(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + dimensions.x, pos.getY() + dimensions.y, pos.getZ() + dimensions.z)) {
- renderFilledInternal(context, pos, dimensions, colorComponents, alpha, false);
+ if (OcclusionCulling.getRegularCuller().isVisible(minX, minY, minZ, maxX, maxY, maxZ)) {
+ renderFilledInternal(context, minX, minY, minZ, maxX, maxY, maxZ, colorComponents, alpha, false);
}
}
}
- private static void renderFilledInternal(WorldRenderContext context, Vec3d pos, Vec3d dimensions, float[] colorComponents, float alpha, boolean throughWalls) {
+ private static void renderFilledInternal(WorldRenderContext context, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float[] colorComponents, float alpha, boolean throughWalls) {
MatrixStack matrices = context.matrixStack();
Vec3d camera = context.camera().getPos();
@@ -90,7 +89,7 @@ public class RenderHelper {
VertexConsumerProvider consumers = context.consumers();
VertexConsumer buffer = consumers.getBuffer(throughWalls ? SkyblockerRenderLayers.FILLED_THROUGH_WALLS : SkyblockerRenderLayers.FILLED);
- VertexRendering.drawFilledBox(matrices, buffer, pos.x, pos.y, pos.z, pos.x + dimensions.x, pos.y + dimensions.y, pos.z + dimensions.z, colorComponents[0], colorComponents[1], colorComponents[2], alpha);
+ VertexRendering.drawFilledBox(matrices, buffer, minX, minY, minZ, maxX, maxY, maxZ, colorComponents[0], colorComponents[1], colorComponents[2], alpha);
matrices.pop();
}
@@ -109,22 +108,24 @@ public class RenderHelper {
}
}
- /**
- * Renders the outline of a box with the specified color components and line width.
- * This does not use renderer since renderer draws outline using debug lines with a fixed width.
- */
+ public static void renderOutline(WorldRenderContext context, BlockPos pos, float[] colorComponents, float lineWidth, boolean throughWalls) {
+ renderOutline(context, pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1, colorComponents, 1f, lineWidth, throughWalls);
+ }
+
+ public static void renderOutline(WorldRenderContext context, Vec3d pos, Vec3d dimensions, float[] colorComponents, float lineWidth, boolean throughWalls) {
+ renderOutline(context, pos.x, pos.y, pos.z, pos.x + dimensions.x, pos.y + dimensions.y, pos.z + dimensions.z, colorComponents, 1f, lineWidth, throughWalls);
+ }
+
public static void renderOutline(WorldRenderContext context, Box box, float[] colorComponents, float lineWidth, boolean throughWalls) {
renderOutline(context, box, colorComponents, 1f, lineWidth, throughWalls);
}
- /**
- * Renders the outline of a box with the specified color components and line width.
- * This does not use renderer since renderer draws outline using debug lines with a fixed width.
- *
- * @param alpha the transparency of the lines for the box
- */
public static void renderOutline(WorldRenderContext context, Box box, float[] colorComponents, float alpha, float lineWidth, boolean throughWalls) {
- if (FrustumUtils.isVisible(box)) {
+ renderOutline(context, box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ, colorComponents, alpha, lineWidth, throughWalls);
+ }
+
+ public static void renderOutline(WorldRenderContext context, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float[] colorComponents, float alpha, float lineWidth, boolean throughWalls) {
+ if (FrustumUtils.isVisible(minX, minY, minZ, maxX, maxY, maxZ)) {
MatrixStack matrices = context.matrixStack();
Vec3d camera = context.camera().getPos();
Tessellator tessellator = RenderSystem.renderThreadTesselator();
@@ -141,7 +142,7 @@ public class RenderHelper {
matrices.translate(-camera.getX(), -camera.getY(), -camera.getZ());
BufferBuilder buffer = tessellator.begin(DrawMode.LINES, VertexFormats.LINES);
- VertexRendering.drawBox(matrices, buffer, box, colorComponents[0], colorComponents[1], colorComponents[2], alpha);
+ VertexRendering.drawBox(matrices, buffer, minX, minY, minZ, maxX, maxY, maxZ, colorComponents[0], colorComponents[1], colorComponents[2], alpha);
BufferRenderer.drawWithGlobalProgram(buffer.end());
matrices.pop();
diff --git a/src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java b/src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java
index e2e246a3..a5c5d251 100644
--- a/src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java
+++ b/src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java
@@ -6,7 +6,6 @@ import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.Box;
import java.util.Arrays;
import java.util.Objects;
@@ -21,7 +20,6 @@ public class Waypoint implements Renderable {
protected static final float DEFAULT_HIGHLIGHT_ALPHA = 0.5f;
protected static final float DEFAULT_LINE_WIDTH = 5f;
public final BlockPos pos;
- final Box box;
final Supplier<Type> typeSupplier;
/**
* The color components of the waypoint.
@@ -64,7 +62,6 @@ public class Waypoint implements Renderable {
public Waypoint(BlockPos pos, Supplier<Type> typeSupplier, float[] colorComponents, float alpha, float lineWidth, boolean throughWalls, boolean enabled) {
this.pos = pos;
- this.box = new Box(pos);
this.typeSupplier = typeSupplier;
this.colorComponents = colorComponents;
this.alpha = alpha;
@@ -180,15 +177,15 @@ public class Waypoint implements Renderable {
case OUTLINED_WAYPOINT -> {
float[] colorComponents = getRenderColorComponents();
RenderHelper.renderFilledWithBeaconBeam(context, pos, colorComponents, alpha, throughWalls);
- RenderHelper.renderOutline(context, box, colorComponents, lineWidth, throughWalls);
+ RenderHelper.renderOutline(context, pos, colorComponents, lineWidth, throughWalls);
}
case HIGHLIGHT -> RenderHelper.renderFilled(context, pos, getRenderColorComponents(), alpha, throughWalls);
case OUTLINED_HIGHLIGHT -> {
float[] colorComponents = getRenderColorComponents();
RenderHelper.renderFilled(context, pos, colorComponents, alpha, throughWalls);
- RenderHelper.renderOutline(context, box, colorComponents, lineWidth, throughWalls);
+ RenderHelper.renderOutline(context, pos, colorComponents, lineWidth, throughWalls);
}
- case OUTLINE -> RenderHelper.renderOutline(context, box, getRenderColorComponents(), lineWidth, throughWalls);
+ case OUTLINE -> RenderHelper.renderOutline(context, pos, getRenderColorComponents(), lineWidth, throughWalls);
}
}