diff --git a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/render/PointerESP.kt b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/render/PointerESP.kt index 19e6c0a607f..81e0e0d8b37 100644 --- a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/render/PointerESP.kt +++ b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/render/PointerESP.kt @@ -102,6 +102,7 @@ object PointerESP : Module("PointerESP", Category.RENDER, hideModule = false) { private fun draw(ticks: Float) { val player = mc.thePlayer ?: return + val world = mc.theWorld ?: return val arrowRadius = -arrowRadius val halfAngle = arrowAngle / 2 @@ -115,7 +116,7 @@ object PointerESP : Module("PointerESP", Category.RENDER, hideModule = false) { glEnable(GL_LINE_SMOOTH) glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) - for (entity in mc.theWorld.loadedEntityList) { + for (entity in world.loadedEntityList.filterNotNull()) { if (entity !is EntityLivingBase || !bot && isBot(entity)) continue if (!team && Teams.isInYourTeam(entity)) continue diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/hud/element/elements/Armor.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/hud/element/elements/Armor.kt index 72c241ca4f3..ef8c98942ce 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/hud/element/elements/Armor.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/hud/element/elements/Armor.kt @@ -47,10 +47,15 @@ class Armor( for (index in 3 downTo 0) { val stack = mc.thePlayer.inventory.armorInventory[index] ?: continue + glPushMatrix() + glEnable(GL_BLEND) + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) enableGUIStandardItemLighting() renderItem.renderItemIntoGUI(stack, x, y) renderItem.renderItemOverlays(mc.fontRendererObj, stack, x, y) disableStandardItemLighting() + glDisable(GL_BLEND) + glPopMatrix() when (modeValue) { "Horizontal" -> x += 18 diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/hud/element/elements/ScoreboardElement.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/hud/element/elements/ScoreboardElement.kt index 5e8ac08f946..7e1e080ca92 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/hud/element/elements/ScoreboardElement.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/hud/element/elements/ScoreboardElement.kt @@ -19,6 +19,7 @@ import net.ccbluex.liquidbounce.utils.render.ColorUtils import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRoundedRect import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRoundedRectInt import net.ccbluex.liquidbounce.config.* +import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile import net.minecraft.scoreboard.ScoreObjective import net.minecraft.scoreboard.ScorePlayerTeam import net.minecraft.util.EnumChatFormatting @@ -62,135 +63,139 @@ class ScoreboardElement( * Draw element */ override fun drawElement(): Border? { - if (AntiBlind.handleEvents() && AntiBlind.scoreboard) - return null + assumeNonVolatile { + if (AntiBlind.handleEvents() && AntiBlind.scoreboard) + return null - val (fontRenderer, fontHeight) = font to ((font as? GameFontRenderer)?.height ?: font.FONT_HEIGHT) - val textColor = textColor().rgb - val backColor = backgroundColor().rgb + val (fontRenderer, fontHeight) = font to ((font as? GameFontRenderer)?.height ?: font.FONT_HEIGHT) + val textColor = textColor().rgb + val backColor = backgroundColor().rgb - val rectColorMode = rectColorMode - val rectCustomColor = Color(rectColorRed, rectColorGreen, rectColorBlue, rectColorAlpha).rgb + val rectColorMode = rectColorMode + val rectCustomColor = Color(rectColorRed, rectColorGreen, rectColorBlue, rectColorAlpha).rgb - val worldScoreboard = mc.theWorld.scoreboard - var currObjective: ScoreObjective? = null - val playerTeam = worldScoreboard.getPlayersTeam(mc.thePlayer.name) + val worldScoreboard = mc.theWorld.scoreboard ?: return null + var currObjective: ScoreObjective? = null + val playerTeam = worldScoreboard.getPlayersTeam(mc.thePlayer.name) - if (playerTeam != null) { - val colorIndex = playerTeam.chatFormat.colorIndex + if (playerTeam != null) { + val colorIndex = playerTeam.chatFormat.colorIndex - if (colorIndex >= 0) - currObjective = worldScoreboard.getObjectiveInDisplaySlot(3 + colorIndex) - } - - val objective = currObjective ?: worldScoreboard.getObjectiveInDisplaySlot(1) ?: return null - - val scoreboard = objective.scoreboard - var scoreCollection = scoreboard.getSortedScores(objective) - val scores = scoreCollection.filter { it.playerName?.startsWith("#") == false } + if (colorIndex >= 0) + currObjective = worldScoreboard.getObjectiveInDisplaySlot(3 + colorIndex) + } - scoreCollection = if (scores.size > 15) { - scores.drop(scoreCollection.size - 15) - } else scores + val objective = currObjective ?: worldScoreboard.getObjectiveInDisplaySlot(1) ?: return null - var maxWidth = fontRenderer.getStringWidth(objective.displayName) + val scoreboard = objective.scoreboard ?: return null + var scoreCollection = scoreboard.getSortedScores(objective) ?: return null + val scores = scoreCollection.filter { it.playerName?.startsWith("#") == false } - for (score in scoreCollection) { - val scorePlayerTeam = scoreboard.getPlayersTeam(score.playerName) - val width = "${ - ScorePlayerTeam.formatPlayerName( - scorePlayerTeam, - score.playerName - ) - }: ${EnumChatFormatting.RED}${score.scorePoints}" - maxWidth = maxWidth.coerceAtLeast(fontRenderer.getStringWidth(width)) - } + scoreCollection = if (scores.size > 15) { + scores.drop(scoreCollection.size - 15) + } else scores - val maxHeight = scoreCollection.size * fontHeight - val l1 = -maxWidth - 3 - if (rect) 3 else 0 + var maxWidth = fontRenderer.getStringWidth(objective.displayName) - drawRoundedRectInt(l1 - 4, -4, 7, maxHeight + fontHeight, backColor, roundedRectRadius) + for (score in scoreCollection) { + val scorePlayerTeam = scoreboard.getPlayersTeam(score.playerName) + val width = "${ + ScorePlayerTeam.formatPlayerName( + scorePlayerTeam, + score.playerName + ) + }: ${EnumChatFormatting.RED}${score.scorePoints}" + maxWidth = maxWidth.coerceAtLeast(fontRenderer.getStringWidth(width)) + } - scoreCollection.forEachIndexed { index, score -> - val team = scoreboard.getPlayersTeam(score.playerName) + val maxHeight = scoreCollection.size * fontHeight + val l1 = -maxWidth - 3 - if (rect) 3 else 0 - var name = ScorePlayerTeam.formatPlayerName(team, score.playerName) - val scorePoints = "${EnumChatFormatting.RED}${score.scorePoints}" + drawRoundedRectInt(l1 - 4, -4, 7, maxHeight + fontHeight, backColor, roundedRectRadius) - val width = 5 - if (rect) 4 else 0 - val height = maxHeight - index * fontHeight.toFloat() + scoreCollection.filterNotNull().forEachIndexed { index, score -> + val team = scoreboard.getPlayersTeam(score.playerName) - glColor4f(1f, 1f, 1f, 1f) + var name = ScorePlayerTeam.formatPlayerName(team, score.playerName) + val scorePoints = "${EnumChatFormatting.RED}${score.scorePoints}" - if (serverIp != "Normal") { - runCatching { - val nameWithoutFormatting = name?.replace(EnumChatFormatting.RESET.toString(), "") - ?.replace(Regex("[\u00a7&][0-9a-fk-or]"), "")?.trim() - val trimmedServerIP = mc.currentServerData?.serverIP?.trim()?.lowercase() + val width = 5 - if (rect) 4 else 0 + val height = maxHeight - index * fontHeight.toFloat() - 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 + glColor4f(1f, 1f, 1f, 1f) - runCatching { - if (nameWithoutFormatting?.lowercase() == trimmedServerIP || containsDomain) { - val colorCode = name?.substring(0, 2) ?: "§9" - name = when (serverIp.lowercase()) { - "none" -> "" - "client" -> "$colorCode$CLIENT_NAME" - "website" -> "$colorCode$CLIENT_WEBSITE" - else -> return null + if (serverIp != "Normal") { + try { + val nameWithoutFormatting = name?.replace(EnumChatFormatting.RESET.toString(), "") + ?.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) } == true + + runCatching { + if (nameWithoutFormatting?.lowercase() == trimmedServerIP || containsDomain) { + val colorCode = name?.substring(0, 2) ?: "§9" + name = when (serverIp.lowercase()) { + "none" -> "" + "client" -> "$colorCode$CLIENT_NAME" + "website" -> "$colorCode$CLIENT_WEBSITE" + else -> return null + } } + }.onFailure { + LOGGER.error("Error while changing Scoreboard Server IP: ${it.message}") } - }.onFailure { - LOGGER.error("Error while changing Scoreboard Server IP: ${it.message}") + } catch (e: Exception) { + LOGGER.error("Error while drawing ScoreboardElement", e) } - }.onFailure { - LOGGER.error("Failed to run: ${it.message}") } - } - - fontRenderer.drawString(name, l1.toFloat(), height, textColor, shadow) - fontRenderer.drawString( - scorePoints, - (width - fontRenderer.getStringWidth(scorePoints)).toFloat(), - height, - textColor, - shadow - ) - - if (index == scoreCollection.size - 1) { - val displayName = objective.displayName - - glColor4f(1f, 1f, 1f, 1f) + fontRenderer.drawString(name, l1.toFloat(), height, textColor, shadow) fontRenderer.drawString( - displayName, - (l1 + maxWidth / 2 - fontRenderer.getStringWidth(displayName) / 2).toFloat(), - height - fontHeight, + scorePoints, + (width - fontRenderer.getStringWidth(scorePoints)).toFloat(), + height, textColor, shadow ) - } - if (rect) { - val rectColor = when (rectColorMode) { - "Rainbow" -> ColorUtils.rainbow(400000000L * index).rgb - else -> rectCustomColor + if (index == scoreCollection.size - 1) { + val displayName = objective.displayName + + glColor4f(1f, 1f, 1f, 1f) + + fontRenderer.drawString( + displayName, + (l1 + maxWidth / 2 - fontRenderer.getStringWidth(displayName) / 2).toFloat(), + height - fontHeight, + textColor, + shadow + ) } - drawRoundedRect( - 2F, - if (index == scoreCollection.size - 1) -2F else height, - 5F, - if (index == 0) fontHeight.toFloat() else height + fontHeight * 2F, - rectColor, - roundedRectRadius - ) + if (rect) { + val rectColor = when (rectColorMode) { + "Rainbow" -> ColorUtils.rainbow(400000000L * index).rgb + else -> rectCustomColor + } + + drawRoundedRect( + 2F, + if (index == scoreCollection.size - 1) -2F else height, + 5F, + if (index == 0) fontHeight.toFloat() else height + fontHeight * 2F, + rectColor, + roundedRectRadius + ) + } } + + return Border(l1 - 4F, -4F, 7F, maxHeight + fontHeight.toFloat()) } - return Border(l1 - 4F, -4F, 7F, maxHeight + fontHeight.toFloat()) + return null } private fun backgroundColor() = Color( diff --git a/src/main/java/net/ccbluex/liquidbounce/utils/render/RenderUtils.kt b/src/main/java/net/ccbluex/liquidbounce/utils/render/RenderUtils.kt index 9bc00c0a3d9..fa627506176 100644 --- a/src/main/java/net/ccbluex/liquidbounce/utils/render/RenderUtils.kt +++ b/src/main/java/net/ccbluex/liquidbounce/utils/render/RenderUtils.kt @@ -843,7 +843,6 @@ object RenderUtils : MinecraftInstance() { fun drawImage(image: ResourceLocation?, x: Int, y: Int, width: Int, height: Int) { glPushMatrix() - glPushAttrib(GL_ALL_ATTRIB_BITS) glDisable(GL_DEPTH_TEST) glEnable(GL_BLEND) glDepthMask(false) @@ -856,7 +855,6 @@ object RenderUtils : MinecraftInstance() { glDepthMask(true) glDisable(GL_BLEND) glEnable(GL_DEPTH_TEST) - glPopAttrib() glPopMatrix() }