aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/dulkirmod/utils/WorldRenderUtils.kt
diff options
context:
space:
mode:
authorIlmarsXd <ilmars500@gmail.com>2023-06-05 23:15:11 +0300
committerIlmarsXd <ilmars500@gmail.com>2023-06-05 23:15:11 +0300
commit89bf4d23a30c02b341df0048bc0717142af1a9ff (patch)
tree3dbdaa7eb6bd52fbc6f3dad38a73cfe1c54359ee /src/main/kotlin/dulkirmod/utils/WorldRenderUtils.kt
parentb220e76e12724a91507e894ac018e1ad6b695c9a (diff)
downloadDulkirMod-89bf4d23a30c02b341df0048bc0717142af1a9ff.tar.gz
DulkirMod-89bf4d23a30c02b341df0048bc0717142af1a9ff.tar.bz2
DulkirMod-89bf4d23a30c02b341df0048bc0717142af1a9ff.zip
Some cleanup
Diffstat (limited to 'src/main/kotlin/dulkirmod/utils/WorldRenderUtils.kt')
-rw-r--r--src/main/kotlin/dulkirmod/utils/WorldRenderUtils.kt308
1 files changed, 147 insertions, 161 deletions
diff --git a/src/main/kotlin/dulkirmod/utils/WorldRenderUtils.kt b/src/main/kotlin/dulkirmod/utils/WorldRenderUtils.kt
index 0728f38..7317d16 100644
--- a/src/main/kotlin/dulkirmod/utils/WorldRenderUtils.kt
+++ b/src/main/kotlin/dulkirmod/utils/WorldRenderUtils.kt
@@ -2,9 +2,8 @@ package dulkirmod.utils
import dulkirmod.DulkirMod.Companion.mc
import dulkirmod.mixins.AccessorRenderManager
+import net.minecraft.client.gui.FontRenderer
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.WorldRenderer
import net.minecraft.client.renderer.entity.RenderManager
@@ -14,180 +13,167 @@ import org.lwjgl.opengl.GL11
import java.awt.Color
-class WorldRenderUtils {
-
-
- companion object {
- private val tessellator: Tessellator = Tessellator.getInstance()
- private val worldRenderer: WorldRenderer = tessellator.worldRenderer
- private val renderManager: RenderManager = mc.renderManager
- fun renderString(
- 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)
+object WorldRenderUtils {
+ private val tessellator: Tessellator
+ get() = Tessellator.getInstance()
+ private val worldRenderer: WorldRenderer
+ get() = tessellator.worldRenderer
+ private val renderManager: RenderManager
+ get() = mc.renderManager
+ private val fontRenderer: FontRenderer
+ get() = mc.fontRendererObj
+
+ fun renderString(
+ 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 - renderManager.viewerPosX,
+ location.yCoord - renderManager.viewerPosY,
+ location.zCoord - renderManager.viewerPosZ
+ )
+ GlStateManager.color(1f, 1f, 1f, 0.5f)
+ GlStateManager.rotate(-renderManager.playerViewY, 0.0f, 1.0f, 0.0f)
+ GlStateManager.rotate(renderManager.playerViewX, 1.0f, 0.0f, 0.0f)
+ GlStateManager.scale(-scale / 25, -scale / 25, scale / 25)
+
+ if (renderBlackBox) {
+ val j = fontRenderer.getStringWidth(text) / 2
+ GlStateManager.disableTexture2D()
+ worldRenderer.begin(7, DefaultVertexFormats.POSITION_COLOR)
+ worldRenderer.pos(-j - 1.0, -1.0, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
+ worldRenderer.pos(-j - 1.0, 8.0, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
+ worldRenderer.pos(j + 1.0, 8.0, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
+ worldRenderer.pos(j + 1.0, -1.0, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
+ tessellator.draw()
+ GlStateManager.enableTexture2D()
+ }
+
+ if (shadow) {
+ fontRenderer.drawStringWithShadow(text, -fontRenderer.getStringWidth(text) / 2f, 0f, 0)
+ } else {
+ fontRenderer.drawString(text, -fontRenderer.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(0.66, 0.66, 0.66)
if (renderBlackBox) {
- val j = mc.fontRendererObj.getStringWidth(text) / 2
- disableTexture2D()
- val worldRenderer = Tessellator.getInstance().worldRenderer
+ val j = fontRenderer.getStringWidth(distance) / 2
+ GlStateManager.disableTexture2D()
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()
+ worldRenderer.pos(-j - 1.0, -1.0, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
+ worldRenderer.pos(-j - 1.0, 8.0, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
+ worldRenderer.pos(j + 1.0, 8.0, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
+ worldRenderer.pos(j + 1.0, -1.0, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
+ tessellator.draw()
+ GlStateManager.enableTexture2D()
}
if (shadow) {
- mc.fontRendererObj.drawStringWithShadow(
- text,
- -mc.fontRendererObj.getStringWidth(text) / 2f,
- 0f,
- 0
- )
+ fontRenderer.drawStringWithShadow(distance, -fontRenderer.getStringWidth(distance) / 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)
+ fontRenderer.drawString(distance, -fontRenderer.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)
+ }
+ }
- /**
- * Courtesy of Odin, I could not be bothered to deal with rendering code.
- */
- fun drawCustomBox(x: Double, xWidth: Double, y: Double, yWidth: Double, z: Double, zWidth: Double, color: Color, thickness: Float = 3f, phase: Boolean) {
- GlStateManager.pushMatrix()
-
- GlStateManager.color(color.red.toFloat() / 255f, color.green.toFloat() / 255f, color.blue.toFloat() / 255f, 1f)
- GlStateManager.translate(-renderManager.viewerPosX, -renderManager.viewerPosY, -renderManager.viewerPosZ)
- GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
- if (phase) GlStateManager.disableDepth()
- disableTexture2D()
- GlStateManager.disableLighting()
- GlStateManager.enableBlend()
-
- GL11.glLineWidth(thickness)
-
- val x1 = x + xWidth
- val y1 = y + yWidth
- val z1 = z + zWidth
-
- worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION)
- worldRenderer.pos(x1,y1,z1).endVertex()
- worldRenderer.pos(x1,y1,z).endVertex()
- worldRenderer.pos(x,y1,z).endVertex()
- worldRenderer.pos(x,y1,z1).endVertex()
- worldRenderer.pos(x1,y1,z1).endVertex()
- worldRenderer.pos(x1,y,z1).endVertex()
- worldRenderer.pos(x1,y,z).endVertex()
- worldRenderer.pos(x,y,z).endVertex()
- worldRenderer.pos(x,y,z1).endVertex()
- worldRenderer.pos(x,y,z).endVertex()
- worldRenderer.pos(x,y1,z).endVertex()
- worldRenderer.pos(x,y,z).endVertex()
- worldRenderer.pos(x1,y,z).endVertex()
- worldRenderer.pos(x1,y1,z).endVertex()
- worldRenderer.pos(x1,y,z).endVertex()
- worldRenderer.pos(x1,y,z1).endVertex()
- worldRenderer.pos(x,y,z1).endVertex()
- worldRenderer.pos(x,y1,z1).endVertex()
- worldRenderer.pos(x1,y1,z1).endVertex()
-
- tessellator.draw()
-
- enableTexture2D()
- GlStateManager.disableBlend()
- GlStateManager.enableDepth()
- GlStateManager.popMatrix()
- }
+ /**
+ * Courtesy of Odin, I could not be bothered to deal with rendering code.
+ */
+ fun drawCustomBox(
+ x: Double,
+ xWidth: Double,
+ y: Double,
+ yWidth: Double,
+ z: Double,
+ zWidth: Double,
+ color: Color,
+ thickness: Float = 3f,
+ phase: Boolean
+ ) {
+ GlStateManager.pushMatrix()
+
+ GlStateManager.color(color.red / 255f, color.green / 255f, color.blue / 255f, 1f)
+ GlStateManager.translate(-renderManager.viewerPosX, -renderManager.viewerPosY, -renderManager.viewerPosZ)
+ GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
+ if (phase) GlStateManager.disableDepth()
+ GlStateManager.disableTexture2D()
+ GlStateManager.disableLighting()
+ GlStateManager.enableBlend()
+
+ GL11.glLineWidth(thickness)
+
+ val x1 = x + xWidth
+ val y1 = y + yWidth
+ val z1 = z + zWidth
+
+ worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION)
+ worldRenderer.pos(x1, y1, z1).endVertex()
+ worldRenderer.pos(x1, y1, z).endVertex()
+ worldRenderer.pos(x, y1, z).endVertex()
+ worldRenderer.pos(x, y1, z1).endVertex()
+ worldRenderer.pos(x1, y1, z1).endVertex()
+ worldRenderer.pos(x1, y, z1).endVertex()
+ worldRenderer.pos(x1, y, z).endVertex()
+ worldRenderer.pos(x, y, z).endVertex()
+ worldRenderer.pos(x, y, z1).endVertex()
+ worldRenderer.pos(x, y, z).endVertex()
+ worldRenderer.pos(x, y1, z).endVertex()
+ worldRenderer.pos(x, y, z).endVertex()
+ worldRenderer.pos(x1, y, z).endVertex()
+ worldRenderer.pos(x1, y1, z).endVertex()
+ worldRenderer.pos(x1, y, z).endVertex()
+ worldRenderer.pos(x1, y, z1).endVertex()
+ worldRenderer.pos(x, y, z1).endVertex()
+ worldRenderer.pos(x, y1, z1).endVertex()
+ worldRenderer.pos(x1, y1, z1).endVertex()
+
+ tessellator.draw()
+
+ GlStateManager.enableTexture2D()
+ GlStateManager.disableBlend()
+ if (phase) GlStateManager.enableDepth()
+ GlStateManager.popMatrix()
+ }
- private fun getRenderX() : Double {
- return (mc.renderManager as AccessorRenderManager).renderX
- }
+ private fun getRenderX(): Double {
+ return (mc.renderManager as AccessorRenderManager).renderX
+ }
- private fun getRenderY() : Double {
- return (mc.renderManager as AccessorRenderManager).renderY
- }
+ private fun getRenderY(): Double {
+ return (mc.renderManager as AccessorRenderManager).renderY
+ }
- private fun getRenderZ() : Double {
- return (mc.renderManager as AccessorRenderManager).renderZ
- }
+ private fun getRenderZ(): Double {
+ return (mc.renderManager as AccessorRenderManager).renderZ
+ }
- fun fixRenderPos(x: Double, y: Double, z: Double) : Triple<Double, Double, Double> {
- return Triple(x + getRenderX(), y + getRenderY(), z + getRenderZ())
- }
+ fun fixRenderPos(x: Double, y: Double, z: Double): Triple<Double, Double, Double> {
+ return Triple(x + getRenderX(), y + getRenderY(), z + getRenderZ())
}
} \ No newline at end of file