Skip to content

Commit

Permalink
fix(legacy): FreeLook being incompatible with Tracers. (#4971)
Browse files Browse the repository at this point in the history
  • Loading branch information
mems01 authored Dec 19, 2024
1 parent 19d59ed commit 1401cb3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +35,9 @@ object FreeLook : Module("FreeLook", Category.RENDER) {
val onRotationSet = handler<RotationSetEvent> { event ->
if (mc.gameSettings.thirdPersonView != 0) {
event.cancelEvent()
} else {
currRotation = mc.thePlayer.rotation
prevRotation = currRotation
}

prevRotation = currRotation
Expand All @@ -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
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1401cb3

Please sign in to comment.