From 1401cb3a23043cbfa8102210638dca6a8f528d9f Mon Sep 17 00:00:00 2001 From: mems01 <70612656+mems01@users.noreply.github.com> Date: Thu, 19 Dec 2024 20:36:48 +0200 Subject: [PATCH] fix(legacy): FreeLook being incompatible with Tracers. (#4971) --- .../module/modules/render/FreeLook.kt | 33 +++++-- .../features/module/modules/render/Tracers.kt | 90 ++++++++++--------- 2 files changed, 70 insertions(+), 53 deletions(-) diff --git a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/render/FreeLook.kt b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/render/FreeLook.kt index 86eb41e95fd..474be678600 100644 --- a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/render/FreeLook.kt +++ b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/render/FreeLook.kt @@ -23,6 +23,8 @@ object FreeLook : Module("FreeLook", Category.RENDER) { private var savedCurrRotation = Rotation.ZERO private var savedPrevRotation = Rotation.ZERO + private var modifySavedRotations = true + override fun onEnable() { mc.thePlayer?.run { currRotation = rotation @@ -33,6 +35,9 @@ object FreeLook : Module("FreeLook", Category.RENDER) { val onRotationSet = handler { event -> if (mc.gameSettings.thirdPersonView != 0) { event.cancelEvent() + } else { + currRotation = mc.thePlayer.rotation + prevRotation = currRotation } prevRotation = currRotation @@ -44,8 +49,13 @@ object FreeLook : Module("FreeLook", Category.RENDER) { fun useModifiedRotation() { val player = mc.thePlayer ?: return - savedCurrRotation = player.rotation - savedPrevRotation = player.prevRotation + if (mc.gameSettings.thirdPersonView == 0) + return + + if (modifySavedRotations) { + savedCurrRotation = player.rotation + savedPrevRotation = player.prevRotation + } if (!handleEvents()) return @@ -57,16 +67,21 @@ object FreeLook : Module("FreeLook", Category.RENDER) { fun restoreOriginalRotation() { val player = mc.thePlayer ?: return - if (mc.gameSettings.thirdPersonView == 0) { - savedCurrRotation = player.rotation - savedPrevRotation = player.prevRotation - return - } - - if (!handleEvents()) + if (!handleEvents() || mc.gameSettings.thirdPersonView == 0) return player.rotation = savedCurrRotation player.prevRotation = savedPrevRotation } + + fun runWithoutSavingRotations(f: () -> Unit) { + modifySavedRotations = false + + try { + f() + } catch (_: Exception) { + } + + modifySavedRotations = true + } } \ No newline at end of file diff --git a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/render/Tracers.kt b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/render/Tracers.kt index 7c5095faec8..da23c7b9072 100644 --- a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/render/Tracers.kt +++ b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/render/Tracers.kt @@ -59,56 +59,58 @@ object Tracers : Module("Tracers", Category.RENDER, hideModule = false) { val originalViewBobbing = mc.gameSettings.viewBobbing - // Temporarily disable view bobbing and re-apply camera transformation - mc.gameSettings.viewBobbing = false - mc.entityRenderer.setupCameraTransform(mc.timer.renderPartialTicks, 0) - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) - glEnable(GL_BLEND) - glEnable(GL_LINE_SMOOTH) - glLineWidth(thickness) - glDisable(GL_TEXTURE_2D) - glDisable(GL_DEPTH_TEST) - glDepthMask(false) - - glBegin(GL_LINES) - - for (entity in mc.theWorld.loadedEntityList) { - val distanceSquared = thePlayer.getDistanceSqToEntity(entity) - - if (distanceSquared <= maxRenderDistanceSq) { - if (onLook && !isLookingOnEntities(entity, maxAngleDifference.toDouble())) continue - if (entity !is EntityLivingBase || !bot && isBot(entity)) continue - if (!thruBlocks && !isEntityHeightVisible(entity)) continue - - if (entity != thePlayer && isSelected(entity, false)) { - val dist = (thePlayer.getDistanceToEntity(entity) * 2).toInt().coerceAtMost(255) - - val colorMode = colorMode.lowercase() - val color = when { - entity is EntityPlayer && entity.isClientFriend() -> Color(0, 0, 255, 150) - teams && state && Teams.isInYourTeam(entity) -> Color(0, 162, 232) - colorMode == "custom" -> Color(colorRed, colorGreen, colorBlue, 150) - colorMode == "distancecolor" -> Color(255 - dist, dist, 0, 150) - colorMode == "rainbow" -> ColorUtils.rainbow() - else -> Color(255, 255, 255, 150) + FreeLook.runWithoutSavingRotations { + // Temporarily disable view bobbing and re-apply camera transformation + mc.gameSettings.viewBobbing = false + mc.entityRenderer.setupCameraTransform(mc.timer.renderPartialTicks, 0) + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) + glEnable(GL_BLEND) + glEnable(GL_LINE_SMOOTH) + glLineWidth(thickness) + glDisable(GL_TEXTURE_2D) + glDisable(GL_DEPTH_TEST) + glDepthMask(false) + + glBegin(GL_LINES) + + for (entity in mc.theWorld.loadedEntityList) { + val distanceSquared = thePlayer.getDistanceSqToEntity(entity) + + if (distanceSquared <= maxRenderDistanceSq) { + if (onLook && !isLookingOnEntities(entity, maxAngleDifference.toDouble())) continue + if (entity !is EntityLivingBase || !bot && isBot(entity)) continue + if (!thruBlocks && !isEntityHeightVisible(entity)) continue + + if (entity != thePlayer && isSelected(entity, false)) { + val dist = (thePlayer.getDistanceToEntity(entity) * 2).toInt().coerceAtMost(255) + + val colorMode = colorMode.lowercase() + val color = when { + entity is EntityPlayer && entity.isClientFriend() -> Color(0, 0, 255, 150) + teams && state && Teams.isInYourTeam(entity) -> Color(0, 162, 232) + colorMode == "custom" -> Color(colorRed, colorGreen, colorBlue, 150) + colorMode == "distancecolor" -> Color(255 - dist, dist, 0, 150) + colorMode == "rainbow" -> ColorUtils.rainbow() + else -> Color(255, 255, 255, 150) + } + + drawTraces(entity, color) } - - drawTraces(entity, color) } } - } - glEnd() + glEnd() - mc.gameSettings.viewBobbing = originalViewBobbing + mc.gameSettings.viewBobbing = originalViewBobbing - glEnable(GL_TEXTURE_2D) - glDisable(GL_LINE_SMOOTH) - glEnable(GL_DEPTH_TEST) - glDepthMask(true) - glDisable(GL_BLEND) - glColor4f(1f, 1f, 1f, 1f) + glEnable(GL_TEXTURE_2D) + glDisable(GL_LINE_SMOOTH) + glEnable(GL_DEPTH_TEST) + glDepthMask(true) + glDisable(GL_BLEND) + glColor4f(1f, 1f, 1f, 1f) + } } private fun drawTraces(entity: Entity, color: Color) {