aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/dulkirmod/utils/WorldRenderUtils.kt
blob: e0febdd767827ab8386c41cc1793e7f27d7557fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package dulkirmod.utils

import dulkirmod.DulkirMod.Companion.mc
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.GlStateManager.disableTexture2D
import net.minecraft.client.renderer.GlStateManager.enableTexture2D
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.vertex.DefaultVertexFormats
import net.minecraft.util.Vec3
import org.lwjgl.opengl.GL11


class WorldRenderUtils {

    companion object {
        fun render(
            location: Vec3,
            text: String,
            depthTest: Boolean = true,
            scale: Float = 1f,
            showDistance: Boolean = false,
            shadow: Boolean = false,
            renderBlackBox: Boolean = true,
        ) {
            if (!depthTest) {
                GL11.glDisable(GL11.GL_DEPTH_TEST)
                GL11.glDepthMask(false)
            }
            GlStateManager.pushMatrix()
            GlStateManager.enableBlend()
            GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
            GlStateManager.translate(
                location.xCoord - mc.renderManager.viewerPosX,
                location.yCoord - mc.renderManager.viewerPosY,
                location.zCoord - mc.renderManager.viewerPosZ
            )
            GlStateManager.color(1f, 1f, 1f, 0.5f)
            GlStateManager.rotate(-mc.renderManager.playerViewY, 0.0f, 1.0f, 0.0f)
            GlStateManager.rotate(mc.renderManager.playerViewX, 1.0f, 0.0f, 0.0f)
            GlStateManager.scale(-scale / 25, -scale / 25, scale / 25)

            if (renderBlackBox) {
                val j = mc.fontRendererObj.getStringWidth(text) / 2
                disableTexture2D()
                val worldRenderer = Tessellator.getInstance().worldRenderer
                worldRenderer.begin(7, DefaultVertexFormats.POSITION_COLOR)
                worldRenderer.pos((-j - 1).toDouble(), (-1).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
                worldRenderer.pos((-j - 1).toDouble(), 8.toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
                worldRenderer.pos((j + 1).toDouble(), 8.toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
                worldRenderer.pos((j + 1).toDouble(), (-1).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
                Tessellator.getInstance().draw()
                enableTexture2D()
            }

            if (shadow) {
                mc.fontRendererObj.drawStringWithShadow(
                    text,
                    -mc.fontRendererObj.getStringWidth(text) / 2f,
                    0f,
                    0
                )
            } else {
                mc.fontRendererObj.drawString(
                    text,
                    -mc.fontRendererObj.getStringWidth(text) / 2,
                    0,
                    0
                )
            }

            // for waypoints
            if (showDistance) {
                val distance = "§e${mc.thePlayer.positionVector.distanceTo(location).toInt()}m"
                GlStateManager.translate(0.0, 8.66, 0.0)
                GlStateManager.scale(.66, .66, .66)

                if (renderBlackBox) {
                    val j = mc.fontRendererObj.getStringWidth(distance) / 2
                    disableTexture2D()
                    val worldRenderer = Tessellator.getInstance().worldRenderer
                    worldRenderer.begin(7, DefaultVertexFormats.POSITION_COLOR)
                    worldRenderer.pos((-j - 1).toDouble(), (-1).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f)
                        .endVertex()
                    worldRenderer.pos((-j - 1).toDouble(), 8.toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
                    worldRenderer.pos((j + 1).toDouble(), 8.toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
                    worldRenderer.pos((j + 1).toDouble(), (-1).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f)
                        .endVertex()
                    Tessellator.getInstance().draw()
                    enableTexture2D()
                }

                if (shadow) {
                    mc.fontRendererObj.drawStringWithShadow(
                        distance,
                        -mc.fontRendererObj.getStringWidth(distance) / 2f,
                        0f,
                        0
                    )
                } else {
                    mc.fontRendererObj.drawString(
                        distance,
                        -mc.fontRendererObj.getStringWidth(distance) / 2,
                        0,
                        0
                    )
                }
            }

            GlStateManager.color(1f, 1f, 1f)
            GlStateManager.disableBlend()
            GlStateManager.popMatrix()
            if (!depthTest) {
                GL11.glEnable(GL11.GL_DEPTH_TEST)
                GL11.glDepthMask(true)
            }
        }
    }
}