diff options
author | Sin_ender <65603613+sinender@users.noreply.github.com> | 2022-12-30 13:54:39 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-31 03:54:39 +0900 |
commit | 504f2aaf5c743be9a91615cb2fce9f0a45d11962 (patch) | |
tree | f4ee384b8572a8ea51cfd06cb44bc74f47de6e35 /src | |
parent | 135a36eceded2d264e2a2ca634f490e056cd7ce4 (diff) | |
download | Chatting-504f2aaf5c743be9a91615cb2fce9f0a45d11962.tar.gz Chatting-504f2aaf5c743be9a91615cb2fce9f0a45d11962.tar.bz2 Chatting-504f2aaf5c743be9a91615cb2fce9f0a45d11962.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java | 24 | ||||
-rw-r--r-- | src/main/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<ChatLine> injected(GuiNewChat instance) { + if (!ChatTabs.INSTANCE.getCurrentTab().getMessages().isEmpty()) { + List<ChatLine> 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<String> = ArrayList() //Ugly hack to make GSON not make button / regex null fun initialize() { |