Skip to content

Commit

Permalink
feat/fix: Dome visuals for TNTESP module + fixed custom hotbar making…
Browse files Browse the repository at this point in the history
… global line rendering calls abnormally thick
  • Loading branch information
opZywl committed Dec 11, 2024
1 parent 6ca98ad commit d26e20d
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,47 @@ package net.ccbluex.liquidbounce.features.module.modules.visual

import net.ccbluex.liquidbounce.event.EventTarget
import net.ccbluex.liquidbounce.event.Render3DEvent
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.utils.extensions.interpolatedPosition
import net.ccbluex.liquidbounce.utils.extensions.prevPos
import net.ccbluex.liquidbounce.utils.extensions.withAlpha
import net.ccbluex.liquidbounce.utils.render.ColorSettingsInteger
import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawDome
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawEntityBox
import net.ccbluex.liquidbounce.value.boolean
import net.ccbluex.liquidbounce.value.choices
import net.ccbluex.liquidbounce.value.float
import net.minecraft.entity.item.EntityTNTPrimed
import org.lwjgl.opengl.GL11.*
import java.awt.Color

object TNTESP : Module("TNTESP", Category.VISUAL, spacedName = "TNT ESP", hideModule = false) {

private val dangerZoneDome by boolean("DangerZoneDome", false)
private val mode by choices("Mode", arrayOf("Lines", "Triangles", "Filled"), "Lines") { dangerZoneDome }
private val lineWidth by float("LineWidth", 1F, 0.5F..5F) { mode == "Lines" }
private val rainbow by boolean("Rainbow", false) { dangerZoneDome }
private val colors = ColorSettingsInteger(this, "Dome", alphaApply = { dangerZoneDome })
{ !rainbow && dangerZoneDome }

private val renderModes = mapOf("Lines" to GL_LINES, "Triangles" to GL_TRIANGLES, "Filled" to GL_QUADS)

@EventTarget
fun onRender3D(event: Render3DEvent) {
val renderMode = renderModes[mode] ?: return
val color = if (rainbow) ColorUtils.rainbow().withAlpha(colors.color().alpha) else colors.color()

val width = lineWidth.takeIf { mode == "Lines" }

mc.theWorld.loadedEntityList.forEach {
if (it !is EntityTNTPrimed)
return@forEach
if (it !is EntityTNTPrimed) return@forEach

if (dangerZoneDome) {
drawDome(it.interpolatedPosition(it.prevPos), 8.0, 8.0, width, color, renderMode)
}

drawEntityBox(it, Color.RED, false)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -39,8 +40,7 @@
import java.util.List;

import static net.minecraft.client.renderer.GlStateManager.*;
import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.*;

@Mixin(GuiIngame.class)
@SideOnly(Side.CLIENT)
Expand Down Expand Up @@ -105,6 +105,7 @@ private void injectCustomHotbar(ScaledResolution resolution, float delta, Callba

List<float[]> gradientColors = ColorSettingsKt.toColorArray(hud.getBgGradColors(), hud.getMaxHotbarGradientColors());

GL11.glPushAttrib(GL_ALL_ATTRIB_BITS);
resetColor();

boolean isGradient = hud.getHotbarMode().equals("Gradient");
Expand Down Expand Up @@ -183,6 +184,8 @@ private void injectCustomHotbar(ScaledResolution resolution, float delta, Callba
disableRescaleNormal();
disableBlend();

GL11.glPopAttrib();

AWTFontRenderer.Companion.setAssumeNonVolatile(false);

ci.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object RenderUtils : MinecraftInstance() {
fun deltaTimeNormalized(ticks: Int = 50) = (deltaTime / ticks.toDouble()).coerceAtMost(1.0)

private const val CIRCLE_STEPS = 40
val circlePoints = (0..CIRCLE_STEPS).map {
private val circlePoints = (0..CIRCLE_STEPS).map {
val theta = 2 * PI * it / CIRCLE_STEPS
Vec3(-sin(theta), 0.0, cos(theta))
}
Expand Down Expand Up @@ -239,6 +239,86 @@ object RenderUtils : MinecraftInstance() {
glPopAttrib()
}

/**
* Draws a dome around the specified [pos]
*
* Only [GL_LINES], [GL_TRIANGLES] and [GL_QUADS] are allowed.
*/
fun drawDome(pos: Vec3, hRadius: Double, vRadius: Double, lineWidth: Float? = null, color: Color, renderMode: Int) {
require(renderMode in arrayOf(GL_LINES, GL_TRIANGLES, GL_QUADS))
val manager = mc.renderManager ?: return
val (renderX, renderY, renderZ) = Triple(manager.viewerPosX, manager.viewerPosY, manager.viewerPosZ)
val (posX, posY, posZ) = pos
val vStep = Math.PI / (CIRCLE_STEPS / 2)
val hStep = 2 * Math.PI / CIRCLE_STEPS
glPushAttrib(GL_ALL_ATTRIB_BITS)
glPushMatrix()
glDisable(GL_TEXTURE_2D)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_LINE_SMOOTH)
lineWidth?.let { glLineWidth(it) }
glDisable(GL_DEPTH_TEST)
glDisable(GL_CULL_FACE)
glEnable(GL_ALPHA_TEST)
glAlphaFunc(GL_GREATER, 0.0f)
glBegin(renderMode)
RenderUtils.glColor(color)
for (i in -1 until CIRCLE_STEPS / 2) {
val vAngle1 = i * vStep
val vAngle2 = (i + 1) * vStep
for (j in -1 until CIRCLE_STEPS) {
val hAngle1 = j * hStep
val hAngle2 = (j + 1) * hStep
val p1 = calculateDomeVertex(posX, posY, posZ, vAngle1, hAngle1, hRadius, vRadius)
val p2 = calculateDomeVertex(posX, posY, posZ, vAngle2, hAngle1, hRadius, vRadius)
val p3 = calculateDomeVertex(posX, posY, posZ, vAngle2, hAngle2, hRadius, vRadius)
val p4 = calculateDomeVertex(posX, posY, posZ, vAngle1, hAngle2, hRadius, vRadius)
when (renderMode) {
GL_QUADS -> {
glVertex3d(p1[0] - renderX, p1[1] - renderY, p1[2] - renderZ)
glVertex3d(p2[0] - renderX, p2[1] - renderY, p2[2] - renderZ)
glVertex3d(p3[0] - renderX, p3[1] - renderY, p3[2] - renderZ)
glVertex3d(p4[0] - renderX, p4[1] - renderY, p4[2] - renderZ)
}
GL_LINES, GL_TRIANGLES -> {
glVertex3d(p1[0] - renderX, p1[1] - renderY, p1[2] - renderZ)
glVertex3d(p2[0] - renderX, p2[1] - renderY, p2[2] - renderZ)
glVertex3d(p2[0] - renderX, p2[1] - renderY, p2[2] - renderZ)
glVertex3d(p3[0] - renderX, p3[1] - renderY, p3[2] - renderZ)
glVertex3d(p3[0] - renderX, p3[1] - renderY, p3[2] - renderZ)
glVertex3d(p4[0] - renderX, p4[1] - renderY, p4[2] - renderZ)
glVertex3d(p4[0] - renderX, p4[1] - renderY, p4[2] - renderZ)
glVertex3d(p1[0] - renderX, p1[1] - renderY, p1[2] - renderZ)
}
}
}
}
glEnd()
glEnable(GL_CULL_FACE)
glEnable(GL_DEPTH_TEST)
glDisable(GL_ALPHA_TEST)
glDisable(GL_LINE_SMOOTH)
glDisable(GL_BLEND)
glEnable(GL_TEXTURE_2D)
glPopMatrix()
glPopAttrib()
}
private fun calculateDomeVertex(
entityX: Double,
entityY: Double,
entityZ: Double,
theta: Double,
phi: Double,
horizontalRadius: Double,
verticalRadius: Double
): DoubleArray {
return doubleArrayOf(
entityX + horizontalRadius * sin(theta) * cos(phi),
entityY + verticalRadius * cos(theta),
entityZ + horizontalRadius * sin(theta) * sin(phi)
)
}

fun drawEntityBox(entity: Entity, color: Color, outline: Boolean) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
Expand Down

0 comments on commit d26e20d

Please sign in to comment.