Skip to content

Commit

Permalink
支持/tell 识别
Browse files Browse the repository at this point in the history
  • Loading branch information
kitUIN committed Feb 2, 2023
1 parent e30884a commit 338cfb0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void onInitializeClient() {
String[] order = entry.getKey().split("->");
if (order[1].equals(order[0]) && "0".equals(order[1])) {
CACHE_MAP.put(order[2], new ChatImageFrame(ChatImageFrame.FrameError.FILE_NOT_FOUND));
return;
}
HashMap<Integer, byte[]> list = new HashMap<>();
if (CLIENT_CACHE_MAP.containsKey(order[2])) {
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/github/kituin/chatimage/mixin/ChatHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.hud.ChatHud;
import net.minecraft.text.*;
import net.minecraft.util.Formatting;
import org.apache.commons.compress.utils.Lists;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -40,11 +41,12 @@ private static Text replaceCode(Text text) {
String key = "";
MutableText player = null;
boolean isSelf = false;
boolean isIncoming = false;
if (text.getContent() instanceof LiteralTextContent) {
checkedText = ((LiteralTextContent) text.getContent()).string();
} else if (text.getContent() instanceof TranslatableTextContent ttc) {
key = ttc.getKey();
if ("chat.type.text".equals(key) || "chat.type.announcement".equals(key)) {
if ("chat.type.text".equals(key) || "chat.type.announcement".equals(key) || "commands.message.display.incoming".equals(key)) {
Text[] args = (Text[]) ttc.getArgs();
player = (MutableText) args[0];
isSelf = player.getContent().toString().equals(MinecraftClient.getInstance().player.getName().getContent().toString());
Expand All @@ -54,6 +56,9 @@ private static Text replaceCode(Text text) {
} else {
checkedText = contents.getContent().toString();
}
if ("commands.message.display.incoming".equals(key)) {
isIncoming = true;
}
}
} else {
checkedText = text.getContent().toString();
Expand Down Expand Up @@ -105,10 +110,13 @@ private static Text replaceCode(Text text) {
if (player == null) {
return res;
} else {
return MutableText.of(new TranslatableTextContent(key, player, res));
MutableText resp = MutableText.of(new TranslatableTextContent(key, player, res));
if (isIncoming) {
return resp.setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(true));
} else {
return resp;
}
}


}

private static Text replaceMessage(Text message) {
Expand Down

0 comments on commit 338cfb0

Please sign in to comment.