Skip to content

Commit

Permalink
feat(legacy/ChineseHat): Hat texture option. (CCBlueX#5188)
Browse files Browse the repository at this point in the history
  • Loading branch information
mems01 authored Jan 5, 2025
1 parent a4b7558 commit 6724af2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import net.ccbluex.liquidbounce.utils.extensions.*
import net.ccbluex.liquidbounce.utils.render.ColorSettingsInteger
import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.ccbluex.liquidbounce.utils.render.ColorUtils.withAlpha
import net.ccbluex.liquidbounce.utils.render.RenderUtils
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawCone
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawConesForEntities
import net.ccbluex.liquidbounce.utils.render.RenderUtils.glStateManagerColor
import net.ccbluex.liquidbounce.utils.rotation.RotationUtils.isEntityHeightVisible
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.entity.Entity
Expand All @@ -34,11 +34,10 @@ import java.awt.Color

object ChineseHat : Module("ChineseHat", Category.RENDER) {

private val useChineseHatTexture by boolean("UseChineseHatTexture", false)

private val colorMode by choices("Color", arrayOf("Custom", "DistanceColor", "Rainbow"), "Custom")
private val colors =
ColorSettingsInteger(this, zeroAlphaCheck = true, alphaApply = { true }) { colorMode == "Custom" }.with(
0, 160, 255, 150
)
private val colors = ColorSettingsInteger(this, zeroAlphaCheck = true, alphaApply = { true }) { colorMode == "Custom" }.with(0, 160, 255, 150)

private val playerHeight by float("PlayerHeight", 0.5f, 0.25f..2f)

Expand All @@ -64,8 +63,6 @@ object ChineseHat : Module("ChineseHat", Category.RENDER) {

val render = handler<Render3DEvent> {
drawConesForEntities {
var lastColor: Color? = null

for (entity in entityLookup) {
val isRenderingSelf =
entity == mc.thePlayer && (mc.gameSettings.thirdPersonView != 0 || FreeCam.handleEvents())
Expand All @@ -87,14 +84,9 @@ object ChineseHat : Module("ChineseHat", Category.RENDER) {
GlStateManager.pushMatrix()
GlStateManager.translate(x, y, z)

figureOutColor(entity).let {
if (it != lastColor) {
RenderUtils.glColor(it)
lastColor = it
}
}
glStateManagerColor(figureOutColor(entity))

drawCone(coneWidth, coneHeight)
drawCone(coneWidth, coneHeight, useChineseHatTexture)

GlStateManager.popMatrix()

Expand Down
33 changes: 28 additions & 5 deletions src/main/java/net/ccbluex/liquidbounce/utils/render/RenderUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -373,32 +373,52 @@ object RenderUtils : MinecraftInstance {

GlStateManager.disableTexture2D()
GlStateManager.disableCull()

GlStateManager.enableBlend()
GlStateManager.enableDepth()
GL11.glDepthMask(false)
GlStateManager.depthMask(false)
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)

f()

RenderUtils.glColor(Color.WHITE)
GlStateManager.resetColor()

GlStateManager.enableTexture2D()
GL11.glDepthMask(true)
GlStateManager.depthMask(true)
GlStateManager.enableCull()

GlStateManager.disableBlend()
GlStateManager.disableDepth()
GlStateManager.enableCull()

GlStateManager.popMatrix()
GlStateManager.popAttrib()
}

fun drawCone(width: Float, height: Float) {
fun drawCone(width: Float, height: Float, useTexture: Boolean = false) {
if (useTexture) {
// TODO: Maybe image option support to allow many different type of hats.
mc.textureManager.bindTexture(ResourceLocation("liquidbounce/textures/hat.png"))
GlStateManager.enableTexture2D()
GlStateManager.depthMask(true)
}

GL11.glBegin(GL11.GL_TRIANGLE_FAN)

if (useTexture) {
// Place texture in the middle, on the tip
GL11.glTexCoord2d(0.5, 0.5)
}

// The tip of the cone
GL11.glVertex3d(0.0, height.toDouble(), 0.0)

for (point in circlePoints) {
if (useTexture) {
val u = 0.5 + 0.5 * point.xCoord
val v = 0.5 + 0.5 * point.zCoord
GL11.glTexCoord2d(u, v)
}

GL11.glVertex3d(point.xCoord * width, 0.0, point.zCoord * width)
}

Expand Down Expand Up @@ -976,6 +996,9 @@ object RenderUtils : MinecraftInstance {

fun glColor(color: Color) = glColor(color.red, color.green, color.blue, color.alpha)

fun glStateManagerColor(color: Color) =
GlStateManager.color(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f)

private fun glColor(hex: Int) = glColor(hex shr 16 and 0xFF, hex shr 8 and 0xFF, hex and 0xFF, hex shr 24 and 0xFF)

fun draw2D(entity: EntityLivingBase, posX: Double, posY: Double, posZ: Double, color: Int, backgroundColor: Int) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6724af2

Please sign in to comment.