Skip to content

Commit 04737d9

Browse files
committed
Prep HideVanillaHidMod
1 parent f1ee4bb commit 04737d9

File tree

5 files changed

+96
-7
lines changed

5 files changed

+96
-7
lines changed

src/main/java/net/kyrptonaught/lemclienthelper/hud/genericHud/GenericHudMod.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
77
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
88
import net.fabricmc.loader.api.FabricLoader;
9+
import net.kyrptonaught.lemclienthelper.hud.genericHud.HideVanillaHUD;
910
import net.kyrptonaught.lemclienthelper.hud.genericHud.packets.BannerPacket;
1011
import net.kyrptonaught.lemclienthelper.hud.genericHud.packets.PlayerBarPacket;
1112

@@ -65,7 +66,13 @@ public static void onInitialize() {
6566
accessor.getStaticDefinitions().add(UIDefinition.createBeforeInit((a) -> {
6667
if ((Boolean)LegacyMixinOptions.legacyGui.get()) {
6768
a.getElements().put(FactoryGuiElement.EXPERIENCE_BAR.name() + ".isVisible", () -> {
68-
return !SHOULD_RENDER_PLAYERBAR;
69+
return HideVanillaHUD.visibe.getValue(HideVanillaHUD.HUD_ELEMENT.EXPERIENCE) && HideVanillaHUD.visibe.getValue(HideVanillaHUD.HUD_ELEMENT.STATS) && HideVanillaHUD.visibe.getValue(HideVanillaHUD.HUD_ELEMENT.ALL);
70+
});
71+
a.getElements().put(FactoryGuiElement.PLAYER_HEALTH.name() + ".isVisible", () -> {
72+
return HideVanillaHUD.visibe.getValue(HideVanillaHUD.HEARTS.HOTBAR) && HideVanillaHUD.visibe.getValue(HideVanillaHUD.HUD_ELEMENT.STATS) && HideVanillaHUD.visibe.getValue(HideVanillaHUD.HUD_ELEMENT.ALL);
73+
});
74+
a.getElements().put(FactoryGuiElement.HOTBAR.name() + ".isVisible", () -> {
75+
return HideVanillaHUD.visibe.getValue(HideVanillaHUD.HUD_ELEMENT.HOTBAR) && HideVanillaHUD.visibe.getValue(HideVanillaHUD.HUD_ELEMENT.ALL);
6976
});
7077
}
7178
}));
@@ -77,7 +84,10 @@ public static void onInitialize() {
7784
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> SHOULD_RENDER_PLAYERBAR = false);
7885

7986
PayloadTypeRegistry.playS2C().register(PlayerBarPacket.PACKET_ID, PlayerBarPacket.codec);
80-
ClientPlayNetworking.registerGlobalReceiver(PlayerBarPacket.PACKET_ID, ((payload, context) -> SHOULD_RENDER_PLAYERBAR = payload.enabled()));
87+
ClientPlayNetworking.registerGlobalReceiver(PlayerBarPacket.PACKET_ID, ((payload, context) -> {
88+
SHOULD_RENDER_PLAYERBAR = payload.enabled();
89+
HideVanillaHUD.visibe.put(HideVanillaHUD.HUD_ELEMENT.EXPERIENCE, !payload.enabled());
90+
}));
8191

8292
PayloadTypeRegistry.playS2C().register(BannerPacket.PACKET_ID, BannerPacket.codec);
8393
ClientPlayNetworking.registerGlobalReceiver(BannerPacket.PACKET_ID, ((payload, context) -> {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package net.kyrptonaught.lemclienthelper.hud.glideHud;
2+
3+
import java.util.HashMap;
4+
5+
import net.kyrptonaught.lemclienthelper.ServerInfo.ServerInfoData;
6+
import net.kyrptonaught.lemclienthelper.hud.HudMod;
7+
import net.minecraft.client.DeltaTracker;
8+
import net.minecraft.client.Minecraft;
9+
import net.minecraft.client.gui.GuiGraphics;
10+
import net.minecraft.resources.ResourceLocation;
11+
import net.minecraft.util.Mth;
12+
13+
public class HideVanillaHUD {
14+
public static final enum HUD_ELEMENT {
15+
ALL,
16+
EXPERIENCE,
17+
HEARTS,
18+
HOTBAR,
19+
HUNGER,
20+
STATS
21+
}
22+
23+
public static HashMap<HUD_ELEMENT, Boolean> visible;
24+
25+
init {
26+
visible.clear();
27+
HUD_ELEMENT.forEach(element ->
28+
visibe.putIfAbsent(element, true)
29+
);
30+
}
31+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package net.kyrptonaught.lemclienthelper.hud.genericHud.packets;
2+
3+
import net.kyrptonaught.lemclienthelper.hud.genericHud.HideVanillaHUD;
4+
import net.minecraft.network.RegistryFriendlyByteBuf;
5+
import net.minecraft.network.chat.Component;
6+
import net.minecraft.network.codec.ByteBufCodecs;
7+
import net.minecraft.network.codec.StreamCodec;
8+
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
9+
import net.minecraft.resources.ResourceLocation;
10+
import net.minecraft.network.chat.ComponentSerialization;
11+
12+
import java.util.Optional;
13+
14+
/**
15+
* HideVanillaHUDPacket sends banner to client
16+
*
17+
* @param element an enumerator, HOTBAR, HEARTS, HUNGER, STATS (Hearts & Hunger), ALL (Hearts, Hunger, & Hotbar).
18+
* @param visibe boolean, Is the element visible, false for hidden, true for shown.
19+
*/
20+
public record HideVanillaHUDPacket(HideVanillaHUD.HUD_ELEMENT element, boolean visible) implements CustomPacketPayload {
21+
public static final Type<HideVanillaHUDPacket> PACKET_ID = new Type<>(ResourceLocation.fromNamespaceAndPath("hud", "hidevanilla"));
22+
public static final StreamCodec<RegistryFriendlyByteBuf, HideVanillaHUDPacket> codec = StreamCodec.composite(
23+
ByteBufCodecs.idMapper(i -> HideVanillaHUD.HUD_ELEMENT.values()[i], HideVanillaHUD.HUD_ELEMENT::ordinal), HideVanillaHUDPacket::element,
24+
ByteBufCodecs.BOOL, HideVanillaHUDPacket::visible,
25+
HideVanillaHUDPacket::new
26+
);
27+
28+
@Override
29+
public Type<? extends CustomPacketPayload> type() {
30+
return PACKET_ID;
31+
}
32+
33+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package net.kyrptonaught.lemclienthelper.mixin.hud.genericHud;
2+
3+
import net.kyrptonaught.lemclienthelper.hud.genericHud.GenericHudMod;
4+
import net.kyrptonaught.lemclienthelper.hud.genericHud.HideVanillaHUD;
5+
import net.kyrptonaught.lemclienthelper.hud.genericHud.PlayerBarRenderer;
6+
import net.minecraft.client.DeltaTracker;
7+
import net.minecraft.client.gui.Gui;
8+
import net.minecraft.client.gui.GuiGraphics;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13+
14+
@Mixin(Gui.class)
15+
public class HideVanillaHUDMixin {
16+
@Inject(method = "renderExperienceBar", at=@At("HEAD"), cancellable = true)
17+
void disableExperienceBar(GuiGraphics guiGraphics, int i, CallbackInfo ci) {
18+
if (!HideVanillaHUD.visibe.getValue(HideVanillaHUD.HUD_ELEMENT.EXPERIENCE) || !HideVanillaHUD.visibe.getValue(HideVanillaHUD.HUD_ELEMENT.ALL)) {ci.cancel();}
19+
}
20+
}

src/main/java/net/kyrptonaught/lemclienthelper/mixin/hud/genericHud/PlayerBarMixin.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,4 @@ public class PlayerBarMixin {
1616
void renderPlayerBar(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci){
1717
PlayerBarRenderer.renderPlayerBar(guiGraphics,deltaTracker);
1818
}
19-
20-
@Inject(method = "renderExperienceBar", at=@At("HEAD"), cancellable = true)
21-
void disableExperienceBar(GuiGraphics guiGraphics, int i, CallbackInfo ci) {
22-
if (GenericHudMod.SHOULD_RENDER_PLAYERBAR) {ci.cancel();}
23-
}
2419
}

0 commit comments

Comments
 (0)