| 1 | package com.jellypudding.offlineclient.mixin;
|
| 2 |
|
| 3 | import com.jellypudding.offlineclient.modules.misc.AntiSpam;
|
| 4 | import com.jellypudding.offlineclient.modules.misc.BetterChat;
|
| 5 | import com.jellypudding.offlineclient.modules.misc.NameProtect;
|
| 6 | import com.jellypudding.offlineclient.util.Modules;
|
| 7 | import net.minecraft.client.gui.components.ChatComponent;
|
| 8 | import net.minecraft.client.multiplayer.chat.GuiMessageSource;
|
| 9 | import net.minecraft.client.multiplayer.chat.GuiMessageTag;
|
| 10 | import net.minecraft.network.chat.Component;
|
| 11 | import net.minecraft.network.chat.MessageSignature;
|
| 12 | import org.spongepowered.asm.mixin.Mixin;
|
| 13 | import org.spongepowered.asm.mixin.injection.At;
|
| 14 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 15 | import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
| 16 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
| 17 | import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
| 18 |
|
| 19 | @Mixin(ChatComponent.class)
|
| 20 | public abstract class ChatComponentMixin {
|
| 21 |
|
| 22 | private static final String ADD_MESSAGE = "addMessage"
|
| 23 | + "(Lnet/minecraft/network/chat/Component;"
|
| 24 | + "Lnet/minecraft/network/chat/MessageSignature;"
|
| 25 | + "Lnet/minecraft/client/multiplayer/chat/GuiMessageSource;"
|
| 26 | + "Lnet/minecraft/client/multiplayer/chat/GuiMessageTag;)V";
|
| 27 |
|
| 28 | @Inject(method = ADD_MESSAGE, at = @At("HEAD"), cancellable = true)
|
| 29 | private void onAddMessage(Component message, MessageSignature signature,
|
| 30 | GuiMessageSource source, GuiMessageTag tag, CallbackInfo ci) {
|
| 31 | BetterChat betterChat = Modules.get(BetterChat.class);
|
| 32 | if (betterChat != null && betterChat.filters(message)) {
|
| 33 | ci.cancel();
|
| 34 | }
|
| 35 | }
|
| 36 |
|
| 37 | @ModifyVariable(method = ADD_MESSAGE, at = @At("HEAD"), argsOnly = true)
|
| 38 | private Component rewriteMessage(Component message) {
|
| 39 | NameProtect nameProtect = Modules.get(NameProtect.class);
|
| 40 | if (nameProtect != null) {
|
| 41 | message = nameProtect.filter(message);
|
| 42 | }
|
| 43 | AntiSpam antiSpam = Modules.get(AntiSpam.class);
|
| 44 | if (antiSpam != null) {
|
| 45 | message = antiSpam.fold((ChatComponent) (Object) this, message);
|
| 46 | }
|
| 47 | BetterChat betterChat = Modules.get(BetterChat.class);
|
| 48 | return betterChat == null ? message : betterChat.decorate(message);
|
| 49 | }
|
| 50 |
|
| 51 | // Both queues trim to the same hundred lines.
|
| 52 | @ModifyExpressionValue(method = {"addMessageToDisplayQueue", "addMessageToQueue"},
|
| 53 | at = @At(value = "CONSTANT", args = "intValue=100"))
|
| 54 | private int historyLimit(int vanilla) {
|
| 55 | BetterChat betterChat = Modules.get(BetterChat.class);
|
| 56 | return betterChat == null ? vanilla : betterChat.historyLimit(vanilla);
|
| 57 | }
|
| 58 |
|
| 59 | // The width the lines are laid out in. A head needs room on the left.
|
| 60 | @ModifyExpressionValue(
|
| 61 | method = "extractRenderState(Lnet/minecraft/client/gui/components/ChatComponent$ChatGraphicsAccess;"
|
| 62 | + "IILnet/minecraft/client/gui/components/ChatComponent$DisplayMode;)V",
|
| 63 | at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;ceil(F)I"))
|
| 64 | private int headRoom(int width) {
|
| 65 | BetterChat betterChat = Modules.get(BetterChat.class);
|
| 66 | return betterChat == null ? width : betterChat.headRoom(width);
|
| 67 | }
|
| 68 |
|
| 69 | // Called on a disconnect and by the debug clear key.
|
| 70 | @Inject(method = "clearMessages(Z)V", at = @At("HEAD"), cancellable = true)
|
| 71 | private void onClearMessages(boolean history, CallbackInfo ci) {
|
| 72 | BetterChat betterChat = Modules.get(BetterChat.class);
|
| 73 | if (betterChat != null && betterChat.keepsHistory()) {
|
| 74 | ci.cancel();
|
| 75 | }
|
| 76 | }
|
| 77 | }
|
| 78 |
|