diff options
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt index 8a1d7b50d..4a86519c3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt @@ -30,6 +30,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment import at.hannibal2.skyhanni.utils.RenderUtils.VerticalAlignment import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.fromNow import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.renderables.Renderable @@ -50,7 +51,7 @@ object CustomScoreboard { private var cache = emptyList<ScoreboardElementType>() private const val GUI_NAME = "Custom Scoreboard" - private var lastScoreboardUpdate = SimpleTimeMark.farFuture() + private var nextScoreboardUpdate = SimpleTimeMark.farFuture() @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { @@ -82,9 +83,7 @@ object CustomScoreboard { fun onGuiPositionMoved(event: GuiPositionMovedEvent) { if (event.guiName == GUI_NAME) { with(alignmentConfig) { - if (horizontalAlignment != HorizontalAlignment.DONT_ALIGN || - verticalAlignment != VerticalAlignment.DONT_ALIGN - ) { + if (horizontalAlignment != HorizontalAlignment.DONT_ALIGN || verticalAlignment != VerticalAlignment.DONT_ALIGN) { val tempHori = horizontalAlignment val tempVert = verticalAlignment @@ -108,15 +107,9 @@ object CustomScoreboard { fun onTick(event: LorenzTickEvent) { if (!isEnabled()) return - // We want to update the scoreboard as soon as we have new data, not 5 ticks delayed - var dirty = false - if (lastScoreboardUpdate.passedSince() > 250.milliseconds) { - lastScoreboardUpdate = SimpleTimeMark.farFuture() - dirty = true - } - - // Creating the lines - if (dirty) { + if (dirty || nextScoreboardUpdate.isInPast()) { + nextScoreboardUpdate = 250.milliseconds.fromNow() + dirty = false display = createLines().removeEmptyLinesFromEdges() if (TabListData.fullyLoaded) { cache = display.toList() @@ -129,10 +122,9 @@ object CustomScoreboard { @SubscribeEvent fun onScoreboardChange(event: ScoreboardUpdateEvent) { - lastScoreboardUpdate = SimpleTimeMark.now() + dirty = true } - internal val config get() = SkyHanniMod.feature.gui.customScoreboard internal val displayConfig get() = config.display internal val alignmentConfig get() = displayConfig.alignment |