Skip to content

Commit

Permalink
fix: Designer screen using the game's original font (Minecraft) heigh…
Browse files Browse the repository at this point in the history
…t instead of selected font height.

Also fixed a NPE in AutoClicker being caused by the player's hand having nothing.
  • Loading branch information
opZywl committed Dec 7, 2024
1 parent 97de539 commit be0765d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.utils.EntityUtils.isLookingOnEntities
import net.ccbluex.liquidbounce.utils.EntityUtils.isSelected
import net.ccbluex.liquidbounce.utils.extensions.*
import net.ccbluex.liquidbounce.utils.extensions.fixedSensitivityPitch
import net.ccbluex.liquidbounce.utils.extensions.fixedSensitivityYaw
import net.ccbluex.liquidbounce.utils.extensions.getDistanceToEntityBox
import net.ccbluex.liquidbounce.utils.extensions.isBlock
import net.ccbluex.liquidbounce.utils.misc.RandomUtils
import net.ccbluex.liquidbounce.utils.misc.RandomUtils.nextFloat
import net.ccbluex.liquidbounce.utils.timing.TimeUtils.randomClickDelay
Expand Down Expand Up @@ -97,7 +100,7 @@ object AutoClicker : Module("AutoClicker", Category.COMBAT, hideModule = false)
}

if (right && mc.gameSettings.keyBindUseItem.isKeyDown && time - rightLastSwing >= rightDelay) {
if (!onlyBlocks || thePlayer.heldItem.item is ItemBlock) {
if (!onlyBlocks || thePlayer.heldItem?.item is ItemBlock) {
handleRightClick(time, doubleClick)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net.ccbluex.liquidbounce.ui.client.hud.element.Element
import net.ccbluex.liquidbounce.ui.client.hud.element.ElementInfo
import net.ccbluex.liquidbounce.ui.client.hud.element.Side
import net.ccbluex.liquidbounce.ui.font.Fonts
import net.ccbluex.liquidbounce.ui.font.GameFontRenderer
import net.ccbluex.liquidbounce.utils.ClientUtils.LOGGER
import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRoundedRect
Expand All @@ -28,9 +29,11 @@ import java.awt.Color
*
* Allows to move and customize minecraft scoreboard
*/
@ElementInfo(name = "Scoreboard")
class ScoreboardElement(x: Double = 5.0, y: Double = 0.0, scale: Float = 1F,
side: Side = Side(Side.Horizontal.RIGHT, Side.Vertical.MIDDLE)) : Element(x, y, scale, side) {
@ElementInfo(name = "Scoreboard", force = true)
class ScoreboardElement(
x: Double = 5.0, y: Double = 0.0, scale: Float = 1F,
side: Side = Side(Side.Horizontal.RIGHT, Side.Vertical.MIDDLE)
) : Element(x, y, scale, side) {

private val textRed by int("Text-R", 255, 0..255)
private val textGreen by int("Text-G", 255, 0..255)
Expand All @@ -45,10 +48,10 @@ class ScoreboardElement(x: Double = 5.0, y: Double = 0.0, scale: Float = 1F,

private val rect by boolean("Rect", false)
private val rectColorMode by choices("Rect-Color", arrayOf("Custom", "Rainbow"), "Custom") { rect }
private val rectColorRed by int("Rect-R", 0, 0..255) { rect && rectColorMode == "Custom"}
private val rectColorGreen by int("Rect-G", 111, 0..255) { rect && rectColorMode == "Custom"}
private val rectColorBlue by int("Rect-B", 255, 0..255) { rect && rectColorMode == "Custom"}
private val rectColorAlpha by int("Rect-Alpha", 255, 0..255) { rect && rectColorMode == "Custom"}
private val rectColorRed by int("Rect-R", 0, 0..255) { rect && rectColorMode == "Custom" }
private val rectColorGreen by int("Rect-G", 111, 0..255) { rect && rectColorMode == "Custom" }
private val rectColorBlue by int("Rect-B", 255, 0..255) { rect && rectColorMode == "Custom" }
private val rectColorAlpha by int("Rect-Alpha", 255, 0..255) { rect && rectColorMode == "Custom" }

private val serverIp by choices("ServerIP", arrayOf("Normal", "None", "Client", "Website"), "Normal")
private val showNumber by boolean("ShowNumber", true)
Expand All @@ -59,7 +62,7 @@ class ScoreboardElement(x: Double = 5.0, y: Double = 0.0, scale: Float = 1F,
* Draw element
*/
override fun drawElement(): Border? {
val fontRenderer = font
val (fontRenderer, fontHeight) = font to ((font as? GameFontRenderer)?.height ?: font.FONT_HEIGHT)
val textColor = textColor().rgb
val backColor = backgroundColor().rgb

Expand All @@ -83,10 +86,9 @@ class ScoreboardElement(x: Double = 5.0, y: Double = 0.0, scale: Float = 1F,
var scoreCollection = scoreboard.getSortedScores(objective)
val scores = scoreCollection.filter { it.playerName?.startsWith("#") == false }

scoreCollection = if (scores.size > 15)
scoreCollection = if (scores.size > 15) {
scores.drop(scoreCollection.size - 15)
else
scores
} else scores

var maxWidth = fontRenderer.getStringWidth(objective.displayName)

Expand All @@ -100,19 +102,19 @@ class ScoreboardElement(x: Double = 5.0, y: Double = 0.0, scale: Float = 1F,
maxWidth = maxWidth.coerceAtLeast(fontRenderer.getStringWidth(width))
}

val maxHeight = scoreCollection.size * fontRenderer.FONT_HEIGHT
val maxHeight = scoreCollection.size * fontHeight
val l1 = -maxWidth - 3 - if (rect) 3 else 0

drawRoundedRectInt(l1 - 4, -4, 7, (2 + maxHeight + fontRenderer.FONT_HEIGHT), backColor, roundedRectRadius)
drawRoundedRectInt(l1 - 4, -4, 7, maxHeight + fontHeight, backColor, roundedRectRadius)

scoreCollection.forEachIndexed { index, score ->
val team = scoreboard.getPlayersTeam(score.playerName)

var name = ScorePlayerTeam.formatPlayerName(team, score.playerName)
val scorePoints = if (showNumber) "${EnumChatFormatting.RED}${score.scorePoints}" else ""
val scorePoints = if (showNumber) "${EnumChatFormatting.RED}${score.scorePoints}" else ""

val width = 5 - if (rect) 4 else 0
val height = maxHeight - index * fontRenderer.FONT_HEIGHT.toFloat()
val height = maxHeight - index * fontHeight.toFloat()

glColor4f(1f, 1f, 1f, 1f)

Expand All @@ -122,8 +124,9 @@ class ScoreboardElement(x: Double = 5.0, y: Double = 0.0, scale: Float = 1F,
?.replace(Regex("[\u00a7&][0-9a-fk-or]"), "")?.trim()
val trimmedServerIP = mc.currentServerData?.serverIP?.trim()?.lowercase()

val domainRegex = Regex("\\b(?:[a-zA-Z0-9](?:[a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,63}\\b")
val containsDomain = nameWithoutFormatting?.let { domainRegex.containsMatchIn(it) } ?: false
val domainRegex =
Regex("\\b(?:[a-zA-Z0-9](?:[a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,63}\\b")
val containsDomain = nameWithoutFormatting?.let { domainRegex.containsMatchIn(it) } == true

runCatching {
if (nameWithoutFormatting?.lowercase() == trimmedServerIP || containsDomain) {
Expand All @@ -145,7 +148,13 @@ class ScoreboardElement(x: Double = 5.0, y: Double = 0.0, scale: Float = 1F,

fontRenderer.drawString(name, l1.toFloat(), height, textColor, shadow)
if (showNumber) {
fontRenderer.drawString(scorePoints, (width - fontRenderer.getStringWidth(scorePoints)).toFloat(), height, textColor, shadow)
fontRenderer.drawString(
scorePoints,
(width - fontRenderer.getStringWidth(scorePoints)).toFloat(),
height,
textColor,
shadow
)
}

if (index == scoreCollection.size - 1) {
Expand All @@ -156,7 +165,7 @@ class ScoreboardElement(x: Double = 5.0, y: Double = 0.0, scale: Float = 1F,
fontRenderer.drawString(
displayName,
(l1 + maxWidth / 2 - fontRenderer.getStringWidth(displayName) / 2).toFloat(),
height - fontRenderer.FONT_HEIGHT,
height - fontHeight,
textColor,
shadow
)
Expand All @@ -172,17 +181,21 @@ class ScoreboardElement(x: Double = 5.0, y: Double = 0.0, scale: Float = 1F,
2F,
if (index == scoreCollection.size - 1) -2F else height,
5F,
if (index == 0) fontRenderer.FONT_HEIGHT.toFloat() else height + fontRenderer.FONT_HEIGHT * 2F,
if (index == 0) fontHeight.toFloat() else height + fontHeight * 2F,
rectColor,
roundedRectRadius
)
}
}

return Border(-maxWidth - 5f - if (rect) 3 else 0, -2F, 5F, maxHeight + fontRenderer.FONT_HEIGHT.toFloat())
return Border(l1 - 4F, -4F, 7F, maxHeight + fontHeight.toFloat())
}

private fun backgroundColor() = Color(backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha)
private fun backgroundColor() = Color(
backgroundColorRed, backgroundColorGreen,
backgroundColorBlue, backgroundColorAlpha
)

private fun textColor() = Color(textRed, textGreen, textBlue)

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import net.ccbluex.liquidbounce.ui.client.hud.element.ElementInfo
import net.ccbluex.liquidbounce.ui.client.hud.element.Side
import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile
import net.ccbluex.liquidbounce.ui.font.Fonts
import net.ccbluex.liquidbounce.ui.font.GameFontRenderer
import net.ccbluex.liquidbounce.utils.*
import net.ccbluex.liquidbounce.utils.MovementUtils.speed
import net.ccbluex.liquidbounce.utils.extensions.getPing
Expand Down Expand Up @@ -46,14 +47,16 @@ import org.lwjgl.opengl.GL11.*
import java.awt.Color
import java.text.DecimalFormat
import java.text.SimpleDateFormat
import kotlin.math.max

/**
* CustomHUD text element
*
* Allows to draw custom text
*/
@ElementInfo(name = "Text")
class Text(x: Double = 10.0, y: Double = 10.0, scale: Float = 1F, side: Side = Side.default()) : Element(x,
class Text(x: Double = 10.0, y: Double = 10.0, scale: Float = 1F, side: Side = Side.default()) : Element(
x,
y,
scale,
side
Expand Down Expand Up @@ -104,7 +107,8 @@ class Text(x: Double = 10.0, y: Double = 10.0, scale: Float = 1F, side: Side = S

private val textColorMode by choices("Text-Color", arrayOf("Custom", "Rainbow", "Gradient"), "Custom")

private val colors = ColorSettingsInteger(this,
private val colors = ColorSettingsInteger(
this,
zeroAlphaCheck = true,
alphaApply = textColorMode != "Rainbow",
applyMax = true
Expand Down Expand Up @@ -258,12 +262,13 @@ class Text(x: Double = 10.0, y: Double = 10.0, scale: Float = 1F, side: Side = S
*/
override fun drawElement(): Border {
val stack = mc.thePlayer?.inventory?.getStackInSlot(SilentHotbar.currentSlot)
val shouldRender = showBlock && stack != null && stack.item is ItemBlock
val shouldRender = showBlock && stack?.item is ItemBlock
val showBlockScale = if (shouldRender) 1.2F else 1F
val fontHeight = ((font as? GameFontRenderer)?.height ?: font.FONT_HEIGHT) + if (shouldRender) 1.5F else 0F

assumeNonVolatile = true

if ((Scaffold.handleEvents() && onScaffold) || !onScaffold) {
if ((Scaffold.handleEvents() && onScaffold) || !onScaffold || mc.currentScreen is GuiHudDesigner) {
val rainbow = textColorMode == "Rainbow"
val gradient = textColorMode == "Gradient"

Expand All @@ -288,7 +293,7 @@ class Text(x: Double = 10.0, y: Double = 10.0, scale: Float = 1F, side: Side = S
((-2F - if (shouldRender) 6F else 0F) * (1F + backgroundScale)) * (showBlockScale * 1.15F),
(-2F * (1F + backgroundScale)) * showBlockScale,
((font.getStringWidth(displayText) + 2F) + backgroundScale) + showBlockScale,
(font.FONT_HEIGHT * backgroundScale.coerceIn(1.2F, 2F)) * showBlockScale,
fontHeight * max(backgroundScale, 1F) * showBlockScale,
when (backgroundMode) {
"Gradient" -> 0
"Rainbow" -> 0
Expand All @@ -304,7 +309,7 @@ class Text(x: Double = 10.0, y: Double = 10.0, scale: Float = 1F, side: Side = S
((-2F - if (shouldRender) 6F else 0F) * (1F + backgroundScale)) * (showBlockScale * 1.15F),
(-2F * (1F + backgroundScale)) * showBlockScale,
((font.getStringWidth(displayText) + 2F) + backgroundScale) + showBlockScale,
(font.FONT_HEIGHT * backgroundScale.coerceIn(1.2F, 2F)) * showBlockScale,
fontHeight * max(backgroundScale, 1F) * showBlockScale,
backgroundBorder,
bgBorderColors.color().rgb,
roundedBackgroundRadius
Expand Down Expand Up @@ -333,22 +338,25 @@ class Text(x: Double = 10.0, y: Double = 10.0, scale: Float = 1F, side: Side = S
glPopMatrix()
}

GradientFontShader.begin(gradient,
GradientFontShader.begin(
gradient,
gradientX,
gradientY,
textGradColors.toColorArray(maxTextGradientColors),
gradientTextSpeed,
gradientOffset
).use {
RainbowFontShader.begin(rainbow,
RainbowFontShader.begin(
rainbow,
if (rainbowX == 0f) 0f else 1f / rainbowX,
if (rainbowY == 0f) 0f else 1f / rainbowY,
rainbowOffset
).use {
font.drawString(displayText, 0F, 0F, if (rainbow) 0 else if (gradient) 0 else color.rgb, shadow)

if (editMode && mc.currentScreen is GuiHudDesigner && editTicks <= 40) {
font.drawString("_",
font.drawString(
"_",
font.getStringWidth(displayText) + 2F,
0F,
if (rainbow) ColorUtils.rainbow(400000000L).rgb else if (gradient) 0 else color.rgb,
Expand All @@ -367,10 +375,10 @@ class Text(x: Double = 10.0, y: Double = 10.0, scale: Float = 1F, side: Side = S
assumeNonVolatile = false

return Border(
((-2F - if (shouldRender) 6F else 0F) * (1F + backgroundScale)) * (showBlockScale * 1.15F),
(-2F - if (shouldRender) 6F else 0F) * (1F + backgroundScale) * (showBlockScale * 1.15F),
(-2F * (1F + backgroundScale)) * showBlockScale,
((font.getStringWidth(displayText) + 2F) + backgroundScale) + showBlockScale,
(font.FONT_HEIGHT * backgroundScale.coerceIn(1.2F, 2F)) * showBlockScale,
fontHeight * max(backgroundScale, 1F) * showBlockScale
)
}

Expand Down

0 comments on commit be0765d

Please sign in to comment.