diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/chat/mixin/UTCompactMessageMixin.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/chat/mixin/UTCompactMessageMixin.java index 91d88d4d..85def412 100644 --- a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/chat/mixin/UTCompactMessageMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/chat/mixin/UTCompactMessageMixin.java @@ -8,13 +8,12 @@ import net.minecraft.client.gui.ChatLine; import net.minecraft.client.gui.GuiNewChat; import net.minecraft.client.gui.GuiUtilRenderComponents; +import net.minecraft.client.resources.I18n; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.Style; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.*; import mod.acgaming.universaltweaks.config.UTConfigTweaks; +import net.minecraft.util.text.event.HoverEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -55,14 +54,14 @@ public void utCompactMessage(ITextComponent chatComponent, int chatLineId, int u int chatSize = MathHelper.floor(this.getChatWidth() / this.getChatScale()); List splittedText = GuiUtilRenderComponents.splitText(chatComponent, chatSize, this.mc.fontRenderer, false, false); ITextComponent textComponent = splittedText.get(splittedText.size() - 1); - for (int i = 0; i < drawnChatLines.size(); i++) - { - ChatLine chatLine = drawnChatLines.get(i); - if (universalTweaks$isMessageEqual(chatLine.getChatComponent().createCopy(), textComponent.createCopy())) + if (!this.drawnChatLines.isEmpty() && !this.chatLines.isEmpty()) { + ChatLine oldDrawnChatLine = this.drawnChatLines.get(0); + ChatLine oldChatLine = this.chatLines.get(0); + if (universalTweaks$isMessageEqual(oldDrawnChatLine.getChatComponent().createCopy(), textComponent.createCopy())) { - if (!chatLine.getChatComponent().getSiblings().isEmpty()) + if (!oldDrawnChatLine.getChatComponent().getSiblings().isEmpty()) { - for (ITextComponent sibling : chatLine.getChatComponent().getSiblings()) + for (ITextComponent sibling : oldDrawnChatLine.getChatComponent().getSiblings()) { if (universalTweaks$matchPattern.matcher(sibling.getUnformattedComponentText()).matches()) { @@ -71,10 +70,16 @@ public void utCompactMessage(ITextComponent chatComponent, int chatLineId, int u } } } - this.drawnChatLines.removeIf(chatLine1 -> splittedText.contains(chatLine1.getChatComponent()) || chatLine1.equals(chatLine)); - this.chatLines.removeIf(chatLine1 -> chatLine1.getChatComponent().getUnformattedComponentText().equals(chatComponent.getUnformattedComponentText())); - chatComponent.appendSibling(new TextComponentString(" (" + count + ")").setStyle(new Style().setColor(TextFormatting.GRAY))); - break; + if ((oldDrawnChatLine.equals(oldDrawnChatLine) || splittedText.contains(oldDrawnChatLine.getChatComponent())) && oldChatLine.getChatComponent().getUnformattedComponentText().equals(chatComponent.getUnformattedComponentText())) { + this.drawnChatLines.remove(oldDrawnChatLine); + this.chatLines.remove(oldChatLine); + } + // this.drawnChatLines.removeIf(chatLine1 -> splittedText.contains(chatLine1.getChatComponent()) || chatLine1.equals(chatLine)); + // this.chatLines.removeIf(chatLine1 -> chatLine1.getChatComponent().getUnformattedComponentText().equals(chatComponent.getUnformattedComponentText())); + ITextComponent textComponentCount = new TextComponentString(" (" + count + ")").setStyle(new Style().setColor(TextFormatting.GRAY)); + textComponentCount.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(I18n.format("msg.universaltweaks.compactmessages.count", count)))); + chatComponent.appendSibling(textComponentCount); + } } } diff --git a/src/main/resources/assets/universaltweaks/lang/de_de.lang b/src/main/resources/assets/universaltweaks/lang/de_de.lang index f7c0449d..2ba1ab5e 100644 --- a/src/main/resources/assets/universaltweaks/lang/de_de.lang +++ b/src/main/resources/assets/universaltweaks/lang/de_de.lang @@ -26,4 +26,7 @@ btn.universaltweaks.lanserverproperties.online_mode=Online-Modus btn.universaltweaks.lanserverproperties.online_mode_desc=Deaktivierung ermöglicht nicht authentifizierte Verbindungen btn.universaltweaks.lanserverproperties.port=Abhörender Port btn.universaltweaks.lanserverproperties.spawn_animals=Erschaffe Tiere -btn.universaltweaks.lanserverproperties.spawn_npcs=Erschaffe NPCs \ No newline at end of file +btn.universaltweaks.lanserverproperties.spawn_npcs=Erschaffe NPCs + +# COMPACT MESSAGES +msg.universaltweaks.compactmessages.count=Diese Nachricht wurde %s mal/e wiederholt diff --git a/src/main/resources/assets/universaltweaks/lang/en_us.lang b/src/main/resources/assets/universaltweaks/lang/en_us.lang index f247db62..8e768eba 100644 --- a/src/main/resources/assets/universaltweaks/lang/en_us.lang +++ b/src/main/resources/assets/universaltweaks/lang/en_us.lang @@ -33,6 +33,9 @@ btn.universaltweaks.lanserverproperties.port=Listening Port btn.universaltweaks.lanserverproperties.spawn_animals=Spawn Animals btn.universaltweaks.lanserverproperties.spawn_npcs=Spawn NPCs +# COMPACT MESSAGES +msg.universaltweaks.compactmessages.count=This message has been repeated %s times + # CONFIG # Doesn't need to be translated because config is English in general cfg.universaltweaks.config.blocks=Blocks