aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/polyfrost/chatting/mixin/GuiUtilRenderComponentsMixin.java
blob: fd497a66be5f654b9ba05ad900653e9ae7cb3080 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package org.polyfrost.chatting.mixin;

import net.minecraft.client.gui.GuiUtilRenderComponents;
import org.polyfrost.chatting.config.ChattingConfig;
import org.polyfrost.chatting.utils.ChatHeadHooks;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(GuiUtilRenderComponents.class)
public class GuiUtilRenderComponentsMixin {
    @Redirect(method = "splitText", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;getStringWidth(Ljava/lang/String;)I"))
    private static int modifyChatLineX(net.minecraft.client.gui.FontRenderer fontRenderer, String text) {
        if (ChattingConfig.INSTANCE.getShowChatHeads() && (ChattingConfig.INSTANCE.getOffsetNonPlayerMessages() || ChatHeadHooks.INSTANCE.detect(text, null))) {
            return fontRenderer.getStringWidth(text) + 10;
        }
        return fontRenderer.getStringWidth(text);
    }
}