@@ -55,7 +55,7 @@ private void render(MatrixStack matrices, int mouseX, int mouseY, float delta, C
5555
5656 for (int i = 0 ; i < Math .min (ClientDB .showScores .size (), 5 ); i ++) {
5757 ScoreboardPlayerScore score = ClientDB .showScores .get (i );
58- ScoreboardRenderer .renderScore (screen , matrices , score , i );
58+ ScoreboardRenderer .renderScore (screen , matrices , score , i , ClientDB . pinnedScores . contains ( score ) );
5959 }
6060
6161 for (int i = 0 ; i < Math .min (ClientDB .showScores .size (), 5 ); i ++) {
@@ -156,14 +156,28 @@ private void search(CallbackInfo ci) {
156156 }
157157 }
158158
159- // don't sort if the amount of scores is too high!!!
159+ Collator collator = Collator .getInstance (Locale .ROOT );
160+ ClientDB .pinnedScores .sort ((score1 , score2 ) -> {
161+ String score1Name = score1 .getPlayerName ();
162+ String score2Name = score2 .getPlayerName ();
163+ return collator .compare (score1Name , score2Name );
164+ });
165+ List <ScoreboardPlayerScore > sortedPins =
166+ ClientDB .pinnedScores .stream ().filter (score ->
167+ score .getPlayerName ().toLowerCase (Locale .ROOT ).contains (searched )).toList ();
168+
169+ // if the amount of scores is too high
160170 if (ClientDB .scores .size () > 10000 ) {
171+ ClientDB .scores .removeAll (sortedPins );
172+ ClientDB .scores .addAll (0 , sortedPins );
161173 return ;
162174 }
163175
164176// hopefully faster sorting than just sorting the whole list at once
165177 HashMap <Character , List <ScoreboardPlayerScore >> scoreByFirstChar = new HashMap <>();
166178 for (ScoreboardPlayerScore score : ClientDB .scores ) {
179+ if (sortedPins .contains (score )) continue ;
180+
167181 char firstChar = score .getPlayerName ().charAt (0 );
168182 if (!scoreByFirstChar .containsKey (firstChar )) {
169183 scoreByFirstChar .put (firstChar , new ArrayList <>());
@@ -172,8 +186,8 @@ private void search(CallbackInfo ci) {
172186 }
173187
174188 ClientDB .scores .clear ();
189+ ClientDB .scores .addAll (sortedPins );
175190
176- Collator collator = Collator .getInstance (Locale .ROOT );
177191 for (char key : scoreByFirstChar .keySet ().stream ().sorted ().toList ()) {
178192 List <ScoreboardPlayerScore > sortedScores = scoreByFirstChar .get (key );
179193 sortedScores .sort ((score1 , score2 ) -> {
@@ -198,4 +212,28 @@ private void mouseScrolled(double mouseX, double mouseY, double amount, Callback
198212 ((CreativeInventoryScreen .CreativeScreenHandler )ClientDB .client .player .currentScreenHandler ).scrollItems (this .scrollPosition );
199213 cir .setReturnValue (true );
200214 }
215+
216+ @ Inject (method = "mouseClicked" , at = @ At ("HEAD" ))
217+ private void onMouseClick (double mouseX , double mouseY , int button , CallbackInfoReturnable <Boolean > cir ) {
218+ if (selectedTab != CommandHelper .ITEM_GROUP .getIndex ()) return ;
219+ if (ClientDB .client .player == null ) return ;
220+ if (button != 0 ) return ;
221+
222+ for (int i = 0 ; i < Math .min (ClientDB .showScores .size (), 5 ); i ++) {
223+ ScoreboardPlayerScore score = ClientDB .showScores .get (i );
224+
225+ if (((HandledScreenAccessor )this ).invokeIsPointWithinBounds (
226+ 9 ,
227+ 18 + 18 * i ,
228+ 18 *9 , 16 , mouseX , mouseY )) {
229+ if (ClientDB .pinnedScores .contains (score )) {
230+ ClientDB .pinnedScores .remove (score );
231+ } else {
232+ ClientDB .pinnedScores .add (score );
233+ }
234+
235+ this .search ();
236+ }
237+ }
238+ }
201239}
0 commit comments