aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-05-13 12:30:18 +0200
committerGitHub <noreply@github.com>2024-05-13 12:30:18 +0200
commit253d92a20b93a46d308cc94b73130e87e82f2da1 (patch)
treef9b0f182583461a2b4b3fca1024efccfd2b8cf78 /src/main/java/at
parent1a5a6a64b75d3e18649c52fc71852c875478bc43 (diff)
downloadskyhanni-253d92a20b93a46d308cc94b73130e87e82f2da1.tar.gz
skyhanni-253d92a20b93a46d308cc94b73130e87e82f2da1.tar.bz2
skyhanni-253d92a20b93a46d308cc94b73130e87e82f2da1.zip
Improvement: updating scoreboard and tab list less often (#1779)
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt14
2 files changed, 26 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
index 0bd1e6866..2995a38e2 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
@@ -1,10 +1,12 @@
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.events.LorenzTickEvent
+import at.hannibal2.skyhanni.events.PacketEvent
import at.hannibal2.skyhanni.events.ScoreboardChangeEvent
import at.hannibal2.skyhanni.events.ScoreboardRawChangeEvent
import at.hannibal2.skyhanni.utils.StringUtils.matches
import net.minecraft.client.Minecraft
+import net.minecraft.network.play.server.S3BPacketScoreboardObjective
import net.minecraft.scoreboard.Score
import net.minecraft.scoreboard.ScorePlayerTeam
import net.minecraftforge.fml.common.eventhandler.EventPriority
@@ -66,8 +68,19 @@ class ScoreboardData {
var objectiveTitle = ""
}
+ var dirty = false
+
+ @SubscribeEvent(receiveCanceled = true)
+ fun onPacketReceive(event: PacketEvent.ReceiveEvent) {
+ if (event.packet is S3BPacketScoreboardObjective) {
+ dirty = true
+ }
+ }
+
@SubscribeEvent(priority = EventPriority.HIGHEST)
fun onTick(event: LorenzTickEvent) {
+ if (!dirty) return
+ dirty = false
val list = fetchScoreboardLines().reversed()
val semiFormatted = list.map { cleanSB(it) }
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt
index 1ba5bc8fa..ea930bee4 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt
@@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.LorenzTickEvent
+import at.hannibal2.skyhanni.events.PacketEvent
import at.hannibal2.skyhanni.events.TabListUpdateEvent
import at.hannibal2.skyhanni.events.TablistFooterUpdateEvent
import at.hannibal2.skyhanni.mixins.hooks.tabListGuard
@@ -14,6 +15,7 @@ import com.google.common.collect.Ordering
import kotlinx.coroutines.launch
import net.minecraft.client.Minecraft
import net.minecraft.client.network.NetworkPlayerInfo
+import net.minecraft.network.play.server.S38PacketPlayerListItem
import net.minecraft.world.WorldSettings
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.relauncher.Side
@@ -106,9 +108,19 @@ object TabListData {
return result.dropLast(1)
}
+ var dirty = false
+
+ @SubscribeEvent(receiveCanceled = true)
+ fun onPacketReceive(event: PacketEvent.ReceiveEvent) {
+ if (event.packet is S38PacketPlayerListItem) {
+ dirty = true
+ }
+ }
+
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
- if (!event.isMod(2)) return
+ if (!dirty) return
+ dirty = false
val tabList = readTabList() ?: return
if (tablistCache != tabList) {