-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from Irgendwer01/main
Add Compact Messages
- Loading branch information
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/mod/acgaming/universaltweaks/tweaks/misc/chat/mixin/UTCompactMessageMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package mod.acgaming.universaltweaks.tweaks.misc.chat.mixin; | ||
|
||
import mod.acgaming.universaltweaks.config.UTConfigTweaks; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.ChatLine; | ||
import net.minecraft.client.gui.GuiNewChat; | ||
import net.minecraft.client.gui.GuiUtilRenderComponents; | ||
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 org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
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.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
@Mixin(GuiNewChat.class) | ||
public abstract class UTCompactMessageMixin { | ||
|
||
@Unique | ||
private Pattern universalTweaks$matchPattern = Pattern.compile("(?:§7)?+\\s+\\(+\\d+\\)"); | ||
|
||
@Shadow | ||
@Final | ||
private List<ChatLine> drawnChatLines = new ArrayList<>(); | ||
|
||
@Shadow | ||
@Final | ||
private List<ChatLine> chatLines = new ArrayList<>(); | ||
|
||
@Shadow @Final private Minecraft mc; | ||
|
||
@Shadow public abstract float getChatScale(); | ||
|
||
@Shadow public abstract int getChatWidth(); | ||
|
||
@Inject(method = "setChatLine", at = @At("HEAD")) | ||
public void utCompactMessage(ITextComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { | ||
if (!UTConfigTweaks.MISC.utCompactMessagesToggle) return; | ||
int count = 1; | ||
int chatSize = MathHelper.floor((float)this.getChatWidth() / this.getChatScale()); | ||
List<ITextComponent> 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 (!chatLine.getChatComponent().getSiblings().isEmpty()) { | ||
for (ITextComponent sibling : chatLine.getChatComponent().getSiblings()) { | ||
if (universalTweaks$matchPattern.matcher(sibling.getUnformattedComponentText()).matches()) { | ||
count += Integer.parseInt(sibling.getUnformattedComponentText().replaceAll("(?:§7)?\\D?", "")); | ||
break; | ||
} | ||
} | ||
} | ||
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; | ||
} | ||
} | ||
} | ||
|
||
@Unique | ||
private boolean universalTweaks$isMessageEqual(ITextComponent msg1, ITextComponent msg2) { | ||
boolean isEqual = false; | ||
if (msg1.equals(msg2) || msg1.getUnformattedText().equals(msg2.getUnformattedText())) { | ||
isEqual = true; | ||
} else { | ||
if (!msg1.getSiblings().isEmpty()) { | ||
for (int i = 0; i < msg1.getSiblings().size(); i++) { | ||
ITextComponent sibling = msg1.getSiblings().get(i); | ||
if (universalTweaks$matchPattern.matcher(sibling.getUnformattedComponentText()).matches()) { | ||
msg1.getSiblings().remove(sibling); | ||
} | ||
} | ||
if (msg1.equals(msg2) || msg1.getUnformattedText().equals(msg2.getUnformattedText())) { | ||
isEqual = true; | ||
} | ||
} | ||
} | ||
return isEqual; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/resources/mixins.tweaks.misc.chat.compactmessage.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"package": "mod.acgaming.universaltweaks.tweaks.misc.chat.mixin", | ||
"refmap": "universaltweaks.refmap.json", | ||
"minVersion": "0.8", | ||
"compatibilityLevel": "JAVA_8", | ||
"client": [ | ||
"UTCompactMessageMixin" | ||
] | ||
} |