diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleProphuntESP.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleProphuntESP.kt index c4d66ae9024..f8eb7ee56ae 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleProphuntESP.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleProphuntESP.kt @@ -11,6 +11,7 @@ import net.ccbluex.liquidbounce.features.module.Category import net.ccbluex.liquidbounce.features.module.Module import net.ccbluex.liquidbounce.render.* import net.ccbluex.liquidbounce.render.engine.Color4b +import net.ccbluex.liquidbounce.render.utils.interpolateHue import net.ccbluex.liquidbounce.utils.block.getState import net.ccbluex.liquidbounce.utils.block.toBlockPos import net.ccbluex.liquidbounce.utils.entity.interpolateCurrentPosition @@ -49,10 +50,11 @@ object ModuleProphuntESP : override fun getColor(param: Any): Color4b = - if (param is TrackedBlock) - freshColor.interpolateHSV(expireColor, param.expirationProgress()) - else + if (param is TrackedBlock) { + interpolateHue(freshColor, expireColor, param.expirationProgress()) + } else { freshColor + } override val parent: ChoiceConfigurable<*> get() = modes @@ -74,13 +76,16 @@ object ModuleProphuntESP : } private val trackedBlocks = PriorityQueue() - private val renderTicks by float("RenderTicks",60f, 0f..600f) + private val renderTicks by float("RenderTicks", 60f, 0f..600f) init { repeatable { val currentTIme = mc.world?.time ?: 0 - while (trackedBlocks.isNotEmpty() && trackedBlocks.peek().expirationTime <= currentTIme) - trackedBlocks.poll() + synchronized(trackedBlocks) { + while (trackedBlocks.isNotEmpty() && trackedBlocks.peek().expirationTime <= currentTIme) { + trackedBlocks.poll() + } + } waitTicks(1) } @@ -94,31 +99,70 @@ object ModuleProphuntESP : @Suppress("unused") val renderHandler = handler { event -> + drawBoxMode(event.matrixStack, this.outline, false) - drawBoxMode(event.matrixStack, event.partialTicks, this.outline, false) + renderEnvironmentForWorld(event.matrixStack) { + drawEntities(this, event.partialTicks, colorMode.activeChoice, true) + } } } - fun drawBoxMode(matrixStack: MatrixStack, partialTicks: Float, drawOutline: Boolean, fullAlpha: Boolean): Boolean { + fun drawBoxMode(matrixStack: MatrixStack, drawOutline: Boolean, fullAlpha: Boolean): Boolean { val colorMode = colorMode.activeChoice var dirty = false renderEnvironmentForWorld(matrixStack) { synchronized(trackedBlocks) { - dirty = drawInternal(this, partialTicks, trackedBlocks, colorMode, fullAlpha, drawOutline) + dirty = drawBlocks(this, trackedBlocks, colorMode, fullAlpha, drawOutline) || dirty } - } return dirty } - private fun WorldRenderEnvironment.drawInternal( + private fun WorldRenderEnvironment.drawEntities( env: WorldRenderEnvironment, partialTicks: Float, + colorMode: GenericColorMode, + drawOutline: Boolean + ): Boolean { + var dirty = false + + if (renderFallingBlockEntity) { + BoxRenderer.drawWith(env) { + mc.world?.entities?.filterIsInstance()?.map { + val dimension = it.getDimensions(it.pose) + val width = dimension.width.toDouble() / 2.0 + it to Box(-width, 0.0, -width, width, dimension.height.toDouble(), width) + }?.forEach { (entity, box) -> + val pos = entity.interpolateCurrentPosition(partialTicks) + val color = colorMode.getColor(entity as Any) // which doesn't matter + + val baseColor = color.alpha(50) + val outlineColor = color.alpha(100) + + withPositionRelativeToCamera(pos) { + drawBox( + box, + baseColor, + outlineColor.takeIf { drawOutline } + ) + } + + dirty = true + } + } + } + + return dirty + } + + + private fun WorldRenderEnvironment.drawBlocks( + env: WorldRenderEnvironment, blocks: PriorityQueue, colorMode: GenericColorMode, fullAlpha: Boolean, @@ -128,7 +172,7 @@ object ModuleProphuntESP : BoxRenderer.drawWith(env) { - if (renderBlockUpdates) + if (renderBlockUpdates) { for (block in blocks) { val pos = block.pos @@ -146,8 +190,9 @@ object ModuleProphuntESP : val color = colorMode.getColor(block) - if (fullAlpha) + if (fullAlpha) { color.alpha(255) + } withPositionRelativeToCamera(vec3d) { drawBox( @@ -159,31 +204,7 @@ object ModuleProphuntESP : dirty = true } - - - if (renderFallingBlockEntity) { - mc.world?.entities?.filterIsInstance()?.map { - val dimension = it.getDimensions(it.pose) - val width = dimension.width.toDouble() / 2.0 - it to Box(-width, 0.0, -width, width, dimension.height.toDouble(), width) - }?.forEach { (entity, box) -> - val pos = entity.interpolateCurrentPosition(partialTicks) - val color = colorMode.getColor(entity as Any) // which doesn't matter - - val baseColor = color.alpha(50) - val outlineColor = color.alpha(100) - - withPositionRelativeToCamera(pos) { - drawBox( - box, - baseColor, - outlineColor.takeIf { drawOutline } - ) - } - } - } - } return dirty @@ -200,11 +221,15 @@ object ModuleProphuntESP : return@handler } - val dirty = drawBoxMode(event.matrixStack, event.partialTicks, drawOutline = false, fullAlpha = true) + var dirty = drawBoxMode(event.matrixStack, drawOutline = false, fullAlpha = true) - if (dirty) - event.markDirty() + renderEnvironmentForWorld(event.matrixStack) { + dirty = drawEntities(this, event.partialTicks, colorMode.activeChoice, true) || dirty + } + if (dirty) { + event.markDirty() + } } } @@ -218,17 +243,24 @@ object ModuleProphuntESP : return@handler } - val dirty = drawBoxMode(event.matrixStack, event.partialTicks, drawOutline = false, fullAlpha = true) + var dirty = drawBoxMode(event.matrixStack, drawOutline = false, fullAlpha = true) - if (dirty) - event.markDirty() + renderEnvironmentForWorld(event.matrixStack) { + dirty = drawEntities(this, event.partialTicks, colorMode.activeChoice, true) || dirty + } + if (dirty) { + event.markDirty() + } } } val networkHandler = handler { event -> - if (event.packet is BlockUpdateS2CPacket) - trackedBlocks.offer(TrackedBlock(event.packet.pos, (mc.world?.time ?: 0L) + renderTicks.toLong())) + if (event.packet is BlockUpdateS2CPacket) { + synchronized(trackedBlocks) { + trackedBlocks.offer(TrackedBlock(event.packet.pos, (mc.world?.time ?: 0L) + renderTicks.toLong())) + } + } } } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/RenderTasks.kt b/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/RenderTasks.kt index cdc1bb788c1..c9a878cd467 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/RenderTasks.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/RenderTasks.kt @@ -181,24 +181,4 @@ data class Color4b(val r: Int, val g: Int, val b: Int, val a: Int) { } else { alpha((a * fade).toInt()) } - - fun interpolateHSV(otherColor: Color4b, percentageOther: Float): Color4b { - val hsv1 = FloatArray(3) - val hsv2 = FloatArray(3) - Color.RGBtoHSB(r, g, b, hsv1) - Color.RGBtoHSB(otherColor.r, otherColor.g, otherColor.b, hsv2) - - val h = hsv1[0] + (hsv2[0] - hsv1[0]) * percentageOther - val s = hsv1[1] + (hsv2[1] - hsv1[1]) * percentageOther - val v = hsv1[2] + (hsv2[2] - hsv1[2]) * percentageOther - val alpha = this.a + (otherColor.a - this.a) * percentageOther - - val rgb = Color.HSBtoRGB(h, s, v) - return Color4b( - (rgb shr 16) and 0xFF, - (rgb shr 8) and 0xFF, - rgb and 0xFF, - alpha.toInt() - ) - } } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/render/utils/ColorUtils.kt b/src/main/kotlin/net/ccbluex/liquidbounce/render/utils/ColorUtils.kt index 7832e17592e..d3bd0eed1cc 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/render/utils/ColorUtils.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/render/utils/ColorUtils.kt @@ -50,3 +50,23 @@ fun shiftHue(color4b: Color4b, shift: Int): Color4b { return Color4b(shiftedColor).alpha(color4b.a) } + +fun interpolateHue(primaryColor: Color4b, otherColor: Color4b, percentageOther: Float): Color4b { + val hsb1 = FloatArray(3) + val hsb2 = FloatArray(3) + Color.RGBtoHSB(primaryColor.r,primaryColor.g, primaryColor.b, hsb1) + Color.RGBtoHSB(otherColor.r, otherColor.g, otherColor.b, hsb2) + + val h = hsb1[0] + (hsb2[0] - hsb1[0]) * percentageOther + val s = hsb1[1] + (hsb2[1] - hsb1[1]) * percentageOther + val v = hsb1[2] + (hsb2[2] - hsb1[2]) * percentageOther + val alpha = primaryColor.a + (otherColor.a - primaryColor.a) * percentageOther + + val rgb = Color.HSBtoRGB(h, s, v) + return Color4b( + (rgb shr 16) and 0xFF, + (rgb shr 8) and 0xFF, + rgb and 0xFF, + alpha.toInt() + ) +}