aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric/util
diff options
context:
space:
mode:
authoringlettronald <inglettronald@gmail.com>2023-07-20 12:02:02 -0500
committeringlettronald <inglettronald@gmail.com>2023-07-20 12:02:02 -0500
commit253a9bffcf3a3f8f99bb426b7b6d8031e73c82ba (patch)
tree3509e61375e3df362a48a9b044d82d11d8fff62d /src/main/kotlin/com/dulkirfabric/util
parent261370d3539579b23f3cf07733d310e9ff35becb (diff)
downloadDulkirMod-Fabric-253a9bffcf3a3f8f99bb426b7b6d8031e73c82ba.tar.gz
DulkirMod-Fabric-253a9bffcf3a3f8f99bb426b7b6d8031e73c82ba.tar.bz2
DulkirMod-Fabric-253a9bffcf3a3f8f99bb426b7b6d8031e73c82ba.zip
Ported some arachne features from 1.8
Diffstat (limited to 'src/main/kotlin/com/dulkirfabric/util')
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt b/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt
index 9f25ab4..c8ec492 100644
--- a/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt
+++ b/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt
@@ -202,6 +202,73 @@ object WorldRenderUtils {
matrices.pop()
}
+ /**
+ * If you intend to show with distance, use a waypoint I think. If you're looking at this
+ * statement and screaming at me for forgetting some use case, either let me know or compile
+ * a method that accomplishes your goals based off of this example code. Neither of these
+ * things should be incredibly difficult.
+ */
+ fun drawText(
+ text: Text,
+ context: WorldRenderContext,
+ pos: Vec3d,
+ depthTest: Boolean = true,
+ scale: Float = 1f
+ ) {
+ if (depthTest) {
+ RenderSystem.disableDepthTest()
+ }
+ RenderSystem.enableBlend()
+ RenderSystem.defaultBlendFunc()
+ RenderSystem.disableCull()
+
+ val vertexConsumer = context.worldRenderer().bufferBuilders.entityVertexConsumers
+ val matrices = context.matrixStack()
+ matrices.push()
+ matrices.translate(
+ pos.x - context.camera().pos.x,
+ pos.y - context.camera().pos.y,
+ pos.z - context.camera().pos.z
+ )
+ matrices.multiply(context.camera().rotation)
+ matrices.scale(-.025f * scale, -.025f * scale, -1F)
+ val matrix4f = matrices.peek().positionMatrix
+ val textRenderer = MinecraftClient.getInstance().textRenderer
+ val j: Int = (.25 * 255.0f).toInt() shl 24
+ val buf = vertexConsumer.getBuffer(RenderLayer.getTextBackgroundSeeThrough())
+ buf.vertex(matrix4f, -1.0f - textRenderer.getWidth(text) / 2, -1.0f, 0.0f)
+ .color(j)
+ .light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE)
+ .next()
+ buf.vertex(matrix4f, -1.0f - textRenderer.getWidth(text) / 2, textRenderer.fontHeight.toFloat(), 0.0f)
+ .color(j)
+ .light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE)
+ .next()
+ buf.vertex(matrix4f, textRenderer.getWidth(text).toFloat() / 2, textRenderer.fontHeight.toFloat(), 0.0f)
+ .color(j)
+ .light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE)
+ .next()
+ buf.vertex(matrix4f, textRenderer.getWidth(text).toFloat() / 2, -1.0f, 0.0f)
+ .color(j)
+ .light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE)
+ .next()
+
+ matrices.translate(0F, 0F, 0.01F)
+
+ textRenderer.draw(
+ text, -textRenderer.getWidth(text).toFloat() / 2, 0f, 0xFFFFFF, false, matrix4f, vertexConsumer,
+ TextRenderer.TextLayerType.SEE_THROUGH,
+ 0, LightmapTextureManager.MAX_LIGHT_COORDINATE
+ )
+
+ vertexConsumer.drawCurrentLayer()
+ matrices.pop()
+ RenderSystem.setShaderColor(1F, 1F, 1F, 1F)
+ RenderSystem.enableDepthTest()
+ RenderSystem.enableCull()
+ RenderSystem.disableBlend()
+ }
+
fun renderWaypoint(
text: Text,
context: WorldRenderContext,