From d9efde3d2cfdff1c6aba58e80f18569617893ca0 Mon Sep 17 00:00:00 2001 From: cattyn Date: Mon, 14 Jul 2025 17:12:07 +0300 Subject: [PATCH] added CatFormat --- build.gradle | 4 +++ gradle.properties | 1 + src/main/java/me/alpha432/oyvey/OyVey.java | 3 ++ .../features/modules/client/HudModule.java | 3 +- .../java/me/alpha432/oyvey/util/TextUtil.java | 31 +++++++++++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/java/me/alpha432/oyvey/util/TextUtil.java diff --git a/build.gradle b/build.gradle index ceef4d8..67745df 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,7 @@ repositories { // See https://docs.gradle.org/current/userguide/declaring_repositories.html // for more information about repositories. mavenCentral() + maven { url "https://jitpack.io" } } loom { @@ -27,6 +28,9 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + + include implementation("com.github.cattyngmd.catformat:catformat-core:${project.catformat_version}") + include modImplementation("com.github.cattyngmd.catformat:catformat-fabric:${project.catformat_version}") } processResources { diff --git a/gradle.properties b/gradle.properties index 58cd8a0..8aaa713 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,3 +15,4 @@ loader_version=0.16.14 # Dependencies # check this on https://modmuss50.me/fabric.html fabric_version=0.121.0+1.21.5 +catformat_version=2.0.3 \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/OyVey.java b/src/main/java/me/alpha432/oyvey/OyVey.java index 42540e5..b3abb3f 100644 --- a/src/main/java/me/alpha432/oyvey/OyVey.java +++ b/src/main/java/me/alpha432/oyvey/OyVey.java @@ -1,6 +1,7 @@ package me.alpha432.oyvey; import me.alpha432.oyvey.manager.*; +import me.alpha432.oyvey.util.TextUtil; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ModInitializer; import net.minecraft.SharedConstants; @@ -37,6 +38,8 @@ public class OyVey implements ModInitializer, ClientModInitializer { moduleManager = new ModuleManager(); speedManager = new SpeedManager(); holeManager = new HoleManager(); + + TextUtil.init(); } @Override public void onInitializeClient() { diff --git a/src/main/java/me/alpha432/oyvey/features/modules/client/HudModule.java b/src/main/java/me/alpha432/oyvey/features/modules/client/HudModule.java index 6694ebc..a72232e 100644 --- a/src/main/java/me/alpha432/oyvey/features/modules/client/HudModule.java +++ b/src/main/java/me/alpha432/oyvey/features/modules/client/HudModule.java @@ -3,6 +3,7 @@ package me.alpha432.oyvey.features.modules.client; import me.alpha432.oyvey.OyVey; import me.alpha432.oyvey.event.impl.Render2DEvent; import me.alpha432.oyvey.features.modules.Module; +import me.alpha432.oyvey.util.TextUtil; public class HudModule extends Module { public HudModule() { @@ -12,7 +13,7 @@ public class HudModule extends Module { @Override public void onRender2D(Render2DEvent event) { event.getContext().drawTextWithShadow( mc.textRenderer, - OyVey.NAME + " " + OyVey.VERSION, + TextUtil.text("{global} %s {} %s", OyVey.NAME, OyVey.VERSION), 2, 2, -1 ); diff --git a/src/main/java/me/alpha432/oyvey/util/TextUtil.java b/src/main/java/me/alpha432/oyvey/util/TextUtil.java new file mode 100644 index 0000000..716fd3c --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/util/TextUtil.java @@ -0,0 +1,31 @@ +package me.alpha432.oyvey.util; + +import dev.cattyn.catformat.CatFormat; +import dev.cattyn.catformat.fabric.FabricCatFormat; +import me.alpha432.oyvey.OyVey; +import net.minecraft.text.MutableText; + +public final class TextUtil { + private static CatFormat formatter; + + private TextUtil() { + throw new AssertionError("Can't create an instance of utility class"); + } + + public static void init() { + if (formatter != null) throw new IllegalStateException("Formatter is already initialized"); + formatter = new FabricCatFormat(true); + initColors(); + } + + public static MutableText text(String content, Object... obj) { + if (obj == null || obj.length == 0) { + return formatter.format(content); + } + return formatter.format(content, obj); + } + + private static void initColors() { + formatter.add("global", () -> OyVey.colorManager.getColorAsInt()); + } +}