Skip to content

Commit 8206e47

Browse files
committed
disable chat heads when it find custom characters used for head in vanilla clients
1 parent 1f3c40d commit 8206e47

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

common/src/main/java/dzwdz/chat_heads/ChatHeads.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class ChatHeads {
7676
public static float lastOpacity = 0.0f;
7777
public static int lastChatOffset;
7878
public static boolean serverSentUuid = false;
79+
public static boolean serverSentCustomCharacter = false;
7980

8081
public static final Set<ResourceLocation> blendedHeadTextures = new HashSet<>();
8182

@@ -92,6 +93,19 @@ public static void resetLineOwner() {
9293
}
9394

9495
public static void handleAddedMessage(Component message, @Nullable ChatType.Bound bound, @Nullable PlayerInfo playerInfo) {
96+
if (!ChatHeads.serverSentCustomCharacter) {
97+
Component sender = getSenderDecoration(bound);
98+
if (sender != null && containsCustomCharacters(sender) || containsCustomCharacters(message)) {
99+
ChatHeads.serverSentCustomCharacter = true;
100+
}
101+
}
102+
103+
// TODO check assets
104+
if (ChatHeads.serverSentCustomCharacter) {
105+
ChatHeads.lastSender = null;
106+
return;
107+
}
108+
95109
if (ChatHeads.CONFIG.senderDetection() != HEURISTIC_ONLY) {
96110
if (playerInfo != null) {
97111
ChatHeads.lastSender = playerInfo;
@@ -182,6 +196,11 @@ private static PlayerInfo getPlayerInfo(String name, ClientPacketListener connec
182196
return getPlayerFromNickname(name, connection, nicknameCache);
183197
}
184198

199+
public static boolean containsCustomCharacters(Component component) {
200+
// characters \uE000-\uE007 are used for drawing heads in vanilla clients via a custom font
201+
return component.getString().codePoints().filter(c -> '\uE000' <= c && c <= '\uE007').findAny().isPresent();
202+
}
203+
185204
/**
186205
* Finds a value v in `collection` such that `keyFunction(v)` equals `key`.
187206
* Uses an (initially empty) cache to speed up subsequent calls.

common/src/main/java/dzwdz/chat_heads/mixin/MinecraftMixin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ public abstract class MinecraftMixin {
1414
public void chatheads$resetServerKnowledge(ClientLevel clientLevel, CallbackInfo ci) {
1515
// reset every time we enter a world, be it singleplayer or multiplayer
1616
ChatHeads.serverSentUuid = false;
17+
ChatHeads.serverSentCustomCharacter = false;
1718
}
1819
}

0 commit comments

Comments
 (0)