From c9df50ede023e81f9ca37585ab641e883c65fe55 Mon Sep 17 00:00:00 2001 From: MukjepScarlet <93977077+MukjepScarlet@users.noreply.github.com> Date: Wed, 1 Jan 2025 16:07:35 +0800 Subject: [PATCH] fix(TargetRenderer): Incorrect duplicate creation of mode (#5132) Also adjusted the use of generics --- .../utils/render/TargetRenderer.kt | 72 ++++++++----------- 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/utils/render/TargetRenderer.kt b/src/main/kotlin/net/ccbluex/liquidbounce/utils/render/TargetRenderer.kt index a8f7041e9a7..9c13258f04b 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/utils/render/TargetRenderer.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/utils/render/TargetRenderer.kt @@ -52,7 +52,7 @@ import kotlin.math.sin /** * A target tracker to choose the best enemy to attack */ -abstract class TargetRenderer( +sealed class TargetRenderer( module: ClientModule ) : ToggleableConfigurable(module, "TargetRendering", true) { @@ -60,33 +60,23 @@ abstract class TargetRenderer( doNotIncludeAlways() } - abstract val appearance: ChoiceConfigurable + abstract val appearance: ChoiceConfigurable> open fun render(env: T, entity: Entity, partialTicks: Float) { if (!enabled) { return } - (appearance.activeChoice as TargetRenderAppearance).render(env, entity, partialTicks) + appearance.activeChoice.render(env, entity, partialTicks) } } - class WorldTargetRenderer(module: ClientModule) : TargetRenderer(module) { - val legacy = Legacy() - val circle = Circle(module) - val glowingCircle = GlowingCircle(module) - val ghost = Ghost() - - override val appearance = - choices( - module, - "Mode", - { glowingCircle }, - { arrayOf(legacy, circle, glowingCircle, ghost) } - ) + override val appearance = choices(module, "Mode", 2) { + arrayOf(Legacy(), Circle(module), GlowingCircle(module), Ghost()) + } inner class Ghost : WorldTargetRenderAppearance("Ghost") { @@ -221,7 +211,7 @@ class WorldTargetRenderer(module: ClientModule) : TargetRenderer + override val parent: ChoiceConfigurable<*> get() = appearance private val size by float("Size", 0.5f, 0.1f..2f) @@ -253,26 +243,22 @@ class WorldTargetRenderer(module: ClientModule) : TargetRenderer + override val parent: ChoiceConfigurable<*> get() = appearance private val radius by float("Radius", 0.85f, 0.1f..2f) private val innerRadius by float("InnerRadius", 0f, 0f..2f) .onChange { min(radius, it) } - private val heightMode = choices( - module, - "HeightMode", - { FeetHeight(it) }, - { arrayOf(FeetHeight(it), TopHeight(it), RelativeHeight(it), HealthHeight(it)) } - ) + private val heightMode = choices(module, "HeightMode", 0) { + arrayOf(FeetHeight(it), TopHeight(it), RelativeHeight(it), HealthHeight(it)) + } private val outerColor by color("OuterColor", Color4b(0x64007CFF, true)) private val innerColor by color("InnerColor", Color4b(0x64007CFF, true)) private val outline = tree(Outline()) - override fun render(env: WorldRenderEnvironment, entity: Entity, partialTicks: Float) { val height = heightMode.activeChoice.getHeight(entity, partialTicks) val pos = entity.interpolateCurrentPosition(partialTicks) + Vec3d(0.0, height, 0.0) @@ -292,17 +278,14 @@ class WorldTargetRenderer(module: ClientModule) : TargetRenderer + override val parent: ChoiceConfigurable<*> get() = appearance private val radius by float("Radius", 0.85f, 0.1f..2f) - private val heightMode = choices( - module, - "HeightMode", - { FeetHeight(it) }, - { arrayOf(FeetHeight(it), TopHeight(it), RelativeHeight(it), HealthHeight(it), AnimatedHeight(it)) } - ) + private val heightMode = choices(module, "HeightMode", 0) { + arrayOf(FeetHeight(it), TopHeight(it), RelativeHeight(it), HealthHeight(it), AnimatedHeight(it)) + } private val color by color("OuterColor", Color4b(0x64007CFF, true)) private val glowColor by color("GlowColor", Color4b(0x00007CFF, true)) @@ -311,7 +294,6 @@ class WorldTargetRenderer(module: ClientModule) : TargetRenderer get() = choiceConfigurable - val offset: Float by float("Offset", 0f, -1f..1f) + val offset by float("Offset", 0f, -1f..1f) override fun getHeight(entity: Entity, partialTicks: Float): Double { return offset.toDouble() @@ -393,10 +375,8 @@ class WorldTargetRenderer(module: ClientModule) : TargetRenderer get() = choiceConfigurable - - override fun getHeight(entity: Entity, partialTicks: Float): Double { - if(entity !is LivingEntity) return 0.0 + if (entity !is LivingEntity) return 0.0 val box = entity.box val entityHeight = box.maxY - box.minY return entity.health / entity.maxHealth * entityHeight @@ -426,11 +406,15 @@ class WorldTargetRenderer(module: ClientModule) : TargetRenderer(module) { - override val appearance = choices(module, "Mode", Legacy(), arrayOf(Legacy())) + private val legacy = Legacy() + + override val appearance = choices(module, "Mode", 0) { + arrayOf(legacy) + } inner class Legacy : OverlayTargetRenderAppearance("Arrow") { - override val parent: ChoiceConfigurable + override val parent: ChoiceConfigurable<*> get() = appearance private val color by color("Color", Color4b.RED) @@ -460,18 +444,18 @@ class OverlayTargetRenderer(module: ClientModule) : TargetRenderer(name: String) : Choice(name) { +sealed class TargetRenderAppearance(name: String) : Choice(name) { open fun render(env: T, entity: Entity, partialTicks: Float) {} } -abstract class WorldTargetRenderAppearance(name: String) : TargetRenderAppearance(name) -abstract class OverlayTargetRenderAppearance(name: String) : TargetRenderAppearance(name) +sealed class WorldTargetRenderAppearance(name: String) : TargetRenderAppearance(name) +sealed class OverlayTargetRenderAppearance(name: String) : TargetRenderAppearance(name) -abstract class HeightMode(name: String) : Choice(name) { +sealed class HeightMode(name: String) : Choice(name) { open fun getHeight(entity: Entity, partialTicks: Float): Double = 0.0 } -abstract class HeightWithGlow(name: String) : HeightMode(name) { +sealed class HeightWithGlow(name: String) : HeightMode(name) { open fun getGlowHeight(entity: Entity, partialTicks: Float): Double = 0.0 }