11package com .lambda .mixin .render ;
22
3+ import com .lambda .Lambda ;
34import com .lambda .command .CommandManager ;
45import com .lambda .graphics .renderer .gui .font .FontRenderer ;
56import com .lambda .graphics .renderer .gui .font .LambdaEmoji ;
67import com .lambda .graphics .renderer .gui .font .glyph .GlyphInfo ;
8+ import com .lambda .module .modules .client .LambdaMoji ;
9+ import com .lambda .util .math .Vec2d ;
710import kotlin .Pair ;
811import kotlin .ranges .IntRange ;
912import net .minecraft .client .gui .screen .ChatScreen ;
1316import org .spongepowered .asm .mixin .injection .ModifyArg ;
1417import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
1518
19+ import java .util .ArrayList ;
1620import java .util .Collections ;
1721import java .util .List ;
1822
1923@ Mixin (ChatScreen .class )
2024public abstract class ChatScreenMixin {
2125 @ ModifyArg (method = "sendMessage" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendChatMessage(Ljava/lang/String;)V" ), index = 0 )
2226 private String modifyChatText (String chatText ) {
27+ if (LambdaMoji .INSTANCE .isDisabled ()) return chatText ;
28+
2329 List <Pair <GlyphInfo , IntRange >> emojis = FontRenderer .Companion .parseEmojis (chatText , LambdaEmoji .Twemoji );
2430 Collections .reverse (emojis );
2531
32+ List <String > pushEmojis = new ArrayList <>();
33+ List <Vec2d > pushPositions = new ArrayList <>();
34+
2635 for (Pair <GlyphInfo , IntRange > emoji : emojis ) {
2736 String emojiString = chatText .substring (emoji .getSecond ().getStart () + 1 , emoji .getSecond ().getEndInclusive ());
2837 if (LambdaEmoji .Twemoji .get (emojiString ) == null )
@@ -33,10 +42,20 @@ private String modifyChatText(String chatText) {
3342 // and render it after the text
3443 chatText = chatText .substring (0 , emoji .getSecond ().getStart ()) + " " + chatText .substring (emoji .getSecond ().getEndInclusive () + 1 );
3544
36- // TODO: Build a renderer for the emojis
37- // TODO: Render the emojis at their correct position
45+ // We cannot retain the position in the future, but we can
46+ // assume that every time you send a message the height of
47+ // the position will change by the height of the glyph
48+ // The positions are from the top left corner of the screen
49+ int x = Lambda .getMc ().textRenderer .getWidth (chatText .substring (0 , emoji .getSecond ().getStart ()));
50+ int y = Lambda .getMc ().textRenderer .fontHeight ;
51+
52+ pushEmojis .add (String .format (":%s:" , emojiString ));
53+ pushPositions .add (new Vec2d (x , y ));
3854 }
3955
56+ // Not optimal because it has to parse the emoji again but who cares
57+ LambdaMoji .INSTANCE .add (pushEmojis , pushPositions );
58+
4059 return chatText ;
4160 }
4261
0 commit comments