This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
133 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/io/github/homchom/recode/feature/visual/LagSlayerHUD.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package io.github.homchom.recode.feature.visual | ||
|
||
import io.github.homchom.recode.Power | ||
import io.github.homchom.recode.config.Config | ||
import io.github.homchom.recode.config.Setting | ||
import io.github.homchom.recode.event.listenEach | ||
import io.github.homchom.recode.feature.AddsFeature | ||
import io.github.homchom.recode.feature.registerFeature | ||
import io.github.homchom.recode.game.TickCountdown | ||
import io.github.homchom.recode.mc | ||
import io.github.homchom.recode.multiplayer.ReceiveMessageEvent | ||
import io.github.homchom.recode.render.AfterRenderHudEvent | ||
import io.github.homchom.recode.ui.text.StyledString | ||
import io.github.homchom.recode.ui.text.matchesPlain | ||
import io.github.homchom.recode.ui.text.substring | ||
import io.github.homchom.recode.ui.text.toVanillaComponent | ||
import io.github.homchom.recode.util.regex.regex | ||
import net.minecraft.client.gui.GuiGraphics | ||
|
||
@OptIn(AddsFeature::class) | ||
object FLagSlayerHUD : Setting<Boolean> { | ||
override val configString = "cpuOnScreen" | ||
|
||
private var regex: Regex? = null | ||
|
||
private var line1: StyledString? = null | ||
private var line2: StyledString? = null | ||
private var line3: StyledString? = null | ||
private val renderCountdown = TickCountdown(30) | ||
|
||
init { | ||
registerFeature("LagSlayer HUD") { | ||
onEnable { | ||
regex = regex { | ||
str("CPU Usage: [") | ||
str('▮') * 20 | ||
str("] (") | ||
digit; digit.optional() | ||
period; digit.oneOrMore() | ||
str("%)") | ||
} | ||
|
||
interceptActionBarPackets() | ||
render() | ||
} | ||
onDisable { | ||
regex = null | ||
} | ||
} | ||
} | ||
|
||
private fun Power.interceptActionBarPackets() = listenEach(ReceiveMessageEvent.ActionBar) l@{ message -> | ||
if (Config[FLagSlayerHUD] == false) return@l | ||
if (!regex!!.matchesPlain(message.value)) return@l | ||
|
||
message.invalidate() | ||
|
||
val text = StyledString(message.value) | ||
line1 = text.substring(0, 11) | ||
line2 = text.substring(11, 33) | ||
line3 = text.substring(33) | ||
renderCountdown.wind() | ||
} | ||
|
||
private fun Power.render() = listenEach(AfterRenderHudEvent) l@{ (guiGraphics) -> | ||
if (!renderCountdown.isActive) return@l | ||
drawString(guiGraphics, line1!!, 3) | ||
drawString(guiGraphics, line2!!, 2) | ||
drawString(guiGraphics, line3!!, 1) | ||
} | ||
|
||
// TODO: rework post-workflow | ||
private fun drawString(guiGraphics: GuiGraphics, string: StyledString, index: Int) { | ||
val font = mc.font | ||
val window = mc.window | ||
guiGraphics.drawString( | ||
font, | ||
string.toVanillaComponent(), | ||
4, | ||
window.guiScaledHeight - (font.lineHeight * index + 4), | ||
0xffffff, | ||
true | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 0 additions & 73 deletions
73
src/main/java/io/github/homchom/recode/mod/features/LagslayerHUD.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.