1212import net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager ;
1313import net .fabricmc .fabric .api .client .command .v2 .ClientCommandRegistrationCallback ;
1414import net .fabricmc .fabric .api .client .event .lifecycle .v1 .ClientLifecycleEvents ;
15+ import net .fabricmc .fabric .api .client .rendering .v1 .hud .HudElement ;
16+ import net .fabricmc .fabric .api .client .rendering .v1 .hud .HudElementRegistry ;
17+ import net .fabricmc .fabric .api .client .rendering .v1 .hud .VanillaHudElements ;
1518import net .minecraft .client .MinecraftClient ;
1619import net .minecraft .client .gui .DrawContext ;
1720import net .minecraft .client .gui .ScreenPos ;
1821import net .minecraft .client .network .ClientPlayerEntity ;
22+ import net .minecraft .util .Identifier ;
1923import net .minecraft .util .math .MathHelper ;
2024import org .jetbrains .annotations .VisibleForTesting ;
25+ import org .joml .Matrix3x2fStack ;
26+ import org .jspecify .annotations .Nullable ;
2127import org .lwjgl .glfw .GLFW ;
2228import org .slf4j .Logger ;
2329import org .slf4j .LoggerFactory ;
3541import java .util .List ;
3642import java .util .Map ;
3743import java .util .concurrent .CompletableFuture ;
44+ import java .util .function .Function ;
3845
3946public class FancyStatusBars {
47+ private static final Identifier HUD_LAYER = SkyblockerMod .id ("fancy_status_bars" );
4048 private static final Path FILE = SkyblockerMod .CONFIG_DIR .resolve ("status_bars.json" );
4149 private static final Logger LOGGER = LoggerFactory .getLogger (FancyStatusBars .class );
4250
@@ -59,6 +67,47 @@ public static boolean isBarEnabled(StatusBarType type) {
5967 @ SuppressWarnings ("deprecation" )
6068 @ Init
6169 public static void init () {
70+ Function <HudElement , HudElement > hideIfFancyStatusBarsEnabled = hudElement -> {
71+ if (Utils .isOnSkyblock () && isEnabled ())
72+ return (context , tickCounter ) -> {};
73+ return hudElement ;
74+ };
75+
76+ HudElementRegistry .replaceElement (VanillaHudElements .HEALTH_BAR , hudElement -> {
77+ if (!Utils .isOnSkyblock () || !isEnabled ()) return hudElement ;
78+ if (isHealthFancyBarEnabled ()) {
79+ return (context , tickCounter ) -> {};
80+ } else if (isExperienceFancyBarEnabled ()) {
81+ return (context , tickCounter ) -> {
82+ Matrix3x2fStack matrices = context .getMatrices ();
83+ matrices .pushMatrix ();
84+ matrices .translate (0 , 6 );
85+ hudElement .render (context , tickCounter );
86+ matrices .popMatrix ();
87+ };
88+ }
89+ return hudElement ;
90+ });
91+ HudElementRegistry .replaceElement (VanillaHudElements .EXPERIENCE_LEVEL , hudElement -> {
92+ if (!Utils .isOnSkyblock () || !isEnabled () || !isExperienceFancyBarEnabled ()) return hudElement ;
93+ return (context , tickCounter ) -> {};
94+ });
95+ HudElementRegistry .replaceElement (VanillaHudElements .INFO_BAR , hudElement -> {
96+ if (!Utils .isOnSkyblock () || !isEnabled () || !isExperienceFancyBarEnabled ()) return hudElement ;
97+ return (context , tickCounter ) -> {};
98+ });
99+ HudElementRegistry .replaceElement (VanillaHudElements .ARMOR_BAR , hideIfFancyStatusBarsEnabled );
100+ HudElementRegistry .replaceElement (VanillaHudElements .MOUNT_HEALTH , hideIfFancyStatusBarsEnabled );
101+ HudElementRegistry .replaceElement (VanillaHudElements .FOOD_BAR , hideIfFancyStatusBarsEnabled );
102+ HudElementRegistry .replaceElement (VanillaHudElements .AIR_BAR , hudElement -> {
103+ if (!Utils .isOnSkyblock () || !isEnabled () || !isBarEnabled (StatusBarType .AIR )) return hudElement ;
104+ return (context , tickCounter ) -> {};
105+ });
106+
107+ HudElementRegistry .attachElementAfter (VanillaHudElements .HOTBAR , HUD_LAYER , (context , tickCounter ) -> {
108+ if (Utils .isOnSkyblock ()) render (context , MinecraftClient .getInstance ());
109+ });
110+
62111 statusBars .put (StatusBarType .HEALTH , StatusBarType .HEALTH .newStatusBar ());
63112 statusBars .put (StatusBarType .INTELLIGENCE , StatusBarType .INTELLIGENCE .newStatusBar ());
64113 statusBars .put (StatusBarType .DEFENSE , StatusBarType .DEFENSE .newStatusBar ());
@@ -158,7 +207,7 @@ public static void placeBarsInPositioner() {
158207 }
159208 }
160209
161- public static JsonObject loadBarConfig () {
210+ public static @ Nullable JsonObject loadBarConfig () {
162211 try (BufferedReader reader = Files .newBufferedReader (FILE )) {
163212 return SkyblockerMod .GSON .fromJson (reader , JsonObject .class );
164213 } catch (NoSuchFileException e ) {
0 commit comments