1717
1818package com .lambda .mixin .render ;
1919
20+ import com .lambda .friend .FriendManager ;
2021import com .lambda .module .modules .render .ExtraTab ;
22+ import com .lambda .util .text .TextBuilder ;
23+ import com .lambda .util .text .TextDslKt ;
24+ import com .llamalad7 .mixinextras .injector .ModifyExpressionValue ;
25+ import kotlin .Unit ;
2126import net .minecraft .client .MinecraftClient ;
2227import net .minecraft .client .gui .hud .PlayerListHud ;
2328import net .minecraft .client .network .PlayerListEntry ;
29+ import net .minecraft .text .MutableText ;
30+ import net .minecraft .text .Text ;
31+ import org .jetbrains .annotations .Nullable ;
2432import org .spongepowered .asm .mixin .Final ;
2533import org .spongepowered .asm .mixin .Mixin ;
2634import org .spongepowered .asm .mixin .Shadow ;
35+ import org .spongepowered .asm .mixin .Unique ;
2736import org .spongepowered .asm .mixin .injection .At ;
37+ import org .spongepowered .asm .mixin .injection .Constant ;
2838import org .spongepowered .asm .mixin .injection .Inject ;
39+ import org .spongepowered .asm .mixin .injection .ModifyConstant ;
2940import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
3041
3142import java .util .Comparator ;
@@ -45,9 +56,35 @@ private void onCollectPlayerEntriesHead(CallbackInfoReturnable<List<PlayerListEn
4556 client .player .networkHandler
4657 .getListedPlayerListEntries ()
4758 .stream ()
59+ .filter (entry -> !ExtraTab .getFriendsOnly () || FriendManager .INSTANCE .isFriend (entry .getProfile ()))
4860 .sorted (ENTRY_ORDERING )
4961 .limit (ExtraTab .getTabEntries ())
5062 .toList ()
5163 );
5264 }
65+
66+ @ ModifyConstant (method = "render" , constant = @ Constant (intValue = 20 ))
67+ private int modifyRowLimit (int original ) {
68+ return ExtraTab .INSTANCE .isEnabled () ? ExtraTab .getRows () : original ;
69+ }
70+
71+ @ ModifyExpressionValue (method = "getPlayerName" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/text/Text;copy()Lnet/minecraft/text/MutableText;" ))
72+ private MutableText modifyPlayerName (MutableText original ) { return modifyName (original ); }
73+
74+ @ ModifyExpressionValue (method = "getPlayerName" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/scoreboard/Team;decorateName(Lnet/minecraft/scoreboard/AbstractTeam;Lnet/minecraft/text/Text;)Lnet/minecraft/text/MutableText;" ))
75+ private MutableText modifyDecorateName (MutableText original ) { return modifyName (original ); }
76+
77+ @ Unique
78+ private @ Nullable MutableText modifyName (Text original ) {
79+ if (ExtraTab .INSTANCE .isDisabled () ||
80+ !ExtraTab .getHighlightFriends () ||
81+ !FriendManager .INSTANCE .isFriend (original .getString ())) return original .copy ();
82+ var newText = original .copy ();
83+ var textBuilder = new TextBuilder ();
84+ TextDslKt .color (textBuilder , ExtraTab .getFriendColor (), builder -> {
85+ builder .styleAndAppend (newText );
86+ return Unit .INSTANCE ;
87+ });
88+ return textBuilder .getText ();
89+ }
5390}
0 commit comments