diff options
Diffstat (limited to 'src/main')
5 files changed, 138 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index a14a831d6..962471ec2 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -190,6 +190,7 @@ public class SkyHanniMod { loadModule(new BingoNextStepHelper()); loadModule(new MinionCraftHelper()); loadModule(new HideDeadEntities()); + loadModule(new TpsCounter()); Commands.INSTANCE.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index 11aac3fc8..f0a830624 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -131,6 +131,11 @@ public class Features extends Config { editOverlay(activeConfigCategory, 200, 16, minions.minionCraftHelperPos); return; } + + if (runnableId.equals("tpsDisplay")) { + editOverlay(activeConfigCategory, 200, 16, misc.tpsDisplayPosition); + return; + } } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java index d1ae139b9..467a6c1b6 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java @@ -150,6 +150,23 @@ public class Misc { public boolean tiaRelayMute = true; @Expose + @ConfigOption(name = "Tps Display", desc = "") + @ConfigEditorAccordion(id = 8) + public boolean tpsDisplay = false; + + @Expose + @ConfigOption(name = "Tps Display", desc = "Show the Tps of the current server.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 8) + public boolean tpsDisplayEnabled = false; + + @Expose + @ConfigOption(name = "Tps Display Position", desc = "") + @ConfigEditorButton(runnableId = "tpsDisplay", buttonText = "Edit") + @ConfigAccordionId(id = 8) + public Position tpsDisplayPosition = new Position(10, 10, false, true); + + @Expose @ConfigOption(name = "Exp Bottles", desc = "Hides all the experience bottles lying on the ground.") @ConfigEditorBoolean public boolean hideExpBottles = false; @@ -180,12 +197,12 @@ public class Misc { public boolean brewingStandOverlay = true; @Expose - @ConfigOption(name = "Config Button", desc = "Add a button to the pause menu to configure SkyHanni.") + @ConfigOption(name = "Red Scoreboard Numbers", desc = "Hide the red scoreboard numbers at the right side of the screen.") @ConfigEditorBoolean - public boolean configButtonOnPause = true; + public boolean hideScoreboardNumbers = false; @Expose - @ConfigOption(name = "Red Scoreboard Numbers", desc = "Hide the red scoreboard numbers at the right side of the screen.") + @ConfigOption(name = "Config Button", desc = "Add a button to the pause menu to configure SkyHanni.") @ConfigEditorBoolean - public boolean hideScoreboardNumbers = false; + public boolean configButtonOnPause = true; }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/HypixelTIck.kt b/src/main/java/at/hannibal2/skyhanni/events/HypixelTIck.kt new file mode 100644 index 000000000..42f015ff5 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/HypixelTIck.kt @@ -0,0 +1,3 @@ +package at.hannibal2.skyhanni.events + +class HypixelTickEvent: LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/TpsCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/TpsCounter.kt new file mode 100644 index 000000000..dcb125b2f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/TpsCounter.kt @@ -0,0 +1,108 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.HyPixelData +import at.hannibal2.skyhanni.events.HypixelTickEvent +import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import net.minecraftforge.client.event.RenderGameOverlayEvent +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.concurrent.fixedRateTimer + +class TpsCounter { + companion object { + private const val minDataAmount = 5 + private const val waitAfterWorldSwitch = 6 + } + + private var packetsFromLastSecond = 0 + private var tpsList = mutableListOf<Int>() + private var ignoreFirstTicks = waitAfterWorldSwitch + private var hasPacketReceived = false + + private var display = "" + + init { + fixedRateTimer(name = "skyhanni-tps-counter-seconds", period = 1000L) { + if (!HyPixelData.skyBlock) return@fixedRateTimer + if (!SkyHanniMod.feature.misc.tpsDisplayEnabled) return@fixedRateTimer + if (packetsFromLastSecond == 0) return@fixedRateTimer + + if (ignoreFirstTicks > 0) { + ignoreFirstTicks-- + val current = ignoreFirstTicks + minDataAmount + display = "§eSkyHanni Tps: §fCalculating.. (${current}s)" + packetsFromLastSecond = 0 + return@fixedRateTimer + } + + tpsList.add(packetsFromLastSecond) + packetsFromLastSecond = 0 + if (tpsList.size > 10) { + tpsList = tpsList.drop(1).toMutableList() + } + + display = if (tpsList.size < minDataAmount) { + val current = minDataAmount - tpsList.size + "§eSkyHanni Tps: §fCalculating.. (${current}s)" + } else { + val sum = tpsList.sum().toDouble() + var tps = (sum / tpsList.size).round(1) + if (tps > 20) tps = 20.0 + val color = getColor(tps) + "§eSkyHanni Tps: $color$tps" + } + } + fixedRateTimer(name = "skyhanni-tps-counter-ticks", period = 50L) { + if (!HyPixelData.skyBlock) return@fixedRateTimer + if (!SkyHanniMod.feature.misc.tpsDisplayEnabled) return@fixedRateTimer + + if (hasPacketReceived) { + hasPacketReceived = false + HypixelTickEvent().postAndCatch() + packetsFromLastSecond++ + } + } + } + + @SubscribeEvent + fun onWorldChange(event: WorldEvent.Load) { + tpsList.clear() + packetsFromLastSecond = 0 + ignoreFirstTicks = waitAfterWorldSwitch + display = "" + } + + @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) + fun onChatPacket(event: PacketEvent.ReceiveEvent) { + if (!SkyHanniMod.feature.misc.tpsDisplayEnabled) return + hasPacketReceived = true + } + + @SubscribeEvent + fun onRenderOverlay(event: RenderGameOverlayEvent.Post) { + if (!LorenzUtils.inSkyBlock) return + if (!SkyHanniMod.feature.misc.tpsDisplayEnabled) return + if (event.type != RenderGameOverlayEvent.ElementType.ALL) return + + SkyHanniMod.feature.misc.tpsDisplayPosition.renderString(display) + } + + private fun getColor(tps: Double): String { + return if (tps > 19.8) { + "§2" + } else if (tps > 19) { + "§a" + } else if (tps > 17.5) { + "§6" + } else if (tps > 12) { + "§c" + } else { + "§8NOT PLAYABLE - " + } + } +}
\ No newline at end of file |