aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt
diff options
context:
space:
mode:
authoringlettronald <inglettronald@gmail.com>2023-06-11 17:19:53 -0500
committeringlettronald <inglettronald@gmail.com>2023-06-11 17:19:53 -0500
commit63012eec9f39fb3752bcded90bfc710ab3d05219 (patch)
treea2b9ef95dcab48108d875ff51cb90e77909aa89d /src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt
parentf3f6da9f50edfbe9ed3be42fa16146210e60fbf3 (diff)
downloadDulkirMod-Fabric-63012eec9f39fb3752bcded90bfc710ab3d05219.tar.gz
DulkirMod-Fabric-63012eec9f39fb3752bcded90bfc710ab3d05219.tar.bz2
DulkirMod-Fabric-63012eec9f39fb3752bcded90bfc710ab3d05219.zip
yeah I'm not documenting this today
Diffstat (limited to 'src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt')
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt b/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt
new file mode 100644
index 0000000..30c19c7
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt
@@ -0,0 +1,56 @@
+package com.dulkirfabric.util
+
+import com.mojang.blaze3d.platform.GlStateManager
+import com.mojang.blaze3d.systems.RenderSystem
+import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext
+import net.minecraft.client.render.GameRenderer
+import net.minecraft.client.render.Tessellator
+import net.minecraft.client.render.VertexFormat
+import net.minecraft.client.render.VertexFormats
+import java.awt.Color
+
+
+object WorldRenderUtils {
+ fun drawBox(
+ context: WorldRenderContext,
+ x1: Float,
+ y1: Float,
+ z1: Float,
+ x2: Float,
+ y2: Float,
+ z2: Float,
+ color: Color,
+ thickness: Float,
+ depthTest: Boolean = true
+ ) {
+ val matrices = context.matrixStack()
+ matrices.push()
+ RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram)
+ RenderSystem.enableBlend()
+ RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA)
+ RenderSystem.lineWidth(thickness)
+ RenderSystem.setShaderColor(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f)
+ if (!depthTest) RenderSystem.disableDepthTest()
+ matrices.translate(-context.camera().pos.x, -context.camera().pos.y, -context.camera().pos.z)
+ val tess = Tessellator.getInstance()
+ val buf = tess.buffer
+ val matrix4f = matrices.peek().positionMatrix
+
+ buf.begin(VertexFormat.DrawMode.LINES, VertexFormats.POSITION_COLOR)
+ buf.fixedColor(255, 255, 255, 255)
+
+ buf.vertex(matrix4f, x1, y1, z1).next()
+ buf.vertex(matrix4f, x2, y1, z1).next()
+
+ //buf.vertex(matrix4f, x2, y2, z1).next()
+
+ buf.unfixColor()
+ tess.draw()
+
+
+ RenderSystem.enableDepthTest()
+ RenderSystem.disableBlend()
+ RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
+ matrices.pop()
+ }
+} \ No newline at end of file