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 ;
24+ import org .jetbrains .annotations .Nullable ;
2025import org .jetbrains .annotations .VisibleForTesting ;
26+ import org .joml .Matrix3x2fStack ;
2127import org .lwjgl .glfw .GLFW ;
2228import org .slf4j .Logger ;
2329import org .slf4j .LoggerFactory ;
3036import java .nio .file .Path ;
3137import java .util .*;
3238import java .util .concurrent .CompletableFuture ;
39+ import java .util .function .Function ;
3340
3441public class FancyStatusBars {
42+ private static final Identifier HUD_LAYER = SkyblockerMod .id ("fancy_status_bars" );
3543 private static final Path FILE = SkyblockerMod .CONFIG_DIR .resolve ("status_bars.json" );
3644 private static final Logger LOGGER = LoggerFactory .getLogger (FancyStatusBars .class );
3745
@@ -54,6 +62,47 @@ public static boolean isBarEnabled(StatusBarType type) {
5462 @ SuppressWarnings ("deprecation" )
5563 @ Init
5664 public static void init () {
65+ Function <HudElement , HudElement > hideIfFancyStatusBarsEnabled = hudElement -> {
66+ if (Utils .isOnSkyblock () && isEnabled ())
67+ return (context , tickCounter ) -> {};
68+ return hudElement ;
69+ };
70+
71+ HudElementRegistry .replaceElement (VanillaHudElements .HEALTH_BAR , hudElement -> {
72+ if (!Utils .isOnSkyblock () || !isEnabled ()) return hudElement ;
73+ if (isHealthFancyBarEnabled ()) {
74+ return (context , tickCounter ) -> {};
75+ } else if (isExperienceFancyBarEnabled ()) {
76+ return (context , tickCounter ) -> {
77+ Matrix3x2fStack matrices = context .getMatrices ();
78+ matrices .pushMatrix ();
79+ matrices .translate (0 , 6 );
80+ hudElement .render (context , tickCounter );
81+ matrices .popMatrix ();
82+ };
83+ }
84+ return hudElement ;
85+ });
86+ HudElementRegistry .replaceElement (VanillaHudElements .EXPERIENCE_LEVEL , hudElement -> {
87+ if (!Utils .isOnSkyblock () || !isEnabled () || !isExperienceFancyBarEnabled ()) return hudElement ;
88+ return (context , tickCounter ) -> {};
89+ });
90+ HudElementRegistry .replaceElement (VanillaHudElements .INFO_BAR , hudElement -> {
91+ if (!Utils .isOnSkyblock () || !isEnabled () || !isExperienceFancyBarEnabled ()) return hudElement ;
92+ return (context , tickCounter ) -> {};
93+ });
94+ HudElementRegistry .replaceElement (VanillaHudElements .ARMOR_BAR , hideIfFancyStatusBarsEnabled );
95+ HudElementRegistry .replaceElement (VanillaHudElements .MOUNT_HEALTH , hideIfFancyStatusBarsEnabled );
96+ HudElementRegistry .replaceElement (VanillaHudElements .FOOD_BAR , hideIfFancyStatusBarsEnabled );
97+ HudElementRegistry .replaceElement (VanillaHudElements .AIR_BAR , hudElement -> {
98+ if (!Utils .isOnSkyblock () || !isEnabled () || !isBarEnabled (StatusBarType .AIR )) return hudElement ;
99+ return (context , tickCounter ) -> {};
100+ });
101+
102+ HudElementRegistry .attachElementAfter (VanillaHudElements .HOTBAR , HUD_LAYER , (context , tickCounter ) -> {
103+ if (Utils .isOnSkyblock ()) render (context , MinecraftClient .getInstance ());
104+ });
105+
57106 statusBars .put (StatusBarType .HEALTH , StatusBarType .HEALTH .newStatusBar ());
58107 statusBars .put (StatusBarType .INTELLIGENCE , StatusBarType .INTELLIGENCE .newStatusBar ());
59108 statusBars .put (StatusBarType .DEFENSE , StatusBarType .DEFENSE .newStatusBar ());
@@ -152,7 +201,7 @@ public static void placeBarsInPositioner() {
152201 }
153202 }
154203
155- public static JsonObject loadBarConfig () {
204+ public static @ Nullable JsonObject loadBarConfig () {
156205 try (BufferedReader reader = Files .newBufferedReader (FILE )) {
157206 return SkyblockerMod .GSON .fromJson (reader , JsonObject .class );
158207 } catch (NoSuchFileException e ) {
0 commit comments