Skip to content

Commit

Permalink
feat: Breadcrumbs with line height support.
Browse files Browse the repository at this point in the history
  • Loading branch information
opZywl committed Dec 7, 2024
1 parent e0c9e43 commit 71c911b
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import net.ccbluex.liquidbounce.value.boolean
import net.ccbluex.liquidbounce.value.choices
import net.ccbluex.liquidbounce.value.int
import org.lwjgl.opengl.GL11.*
import java.awt.Color

object Blink : Module("Blink", Category.PLAYER, gameDetecting = false, hideModule = false) {

Expand Down Expand Up @@ -98,8 +97,8 @@ object Blink : Module("Blink", Category.PLAYER, gameDetecting = false, hideModul
@EventTarget
fun onRender3D(event: Render3DEvent) {
val color =
if (Breadcrumbs.colorRainbow) rainbow()
else Color(Breadcrumbs.colorRed, Breadcrumbs.colorGreen, Breadcrumbs.colorBlue)
if (Breadcrumbs.rainbow) rainbow()
else Breadcrumbs.colors.color()

synchronized(BlinkUtils.positions) {
glPushMatrix()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,110 @@ package net.ccbluex.liquidbounce.features.module.modules.visual

import net.ccbluex.liquidbounce.event.EventTarget
import net.ccbluex.liquidbounce.event.Render3DEvent
import net.ccbluex.liquidbounce.event.UpdateEvent
import net.ccbluex.liquidbounce.event.WorldEvent
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.utils.extensions.*
import net.ccbluex.liquidbounce.utils.render.ColorSettingsInteger
import net.ccbluex.liquidbounce.utils.render.ColorUtils.rainbow
import net.ccbluex.liquidbounce.utils.render.RenderUtils.glColor
import net.ccbluex.liquidbounce.value.boolean
import net.ccbluex.liquidbounce.value.int
import net.ccbluex.liquidbounce.value.float
import org.lwjgl.opengl.GL11.*
import java.awt.Color

object Breadcrumbs : Module("Breadcrumbs", Category.VISUAL, hideModule = false) {
val colorRainbow by boolean("Rainbow", false)
val colorRed by int("R", 255, 0..255) { !colorRainbow }
val colorGreen by int("G", 179, 0..255) { !colorRainbow }
val colorBlue by int("B", 72, 0..255) { !colorRainbow }
val rainbow by boolean("Rainbow", false)
val colors = ColorSettingsInteger(this, "Color", withAlpha = false) { !rainbow }
private val lineHeight by float("LineHeight", 0.25F, 0.25F..2F)
private val temporary by boolean("Temporary", true)
private val fade by boolean("Fade", true) { temporary }
private val lifeTime by float("LifeTime", 1F, 0F..10F) { temporary }

private val positions = mutableListOf<DoubleArray>()
private val positions = mutableListOf<PositionData>()

@EventTarget
fun onRender3D(event: Render3DEvent) {
val color = if (colorRainbow) rainbow() else Color(colorRed, colorGreen, colorBlue)
val player = mc.thePlayer ?: return

if (positions.isEmpty() && !player.isMoving) {
return
}

val currentTime = System.currentTimeMillis()
val fadeSeconds = lifeTime * 1000L

glPushMatrix()

glDisable(GL_TEXTURE_2D)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_LINE_SMOOTH)
glEnable(GL_BLEND)
glDisable(GL_DEPTH_TEST)
glDisable(GL_CULL_FACE)

glEnable(GL_ALPHA_TEST)
glAlphaFunc(GL_GREATER, 0.0f)

player.interpolatedPosition(player.prevPos).let { pos ->
val data = PositionData(pos.toDoubleArray(), currentTime)

val lastData = positions.lastOrNull()?.array

if (lastData == null || !lastData.contentEquals(data.array))
positions += data
}

mc.entityRenderer.disableLightmap()

glBegin(GL_LINE_STRIP)
glColor(color)
glBegin(GL_QUADS)

val renderPosX = mc.renderManager.viewerPosX
val renderPosY = mc.renderManager.viewerPosY
val renderPosZ = mc.renderManager.viewerPosZ

for (pos in positions)
glVertex3d(pos[0] - renderPosX, pos[1] - renderPosY, pos[2] - renderPosZ)
positions.removeAll {
val timestamp = System.currentTimeMillis() - it.time
val transparency = if (fade) {
(0f..150f).lerpWith(1 - (timestamp / fadeSeconds).coerceAtMost(1.0F))
} else 150f

val startPos = it.array
val endPos = positions.getOrNull(positions.indexOf(it) + 1)?.array

if (endPos != null) {
val color = if (rainbow) rainbow() else colors.color()

glColor(color.withAlpha(transparency.toInt()))

glVertex3d(startPos[0] - renderPosX, startPos[1] - renderPosY, startPos[2] - renderPosZ)
glVertex3d(startPos[0] - renderPosX, startPos[1] - renderPosY + lineHeight, startPos[2] - renderPosZ)
glVertex3d(endPos[0] - renderPosX, endPos[1] - renderPosY + lineHeight, endPos[2] - renderPosZ)
glVertex3d(endPos[0] - renderPosX, endPos[1] - renderPosY, endPos[2] - renderPosZ)
}

temporary && timestamp > fadeSeconds
}

glColor4d(1.0, 1.0, 1.0, 1.0)
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()
}

@EventTarget
fun onUpdate(event: UpdateEvent) {
positions += doubleArrayOf(mc.thePlayer.posX, mc.thePlayer.entityBoundingBox.minY, mc.thePlayer.posZ)
}

override fun onEnable() {
val thePlayer = mc.thePlayer ?: return

positions += doubleArrayOf(thePlayer.posX, thePlayer.posY + thePlayer.eyeHeight * 0.5f, thePlayer.posZ)
positions += doubleArrayOf(thePlayer.posX, thePlayer.posY, thePlayer.posZ)
fun onWorld(event: WorldEvent) {
positions.clear()
}

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

data class PositionData(val array: DoubleArray, val time: Long)
Loading

0 comments on commit 71c911b

Please sign in to comment.