diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2023-01-14 14:51:55 -0500 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2023-01-14 14:51:55 -0500 |
commit | e52b994b8a7c32badab7017dc0040d6bfb1cbedb (patch) | |
tree | b7f1005a994524ee4f55b4eb0cf70e5038aef07a /src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_ChatTabs.java | |
parent | e574e54a53b87ef4bbb33404b6fdb6b97c72dd81 (diff) | |
download | Chatting-e52b994b8a7c32badab7017dc0040d6bfb1cbedb.tar.gz Chatting-e52b994b8a7c32badab7017dc0040d6bfb1cbedb.tar.bz2 Chatting-e52b994b8a7c32badab7017dc0040d6bfb1cbedb.zip |
split GuiNewChatMixin into different mixins
Diffstat (limited to 'src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_ChatTabs.java')
-rw-r--r-- | src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_ChatTabs.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_ChatTabs.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_ChatTabs.java new file mode 100644 index 0000000..1d29941 --- /dev/null +++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_ChatTabs.java @@ -0,0 +1,62 @@ +package cc.woverflow.chatting.mixin; + +import cc.woverflow.chatting.chat.ChatSearchingManager; +import cc.woverflow.chatting.chat.ChatTabs; +import cc.woverflow.chatting.config.ChattingConfig; +import cc.woverflow.chatting.utils.ModCompatHooks; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ChatLine; +import net.minecraft.client.gui.GuiNewChat; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IChatComponent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; +import java.util.Locale; + +@Mixin(GuiNewChat.class) +public abstract class GuiNewChatMixin_ChatTabs { + @Shadow @Final private Minecraft mc; + + @Shadow public abstract void deleteChatLine(int id); + + @Shadow @Final private List<ChatLine> chatLines; + @SuppressWarnings({"FieldCanBeLocal", "unused"}) + private float percentComplete; //betterchat support + + @Inject(method = "printChatMessageWithOptionalDeletion", at = @At("HEAD"), cancellable = true) + private void handlePrintChatMessage(IChatComponent chatComponent, int chatLineId, CallbackInfo ci) { + handleChatTabMessage(chatComponent, chatLineId, mc.ingameGUI.getUpdateCounter(), false, ci); + if (!EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.getUnformattedText()).toLowerCase(Locale.ENGLISH).contains(ChatSearchingManager.INSTANCE.getLastSearch().toLowerCase(Locale.ENGLISH))) { + percentComplete = 1.0F; + } + } + + @Inject(method = "setChatLine", at = @At("HEAD"), cancellable = true) + private void handleSetChatLine(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { + handleChatTabMessage(chatComponent, chatLineId, updateCounter, displayOnly, ci); + } + + private void handleChatTabMessage(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { + if (ChattingConfig.INSTANCE.getChatTabs()) { + if (!ChatTabs.INSTANCE.shouldRender(chatComponent)) { + percentComplete = 1.0F; + if (chatLineId != 0) { + deleteChatLine(chatLineId); + } + if (!displayOnly) { + chatLines.add(0, new ChatLine(updateCounter, chatComponent, chatLineId)); + while (this.chatLines.size() > (100 + ModCompatHooks.getExtendedChatLength())) { + this.chatLines.remove(this.chatLines.size() - 1); + } + } + ci.cancel(); + } + } + } +} |