From 504f2aaf5c743be9a91615cb2fce9f0a45d11962 Mon Sep 17 00:00:00 2001 From: Sin_ender <65603613+sinender@users.noreply.github.com> Date: Fri, 30 Dec 2022 13:54:39 -0500 Subject: Allow for custom messages (#14) * Allowing custom messages to be used. * Gave it the ability to search through custom messages * Updated to not store in config and remove from constructor. * Whoops forgot to remove it from the config * Added @Transient --- .../woverflow/chatting/mixin/GuiNewChatMixin.java | 24 +++++++++++++--------- .../kotlin/cc/woverflow/chatting/chat/ChatTab.kt | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java index 2bc5592..d26dc7b 100644 --- a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java +++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java @@ -1,25 +1,20 @@ package cc.woverflow.chatting.mixin; import cc.polyfrost.oneconfig.config.core.OneColor; -import cc.polyfrost.oneconfig.utils.color.ColorUtils; +import cc.polyfrost.oneconfig.libs.universal.ChatColor; +import cc.polyfrost.oneconfig.libs.universal.UMouse; import cc.woverflow.chatting.Chatting; import cc.woverflow.chatting.chat.ChatSearchingManager; import cc.woverflow.chatting.chat.ChatTabs; import cc.woverflow.chatting.config.ChattingConfig; import cc.woverflow.chatting.gui.components.CleanButton; -import cc.woverflow.chatting.hook.ChatLineHook; import cc.woverflow.chatting.hook.GuiNewChatHook; import cc.woverflow.chatting.utils.ModCompatHooks; import cc.woverflow.chatting.utils.RenderUtils; -import cc.polyfrost.oneconfig.libs.universal.UMouse; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.*; -import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.IChatComponent; -import net.minecraft.util.MathHelper; -import net.minecraft.util.ResourceLocation; +import net.minecraft.util.*; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -34,6 +29,7 @@ import org.spongepowered.asm.mixin.injection.invoke.arg.Args; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; import java.awt.image.BufferedImage; +import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -75,7 +71,8 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Shadow public abstract void deleteChatLine(int id); - @Shadow public abstract int getChatWidth(); + @Shadow + public abstract int getChatWidth(); @Unique private static final ResourceLocation COPY = new ResourceLocation("chatting:copy.png"); @@ -159,7 +156,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { float f = this.getChatScale(); int left = 0; int top = (int) ((float) args.get(2) - 1); - int right = MathHelper.ceiling_float_int((float)getChatWidth() / f) + 4; + int right = MathHelper.ceiling_float_int((float) getChatWidth() / f) + 4; int bottom = (int) ((float) args.get(2) + 8); if ((chatting$shouldCopy && lineInBounds) || isInBounds(left, top, right, bottom, f)) { chatting$shouldCopy = true; @@ -186,6 +183,13 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Redirect(method = "drawChat", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/GuiNewChat;drawnChatLines:Ljava/util/List;", opcode = Opcodes.GETFIELD)) private List injected(GuiNewChat instance) { + if (!ChatTabs.INSTANCE.getCurrentTab().getMessages().isEmpty()) { + List list = new ArrayList<>(); + for (String message : ChatTabs.INSTANCE.getCurrentTab().getMessages()) { + list.add(new ChatLine(0, new ChatComponentText(ChatColor.Companion.translateAlternateColorCodes('&', message)), 0)); + } + return ChatSearchingManager.filterMessages(chatting$previousText, list); + } return ChatSearchingManager.filterMessages(chatting$previousText, drawnChatLines); } diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt index 50de1f4..75b5d69 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt @@ -30,6 +30,7 @@ data class ChatTab( lateinit var button: TabButton lateinit var compiledRegex: ChatRegexes lateinit var compiledIgnoreRegex: ChatRegexes + @Transient var messages: List = ArrayList() //Ugly hack to make GSON not make button / regex null fun initialize() { -- cgit