-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from KingsMMA/fancy-scoreboard
Fancy Scoreboard
- Loading branch information
Showing
5 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...main/java/dev/kingrabbit/fruitfulutilities/config/categories/FancyScoreboardCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package dev.kingrabbit.fruitfulutilities.config.categories; | ||
|
||
import dev.kingrabbit.fruitfulutilities.config.CategoryInfo; | ||
import dev.kingrabbit.fruitfulutilities.config.ConfigCategory; | ||
import dev.kingrabbit.fruitfulutilities.config.properties.ConfigBoolean; | ||
|
||
@SuppressWarnings("CanBeFinal") | ||
@CategoryInfo(id = "scoreboard", display = "Fancy Scoreboard") | ||
public class FancyScoreboardCategory extends ConfigCategory { | ||
|
||
@ConfigBoolean(id = "fancy", display = "Balance Commas", description = "Adds commas to balances in the scoreboard, improving readability.") | ||
public boolean fancy = true; | ||
|
||
|
||
@ConfigBoolean(id = "numbers", display = "Hide Numbers", description = "Hides the red numbers on the side of the scoreboard.") | ||
public boolean numbers = true; | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/dev/kingrabbit/fruitfulutilities/mixin/InGameHudMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dev.kingrabbit.fruitfulutilities.mixin; | ||
|
||
import dev.kingrabbit.fruitfulutilities.FruitfulUtilities; | ||
import dev.kingrabbit.fruitfulutilities.config.ConfigManager; | ||
import dev.kingrabbit.fruitfulutilities.config.categories.FancyScoreboardCategory; | ||
import dev.kingrabbit.fruitfulutilities.util.NumberUtils; | ||
import net.minecraft.client.font.TextRenderer; | ||
import net.minecraft.client.gui.hud.InGameHud; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.text.Text; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import java.util.List; | ||
|
||
@Mixin(InGameHud.class) | ||
public class InGameHudMixin { | ||
|
||
@ModifyArg(method = "renderScoreboardSidebar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;draw(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/text/Text;FFI)I")) | ||
public Text fancyScoreboardNumbers(Text text) { | ||
String textString = text.getString(); | ||
if (!(textString.startsWith("Coins: ") || textString.startsWith("Bank Gold: "))) return text; | ||
ConfigManager configManager = FruitfulUtilities.getInstance().configManager; | ||
if (!(configManager.enabled() && configManager.getCategory(FancyScoreboardCategory.class).fancy)) return text; | ||
|
||
List<Text> siblings = text.getSiblings(); | ||
|
||
if (siblings.size() >= 1) { | ||
List<Text> innerSiblings = siblings.get(0).getSiblings(); | ||
if (innerSiblings.size() >= 2) { | ||
Text costText = innerSiblings.get(1); | ||
Text newCostText = Text.literal(NumberUtils.toFancyNumber(Float.parseFloat(costText.getString().replaceAll(",", "")))).setStyle(costText.getStyle()); | ||
innerSiblings.set(1, newCostText); | ||
} | ||
} | ||
return text; | ||
} | ||
|
||
@ModifyArg(method = "renderScoreboardSidebar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;getWidth(Ljava/lang/String;)I", ordinal = 1)) | ||
public String removeScoreboardNumbersFromWidth(String text) { | ||
ConfigManager configManager = FruitfulUtilities.getInstance().configManager; | ||
return configManager.enabled() && configManager.getCategory(FancyScoreboardCategory.class).numbers ? "" : text; | ||
} | ||
|
||
@Redirect(method = "renderScoreboardSidebar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;draw(Lnet/minecraft/client/util/math/MatrixStack;Ljava/lang/String;FFI)I")) | ||
public int removeScoreboardNumbers(TextRenderer instance, MatrixStack matrices, String text, float x, float y, int color) { | ||
ConfigManager configManager = FruitfulUtilities.getInstance().configManager; | ||
return configManager.enabled() && configManager.getCategory(FancyScoreboardCategory.class).numbers ? 0 : instance.draw(matrices, text, x, y, color); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters