Selaa lähdekoodia

Added consecutive order option

Lortseam 4 vuotta sitten
vanhempi
sitoutus
c62866020a

+ 21 - 1
src/main/java/me/lortseam/uglyscoreboardfix/UglyScoreboardFix.java

@@ -9,6 +9,8 @@ import me.lortseam.completeconfig.api.ConfigEntry;
 import net.fabricmc.api.ClientModInitializer;
 import net.fabricmc.api.EnvType;
 import net.fabricmc.api.Environment;
+import net.minecraft.scoreboard.ScoreboardObjective;
+import net.minecraft.scoreboard.ScoreboardPlayerScore;
 
 @Environment(EnvType.CLIENT)
 public class UglyScoreboardFix implements ClientModInitializer, ConfigCategory, ModMenuApi {
@@ -19,9 +21,10 @@ public class UglyScoreboardFix implements ClientModInitializer, ConfigCategory,
 
     @Getter
     private ConfigManager configManager;
-    @Getter
     @ConfigEntry
     private boolean enabled = true;
+    @ConfigEntry
+    private boolean consecutiveOrderOnly = true;
 
     @Override
     public void onInitializeClient() {
@@ -30,4 +33,21 @@ public class UglyScoreboardFix implements ClientModInitializer, ConfigCategory,
         configManager.register(this);
     }
 
+    public boolean shouldHideScores(ScoreboardObjective objective) {
+        if (!enabled) {
+            return false;
+        }
+        if (consecutiveOrderOnly) {
+            int[] scores = objective.getScoreboard().getAllPlayerScores(objective).stream().mapToInt(ScoreboardPlayerScore::getScore).toArray();
+            if (scores.length >= 2) {
+                for (int i = 1; i < scores.length; i++) {
+                    if (scores[i - 1] + 1 != scores[i]) {
+                        return false;
+                    }
+                }
+            }
+        }
+        return true;
+    }
+
 }

+ 8 - 6
src/main/java/me/lortseam/uglyscoreboardfix/mixin/MixinInGameHud.java

@@ -3,6 +3,8 @@ package me.lortseam.uglyscoreboardfix.mixin;
 import me.lortseam.uglyscoreboardfix.UglyScoreboardFix;
 import net.minecraft.client.font.TextRenderer;
 import net.minecraft.client.gui.hud.InGameHud;
+import net.minecraft.client.util.math.MatrixStack;
+import net.minecraft.scoreboard.ScoreboardObjective;
 import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.injection.At;
 import org.spongepowered.asm.mixin.injection.ModifyVariable;
@@ -12,18 +14,18 @@ import org.spongepowered.asm.mixin.injection.Redirect;
 public abstract class MixinInGameHud {
 
     @ModifyVariable(method = "renderScoreboardSidebar", at = @At(value = "STORE"))
-    private String uglyscoreboardfix$modifyScore(String score) {
-        return UglyScoreboardFix.getInstance().isEnabled() ? "" : score;
+    private String uglyscoreboardfix$modifyScore(String score, MatrixStack matrices, ScoreboardObjective objective) {
+        return UglyScoreboardFix.getInstance().shouldHideScores(objective) ? "" : score;
     }
 
     @ModifyVariable(method = "renderScoreboardSidebar", at = @At(value = "STORE"), ordinal = 2)
-    private int uglyscoreboardfix$modifySeperatorWidth(int seperatorWidth) {
-        return UglyScoreboardFix.getInstance().isEnabled() ? 0 : seperatorWidth;
+    private int uglyscoreboardfix$modifySeperatorWidth(int seperatorWidth, MatrixStack matrices, ScoreboardObjective objective) {
+        return UglyScoreboardFix.getInstance().shouldHideScores(objective) ? 0 : seperatorWidth;
     }
 
     @Redirect(method = "renderScoreboardSidebar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;getWidth(Ljava/lang/String;)I", ordinal = 1))
-    private int uglyscoreboardfix$modifyScoreWidth(TextRenderer textRenderer, String score) {
-        return UglyScoreboardFix.getInstance().isEnabled() ? 0 : textRenderer.getWidth(score);
+    private int uglyscoreboardfix$modifyScoreWidth(TextRenderer textRenderer, String score, MatrixStack matrices, ScoreboardObjective objective) {
+        return UglyScoreboardFix.getInstance().shouldHideScores(objective) ? 0 : textRenderer.getWidth(score);
     }
 
 }

+ 2 - 1
src/main/resources/assets/uglyscoreboardfix/lang/de_de.json

@@ -1,4 +1,5 @@
 {
   "config.uglyscoreboardfix.title": "Ugly Scoreboard Fix Konfiguration",
-  "config.uglyscoreboardfix.uglyScoreboardFix.enabled": "Aktiviert"
+  "config.uglyscoreboardfix.uglyScoreboardFix.enabled": "Aktiviert",
+  "config.uglyscoreboardfix.uglyScoreboardFix.consecutiveOrderOnly": "Nur bei aufeinanderfolgender Reihenfolge"
 }

+ 2 - 1
src/main/resources/assets/uglyscoreboardfix/lang/en_us.json

@@ -1,4 +1,5 @@
 {
   "config.uglyscoreboardfix.title": "Ugly Scoreboard Fix Configuration",
-  "config.uglyscoreboardfix.uglyScoreboardFix.enabled": "Enabled"
+  "config.uglyscoreboardfix.uglyScoreboardFix.enabled": "Enabled",
+  "config.uglyscoreboardfix.uglyScoreboardFix.consecutiveOrderOnly": "Consecutive order only"
 }