Skip to content

Commit

Permalink
feat/fix/refactor(legacy): jumpcircle module, fixed targethud (anim, …
Browse files Browse the repository at this point in the history
…healthbar) & renderutils cleanup (CCBlueX#5339)
  • Loading branch information
EclipsesDev authored Jan 18, 2025
1 parent fac7760 commit 9a2d43c
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ object ModuleManager : Listenable, Collection<Module> by MODULE_REGISTRY {
ItemESP,
ItemPhysics,
ItemTeleport,
JumpCircle,
KeepAlive,
KeepContainer,
KeepTabList,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* LiquidBounce Hacked Client
* A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
* https://github.com/CCBlueX/LiquidBounce/
*/
package net.ccbluex.liquidbounce.features.module.modules.render

import net.ccbluex.liquidbounce.config.boolean
import net.ccbluex.liquidbounce.config.color
import net.ccbluex.liquidbounce.config.floatRange
import net.ccbluex.liquidbounce.config.int
import net.ccbluex.liquidbounce.event.JumpEvent
import net.ccbluex.liquidbounce.event.Render3DEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.utils.client.ClientUtils.runTimeTicks
import net.ccbluex.liquidbounce.utils.extensions.currPos
import net.ccbluex.liquidbounce.utils.extensions.lerpWith
import net.ccbluex.liquidbounce.utils.render.ColorUtils.shiftHue
import net.ccbluex.liquidbounce.utils.render.ColorUtils.withAlpha
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawHueCircle
import net.minecraft.util.Vec3
import java.awt.Color

/**
* @author Original by Ell1ott (Nextgen)
* @author Modified by EclipsesDev
*/
object JumpCircle : Module("JumpCircle", Category.RENDER, hideModule = false) {
private val circleRadius by floatRange("CircleRadius", 0.15F..0.8F, 0F..3F)
private val innerColor = color("InnerColor", Color(0, 0, 0, 50))
private val outerColor = color("OuterColor", Color(0, 111, 255, 255))
private val hueOffsetAnim by int("HueOffsetAnim", 63, -360..360)
private val lifeTime by int("LifeTime", 20, 1..50, "Ticks")
private val blackHole by boolean("BlackHole", false)

private val circles = mutableListOf<JumpData>()

val onJump = handler<JumpEvent> {
circles += JumpData(mc.thePlayer.currPos, runTimeTicks + if (blackHole) lifeTime else 0)
}

val onRender3D = handler<Render3DEvent> {
val partialTick = it.partialTicks

circles.removeIf {
val progress = ((runTimeTicks + partialTick) - it.endTime) / lifeTime
val radius = circleRadius.lerpWith(progress)

drawHueCircle(
it.pos,
radius,
animateColor(innerColor.selectedColor(), progress),
animateColor(outerColor.selectedColor(), progress)
)

progress >= 1F
}
}

override fun onDisable() {
circles.clear()
}

private fun animateColor(baseColor: Color, progress: Float): Color {
val color = baseColor.withAlpha((baseColor.alpha * (1 - progress)).toInt().coerceIn(0, 255))

if (hueOffsetAnim == 0) {
return color
}

return shiftHue(color, (hueOffsetAnim * progress).toInt())
}

data class JumpData(val pos: Vec3, val endTime: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRect
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRoundedBorderRect
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawScaledCustomSizeModalRect
import net.ccbluex.liquidbounce.utils.render.animation.AnimationUtil
import net.ccbluex.liquidbounce.utils.render.animation.AnimationUtil.debugFPS
import net.ccbluex.liquidbounce.utils.render.shader.shaders.RainbowShader
import net.ccbluex.liquidbounce.utils.render.shader.shaders.FrostShader
import net.minecraft.client.gui.GuiChat
Expand All @@ -32,11 +31,8 @@ import java.awt.Color
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.util.*
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.math.abs
import kotlin.math.pow
import kotlin.math.roundToInt

/**
* A Target HUD
Expand Down Expand Up @@ -92,19 +88,13 @@ class Target : Element() {
private var delayCounter = 0

override fun drawElement(): Border {
val smoothMode = animation == "Smooth"
val fadeMode = animation == "Fade"

val shouldRender = KillAura.handleEvents() && KillAura.target != null || mc.currentScreen is GuiChat
val target = KillAura.target ?: if (delayCounter >= vanishDelay) mc.thePlayer else lastTarget ?: mc.thePlayer

assumeNonVolatile {
val shouldRender = KillAura.handleEvents() && KillAura.target != null || mc.currentScreen is GuiChat
val smoothMode = animation == "Smooth"
val fadeMode = animation == "Fade"

var (textAlpha, borderAlpha) = if (fadeMode) {
intArrayOf(alphaText, alphaBorder)
} else {
intArrayOf(textColor.alpha, borderColor.alpha)
}

val stringWidth = (40f + (target.name?.let(titleFont::getStringWidth) ?: 0)).coerceAtLeast(118F)

if (shouldRender) {
Expand All @@ -113,24 +103,18 @@ class Target : Element() {
delayCounter++
}

if (smoothMode && !shouldRender && delayCounter >= vanishDelay) {
val decrement = (animationSpeed / (debugFPS / 60)).coerceAtLeast(0f)
width -= decrement
height -= decrement
}

if (shouldRender || isRendered || isAlpha) {
val targetHealth = getHealth(target!!, healthFromScoreboard, absorption)
val maxHealth = target.maxHealth + if (absorption) target.absorptionAmount else 0F

// Calculate health color based on entity's health
val healthColor = when {
targetHealth <= 0 -> Color(255, 0, 0, if (fadeMode) alphaText else textAlpha)
targetHealth <= 0 -> Color(255, 0, 0, if (fadeMode) alphaText else textColor.alpha)
else -> {
ColorUtils.interpolateHealthColor(
target,
255, 255, 0,
if (fadeMode) alphaText else textAlpha,
if (fadeMode) alphaText else textColor.alpha,
healthFromScoreboard,
absorption
)
Expand All @@ -143,24 +127,21 @@ class Target : Element() {

if (smoothMode) {
val targetWidth = if (shouldRender) stringWidth else if (delayCounter >= vanishDelay) 0f else width
width =
AnimationUtil.base(width.toDouble(), targetWidth.toDouble(), animationSpeed.toDouble())
.toFloat()
.coerceAtLeast(0f)
width = AnimationUtil.base(width.toDouble(), targetWidth.toDouble(), animationSpeed.toDouble())
.toFloat()
.coerceAtLeast(0f)

val targetHeight = if (shouldRender) 40f else if (delayCounter >= vanishDelay) 0f else height
height =
AnimationUtil.base(height.toDouble(), targetHeight.toDouble(), animationSpeed.toDouble())
.toFloat()
.coerceAtLeast(0f)
height = AnimationUtil.base(height.toDouble(), targetHeight.toDouble(), animationSpeed.toDouble())
.toFloat()
.coerceAtLeast(0f)
} else {
width = stringWidth
height = 40f

val targetText = if (shouldRender) textAlpha else if (delayCounter >= vanishDelay) 0f else alphaText
alphaText =
AnimationUtil.base(alphaText.toDouble(), targetText.toDouble(), animationSpeed.toDouble())
.roundToInt()
val targetText = if (shouldRender) textColor.alpha else if (delayCounter >= vanishDelay) 0f else alphaText
alphaText = AnimationUtil.base(alphaText.toDouble(), targetText.toDouble(), animationSpeed.toDouble())
.toInt()

val targetBackground = if (shouldRender) {
backgroundColor.alpha
Expand All @@ -172,26 +153,27 @@ class Target : Element() {
alphaBackground.toDouble(),
targetBackground.toDouble(),
animationSpeed.toDouble()
).roundToInt()
).toInt()

val targetBorder = if (shouldRender) {
borderColor.alpha
} else if (delayCounter >= vanishDelay) {
0f
} else alphaBorder

alphaBorder =
AnimationUtil.base(alphaBorder.toDouble(), targetBorder.toDouble(), animationSpeed.toDouble())
.roundToInt()

borderAlpha = alphaBorder
textAlpha = alphaText
alphaBorder = AnimationUtil.base(alphaBorder.toDouble(), targetBorder.toDouble(), animationSpeed.toDouble())
.toInt()
}

val backgroundAlpha = if (fadeMode) alphaBackground else backgroundColor.alpha
val backgroundCustomColor = backgroundColor.withAlpha(backgroundAlpha).rgb
val borderCustomColor = borderColor.withAlpha(borderAlpha).rgb
val textCustomColor = textColor.withAlpha(textAlpha).rgb
val backgroundCustomColor = backgroundColor.withAlpha(
if (fadeMode) alphaBackground else backgroundColor.alpha
).rgb
val borderCustomColor = borderColor.withAlpha(
if (fadeMode) alphaBorder else borderColor.alpha
).rgb
val textCustomColor = textColor.withAlpha(
if (fadeMode) alphaText else textColor.alpha
).rgb

val rainbowOffset = System.currentTimeMillis() % 10000 / 10000F
val rainbowX = if (rainbowX == 0f) 0f else 1f / rainbowX
Expand All @@ -202,7 +184,10 @@ class Target : Element() {
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

if (fadeMode && shouldRender || smoothMode && shouldRender || delayCounter < vanishDelay) {
if (fadeMode && isAlpha || smoothMode && isRendered || delayCounter < vanishDelay) {
val width = width.coerceAtLeast(0F)
val height = height.coerceAtLeast(0F)

when (backgroundMode) {
"Frost" -> {
FrostShader.begin(true, frostIntensity).use {
Expand All @@ -227,7 +212,7 @@ class Target : Element() {
}

// Health bar
val healthBarWidth = (targetHealth / maxHealth).coerceIn(0F, 1F) * (width - 6f)
val healthBarWidth = (targetHealth / maxHealth).coerceIn(0F, 1F) * (width - 6f).coerceAtLeast(0F)
drawRect(3F, 34F, 3f + healthBarWidth, 36F, healthColor.rgb)

// Easing health update
Expand All @@ -244,31 +229,36 @@ class Target : Element() {
drawRect(3f + healthBarWidth, 34F, 3f + easingHealthWidth, 36F, Color(252, 185, 65).rgb)
}

// Draw title text
target.name?.let { titleFont.drawString(it, 36F, 5F, textCustomColor, textShadow) }
val shouldRenderBody = (fadeMode && alphaText + alphaBackground + alphaBorder > 100) ||
(smoothMode && width + height > 100)

// Draw body text
bodyFont.drawString(
"Distance: ${decimalFormat.format(mc.thePlayer.getDistanceToEntityBox(target))}",
36F,
15F,
textCustomColor,
textShadow
)
if (shouldRenderBody) {
// Draw title text
target.name?.let { titleFont.drawString(it, 36F, 5F, textCustomColor, textShadow) }

// Draw info
mc.netHandler?.getPlayerInfo(target.uniqueID)?.let {
// Draw body text
bodyFont.drawString(
"Ping: ${it.responseTime.coerceAtLeast(0)}",
"Distance: ${decimalFormat.format(mc.thePlayer.getDistanceToEntityBox(target))}",
36F,
24F,
15F,
textCustomColor,
textShadow
)

// Draw head
val locationSkin = it.locationSkin
drawHead(locationSkin, 30, 30)
// Draw info
mc.netHandler?.getPlayerInfo(target.uniqueID)?.let {
bodyFont.drawString(
"Ping: ${it.responseTime.coerceAtLeast(0)}",
36F,
24F,
textCustomColor,
textShadow
)

// Draw head
val locationSkin = it.locationSkin
drawHead(locationSkin, 30, 30)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.awt.Font
/**
* Extends Minecraft's [FontRenderer] for potential fallback usage.
*
* * @author opZywl
* @author opZywl
*/
class GameFontRenderer(
font: Font
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/net/ccbluex/liquidbounce/utils/render/ColorUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ object ColorUtils {
}

fun Color.withAlpha(a: Int) = Color(red, green, blue, a)

fun Color.normalize() = Color(this.red / 255f, this.green / 255f, this.blue / 255f, this.alpha / 255f)

fun packARGBValue(r: Int, g: Int, b: Int, a: Int = 0xff): Int {
return (a and 255 shl 24) or (r and 255 shl 16) or (g and 255 shl 8) or (b and 255)
}
Expand Down Expand Up @@ -128,6 +130,16 @@ object ColorUtils {
return Color(red, green, b, a)
}

/**
* @author Ell1ott
*/
fun shiftHue(color: Color, shift: Int): Color {
val hsb = Color.RGBtoHSB(color.red, color.green, color.blue, null)
val shiftedColor = Color(Color.HSBtoRGB((hsb[0] + shift.toFloat() / 360) % 1F, hsb[1], hsb[2]))

return Color(shiftedColor.red, shiftedColor.green, shiftedColor.blue, color.alpha)
}

fun fade(colorSettings: ColorSettingsInteger, speed: Int, count: Int): Color {
val color = colorSettings.color()

Expand Down
Loading

0 comments on commit 9a2d43c

Please sign in to comment.