aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-06-12 01:10:16 +0200
committernea <nea@nea.moe>2023-06-12 01:10:16 +0200
commitbf161d33a01d1d4965c84654d46fd036b7e0c6da (patch)
tree0955e1525c0d63beb8b33b672c0294284927b493 /src/main/kotlin/com/dulkirfabric
parent63012eec9f39fb3752bcded90bfc710ab3d05219 (diff)
downloadDulkirMod-Fabric-bf161d33a01d1d4965c84654d46fd036b7e0c6da.tar.gz
DulkirMod-Fabric-bf161d33a01d1d4965c84654d46fd036b7e0c6da.tar.bz2
DulkirMod-Fabric-bf161d33a01d1d4965c84654d46fd036b7e0c6da.zip
Render wireframes
Diffstat (limited to 'src/main/kotlin/com/dulkirfabric')
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt7
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt77
2 files changed, 66 insertions, 18 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt b/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt
index e037dd9..6a0c048 100644
--- a/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt
+++ b/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt
@@ -3,13 +3,16 @@ package com.dulkirfabric.features
import com.dulkirfabric.events.WorldRenderLastEvent
import com.dulkirfabric.util.WorldRenderUtils
import meteordevelopment.orbit.EventHandler
+import net.minecraft.util.math.Box
import java.awt.Color
object RenderBoxTest {
@EventHandler
fun onRender(event: WorldRenderLastEvent) {
- WorldRenderUtils.drawBox(event.context,0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
- Color(255, 255, 255, 255), 3f, false)
+ WorldRenderUtils.drawBox(
+ event.context, Box(0.0, 0.0, 0.0, 1.0, 1.0, 1.0),
+ Color(255, 255, 255, 255), 3f, true
+ )
}
} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt b/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt
index 30c19c7..d5008ba 100644
--- a/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt
+++ b/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt
@@ -1,24 +1,47 @@
package com.dulkirfabric.util
+import com.mojang.blaze3d.platform.GlConst
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.BufferBuilder
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 net.minecraft.client.util.math.MatrixStack
+import net.minecraft.util.math.Box
+import net.minecraft.util.math.Direction.Axis
+import org.joml.Vector3f
import java.awt.Color
object WorldRenderUtils {
+ private fun line(
+ matrix: MatrixStack.Entry, buffer: BufferBuilder,
+ x1: Number, y1: Number, z1: Number,
+ x2: Number, y2: Number, z2: Number,
+ ) {
+ line(
+ matrix,
+ buffer,
+ Vector3f(x1.toFloat(), y1.toFloat(), z1.toFloat()),
+ Vector3f(x2.toFloat(), y2.toFloat(), z2.toFloat())
+ )
+ }
+
+ private fun line(matrix: MatrixStack.Entry, buffer: BufferBuilder, from: Vector3f, to: Vector3f) {
+ val normal = to.sub(from, Vector3f()).mul(-1F)
+ buffer.vertex(matrix.positionMatrix, from.x, from.y, from.z)
+ .normal(matrix.normalMatrix, normal.x, normal.y, normal.z).next()
+ buffer.vertex(matrix.positionMatrix, to.x, to.y, to.z)
+ .normal(matrix.normalMatrix, normal.x, normal.y, normal.z)
+ .next()
+ }
+
fun drawBox(
context: WorldRenderContext,
- x1: Float,
- y1: Float,
- z1: Float,
- x2: Float,
- y2: Float,
- z2: Float,
+ box: Box,
color: Color,
thickness: Float,
depthTest: Boolean = true
@@ -26,23 +49,43 @@ object WorldRenderUtils {
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.disableBlend()
+ RenderSystem.disableCull()
+ RenderSystem.defaultBlendFunc()
RenderSystem.lineWidth(thickness)
RenderSystem.setShaderColor(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f)
- if (!depthTest) RenderSystem.disableDepthTest()
+ if (!depthTest) {
+ RenderSystem.disableDepthTest()
+ } else {
+ RenderSystem.enableDepthTest()
+ RenderSystem.depthFunc(GlConst.GL_LEQUAL)
+ RenderSystem.depthMask(false)
+ }
matrices.translate(-context.camera().pos.x, -context.camera().pos.y, -context.camera().pos.z)
- val tess = Tessellator.getInstance()
+ val tess = RenderSystem.renderThreadTesselator()
val buf = tess.buffer
- val matrix4f = matrices.peek().positionMatrix
+ val me = matrices.peek()
- buf.begin(VertexFormat.DrawMode.LINES, VertexFormats.POSITION_COLOR)
+ buf.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES)
buf.fixedColor(255, 255, 255, 255)
- buf.vertex(matrix4f, x1, y1, z1).next()
- buf.vertex(matrix4f, x2, y1, z1).next()
+ // X Axis aligned lines
+ line(me, buf, box.minX, box.minY, box.minZ, box.maxX, box.minY, box.minZ)
+ line(me, buf, box.minX, box.maxY, box.minZ, box.maxX, box.maxY, box.minZ)
+ line(me, buf, box.minX, box.minY, box.maxZ, box.maxX, box.minY, box.maxZ)
+ line(me, buf, box.minX, box.maxY, box.maxZ, box.maxX, box.maxY, box.maxZ)
+
+ // Y Axis aligned lines
+ line(me, buf, box.minX, box.minY, box.minZ, box.minX, box.maxY, box.minZ)
+ line(me, buf, box.maxX, box.minY, box.minZ, box.maxX, box.maxY, box.minZ)
+ line(me, buf, box.minX, box.minY, box.maxZ, box.minX, box.maxY, box.maxZ)
+ line(me, buf, box.maxX, box.minY, box.maxZ, box.maxX, box.maxY, box.maxZ)
- //buf.vertex(matrix4f, x2, y2, z1).next()
+ // Z Axis aligned lines
+ line(me, buf, box.minX, box.minY, box.minZ, box.minX, box.minY, box.maxZ)
+ line(me, buf, box.maxX, box.minY, box.minZ, box.maxX, box.minY, box.maxZ)
+ line(me, buf, box.minX, box.maxY, box.minZ, box.minX, box.maxY, box.maxZ)
+ line(me, buf, box.maxX, box.maxY, box.minZ, box.maxX, box.maxY, box.maxZ)
buf.unfixColor()
tess.draw()
@@ -50,7 +93,9 @@ object WorldRenderUtils {
RenderSystem.enableDepthTest()
RenderSystem.disableBlend()
- RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
+ RenderSystem.setShaderColor(
+ 1f, 1f, 1f, 1f
+ )
matrices.pop()
}
} \ No newline at end of file