From fa953dfc7662920aae5efaea249a67cc1456c258 Mon Sep 17 00:00:00 2001 From: JustAlittleWolf Date: Sun, 27 Aug 2023 19:50:16 +0200 Subject: [PATCH 1/5] render on heart blink and username style change Fixes the issue where the hearts get stuck blinking when showing the health scoreboard in the tablist also fixes updates now when the style of playerInfo.getTabListDisplayName() changes --- .../exordium/mixin/PlayerTabOverlayMixin.java | 23 ++++++++++++++++++- .../src/main/resources/exordium.accesswidener | 3 ++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java b/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java index 62f7ee1..095168c 100644 --- a/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java +++ b/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java @@ -4,21 +4,31 @@ import dev.tr7zw.exordium.access.TablistAccess; import dev.tr7zw.exordium.util.BufferedComponent; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; import net.minecraft.client.multiplayer.PlayerInfo; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; import net.minecraft.world.scores.Objective; import net.minecraft.world.scores.Score; import net.minecraft.world.scores.Scoreboard; +import net.minecraft.world.scores.criteria.ObjectiveCriteria; import org.spongepowered.asm.mixin.Mixin; import net.minecraft.client.gui.components.PlayerTabOverlay; import org.spongepowered.asm.mixin.Shadow; +import java.sql.SQLType; import java.util.List; +import java.util.Map; +import java.util.UUID; @Mixin(PlayerTabOverlay.class) public abstract class PlayerTabOverlayMixin implements TablistAccess { @Shadow private Minecraft minecraft; + @Shadow + private Gui gui; + @Shadow + private Map healthStates; private int playerInfoHash = 0; private int headerHash = 0; private int footerHash = 0; @@ -76,8 +86,19 @@ public int fastGetPlayerInfoListHashCode(List playerInfos) { continue; } combinedHashes += playerInfo.getProfile().getId().hashCode(); - combinedHashes += playerInfo.getTabListDisplayName() == null ? 0 : playerInfo.getTabListDisplayName().getString().hashCode(); + if (playerInfo.getTabListDisplayName() != null) { + combinedHashes += playerInfo.getTabListDisplayName().getString().hashCode(); + Style displaynameStyle = playerInfo.getTabListDisplayName().getStyle(); + combinedHashes += (displaynameStyle.getColor() == null ? 0 : displaynameStyle.getColor().getValue()) + (displaynameStyle.isBold() ? 1 : 0) + (displaynameStyle.isItalic() ? 3 : 0) + (displaynameStyle.isObfuscated() ? 7 : 0) + (displaynameStyle.isUnderlined() ? 15 : 0) + (displaynameStyle.isStrikethrough() ? 31 : 0); + combinedHashes += playerInfo.getTabListDisplayName().getStyle().hashCode(); + } combinedHashes += playerInfo.getSkinLocation().hashCode(); + + if (lastTrackedObjective != null && lastTrackedObjective.getRenderType() == ObjectiveCriteria.RenderType.HEARTS) { + PlayerTabOverlay.HealthState healthState = this.healthStates.computeIfAbsent(playerInfo.getProfile().getId(), (uUID) -> + new PlayerTabOverlay.HealthState(lastTrackedObjective.getScoreboard().getOrCreatePlayerScore(playerInfo.getProfile().getName(), lastTrackedObjective).getScore())); + combinedHashes = 31 * combinedHashes + (healthState.isBlinking(this.gui.getGuiTicks()) ? 63 : 127); + } hashCode = 31 * hashCode + combinedHashes; } return hashCode; diff --git a/Shared/src/main/resources/exordium.accesswidener b/Shared/src/main/resources/exordium.accesswidener index cc7cd32..2c8b8a3 100644 --- a/Shared/src/main/resources/exordium.accesswidener +++ b/Shared/src/main/resources/exordium.accesswidener @@ -1,3 +1,4 @@ accessWidener v1 named accessible field com/mojang/blaze3d/platform/GlStateManager BLEND Lcom/mojang/blaze3d/platform/GlStateManager$BlendState; -accessible class com/mojang/blaze3d/platform/GlStateManager$BlendState \ No newline at end of file +accessible class com/mojang/blaze3d/platform/GlStateManager$BlendState +accessible class net/minecraft/client/gui/components/PlayerTabOverlay$HealthState \ No newline at end of file From 353df2ec90909388e4750dc1e39fc253f89f504a Mon Sep 17 00:00:00 2001 From: JustAlittleWolf Date: Sun, 27 Aug 2023 20:01:25 +0200 Subject: [PATCH 2/5] update tablist on latency change --- .../java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java b/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java index 095168c..1cf6e21 100644 --- a/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java +++ b/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java @@ -93,6 +93,7 @@ public int fastGetPlayerInfoListHashCode(List playerInfos) { combinedHashes += playerInfo.getTabListDisplayName().getStyle().hashCode(); } combinedHashes += playerInfo.getSkinLocation().hashCode(); + combinedHashes += playerInfo.getLatency() * 63; if (lastTrackedObjective != null && lastTrackedObjective.getRenderType() == ObjectiveCriteria.RenderType.HEARTS) { PlayerTabOverlay.HealthState healthState = this.healthStates.computeIfAbsent(playerInfo.getProfile().getId(), (uUID) -> From 5bdf828cb740a28af1949a0f271cedf5537d4e61 Mon Sep 17 00:00:00 2001 From: JustAlittleWolf Date: Tue, 29 Aug 2023 22:38:19 +0200 Subject: [PATCH 3/5] Remove unused import --- .../java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java b/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java index 1cf6e21..8beccb5 100644 --- a/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java +++ b/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java @@ -16,7 +16,6 @@ import net.minecraft.client.gui.components.PlayerTabOverlay; import org.spongepowered.asm.mixin.Shadow; -import java.sql.SQLType; import java.util.List; import java.util.Map; import java.util.UUID; From bb864a823eb0690dadacd8865b595fe7b839b2c5 Mon Sep 17 00:00:00 2001 From: JustAlittleWolf Date: Wed, 30 Aug 2023 11:52:03 +0200 Subject: [PATCH 4/5] Fix displayname style hashing --- .../dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java b/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java index 8beccb5..bef3b20 100644 --- a/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java +++ b/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java @@ -8,6 +8,7 @@ import net.minecraft.client.multiplayer.PlayerInfo; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.scores.Objective; import net.minecraft.world.scores.Score; import net.minecraft.world.scores.Scoreboard; @@ -79,16 +80,12 @@ public boolean scoreboardOrObjectiveChanged(Scoreboard scoreboard, Objective obj public int fastGetPlayerInfoListHashCode(List playerInfos) { int hashCode = 1; for (PlayerInfo playerInfo : playerInfos) { + if (playerInfo == null) continue; + int combinedHashes = 0; - if (playerInfo == null) { - hashCode *= 31; - continue; - } combinedHashes += playerInfo.getProfile().getId().hashCode(); if (playerInfo.getTabListDisplayName() != null) { combinedHashes += playerInfo.getTabListDisplayName().getString().hashCode(); - Style displaynameStyle = playerInfo.getTabListDisplayName().getStyle(); - combinedHashes += (displaynameStyle.getColor() == null ? 0 : displaynameStyle.getColor().getValue()) + (displaynameStyle.isBold() ? 1 : 0) + (displaynameStyle.isItalic() ? 3 : 0) + (displaynameStyle.isObfuscated() ? 7 : 0) + (displaynameStyle.isUnderlined() ? 15 : 0) + (displaynameStyle.isStrikethrough() ? 31 : 0); combinedHashes += playerInfo.getTabListDisplayName().getStyle().hashCode(); } combinedHashes += playerInfo.getSkinLocation().hashCode(); From fb3889237139ac267ca99d69111d6f4fef020883 Mon Sep 17 00:00:00 2001 From: JustAlittleWolf Date: Wed, 30 Aug 2023 11:53:31 +0200 Subject: [PATCH 5/5] Clean imports --- .../java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java b/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java index bef3b20..b0b5063 100644 --- a/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java +++ b/Shared/src/main/java/dev/tr7zw/exordium/mixin/PlayerTabOverlayMixin.java @@ -7,8 +7,6 @@ import net.minecraft.client.gui.Gui; import net.minecraft.client.multiplayer.PlayerInfo; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Style; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.scores.Objective; import net.minecraft.world.scores.Score; import net.minecraft.world.scores.Scoreboard;