Skip to content

Commit 7733395

Browse files
committed
Glide HUD rendering and Banner Rendering fixes
TODO Buffer madness for armour hud.
1 parent e024ee5 commit 7733395

File tree

4 files changed

+33
-37
lines changed

4 files changed

+33
-37
lines changed

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package net.kyrptonaught.lemclienthelper.hud.genericHud;
22

3-
import com.mojang.blaze3d.systems.RenderSystem;
43
import net.kyrptonaught.lemclienthelper.ServerInfo.ServerInfoData;
54
import net.minecraft.client.DeltaTracker;
65
import net.minecraft.client.Minecraft;
76
import net.minecraft.client.gui.Font;
87
import net.minecraft.client.gui.GuiGraphics;
8+
import net.minecraft.client.renderer.RenderPipelines;
99
import net.minecraft.resources.ResourceLocation;
10+
import net.minecraft.util.ARGB;
1011
import net.minecraft.util.Mth;
1112

1213
import static net.kyrptonaught.lemclienthelper.ServerInfo.ServerInfoData.GAME_MODES.*;
@@ -46,7 +47,6 @@ public static void render(GuiGraphics context, float lastDur) {
4647
int y = ((13 * height)/50) - (int)((34 * shieldScale)/2);
4748

4849
context.pose().pushMatrix();
49-
RenderSystem.enableBlend();
5050

5151
if (elapsed >= 0.1f) { renderParticles(context,elapsed,(width/2),height); }
5252
renderShield(context,x,y);
@@ -76,26 +76,24 @@ private static void renderBanner(GuiGraphics context, float elapsed, int width,
7676
int x = (width/2) - (int)((bannerWidth)/2);
7777
int y = ((13 * height)/50) + (int)((7.5*((2*bannerScale)/2.4f)));
7878

79-
context.blit(BANNER, (x-(7*(int)bannerScale)), y,(7*(int)(bannerScale)),8*(int)(bannerScale),0,0,7,8,31,8);
80-
context.blit(BANNER, (x), y, (int) bannerWidth,8*(int)(bannerScale), 7*(int)(bannerScale),0, 1,8,31,8);
81-
context.blit(BANNER, ((width/2)+(int)((bannerWidth)/2)), y,7*(int)(bannerScale),8*(int)(bannerScale),24,0,7,8,31,8);
79+
context.blit(RenderPipelines.GUI_TEXTURED, BANNER, (x-(7*(int)bannerScale)), y,(7*(int)(bannerScale)),8*(int)(bannerScale),0,0,7,8,31,8, ARGB.white(1f));
80+
context.blit(RenderPipelines.GUI_TEXTURED, BANNER, (x), y, (int) bannerWidth,8*(int)(bannerScale), 7*(int)(bannerScale),0, 1,8,31,8, ARGB.white(1f));
81+
context.blit(RenderPipelines.GUI_TEXTURED, BANNER, ((width/2)+(int)((bannerWidth)/2)), y,7*(int)(bannerScale),8*(int)(bannerScale),24,0,7,8,31,8, ARGB.white(1f));
8282

83-
context.pose().translate(0f,0.25f,0f);
84-
RenderSystem.setShaderColor(1,1,1,textTrans);
85-
context.drawString(textRenderer,GenericHudMod.BANNER_TEXT,x-((2*(int)bannerScale)),y+2,0x444444,false);
86-
RenderSystem.setShaderColor(1,1,1,1);
87-
context.pose().translate(0f,-0.25f,0f);
83+
context.pose().translate(0f,0.25f);
84+
int textColor = ARGB.color((int) (textTrans*255),68, 68, 68);
85+
context.drawString(textRenderer,GenericHudMod.BANNER_TEXT,x-((2*(int)bannerScale)),y+2,textColor,false);
86+
context.pose().translate(0f,-0.25f);
8887
}
8988

9089
private static void renderParticles(GuiGraphics context, float elapsed, int x, int height) {
9190
float potionPosY = Mth.lerp((elapsed/(24f/30f)), 72f, 56f);
9291
float potionPosX = Mth.lerp((elapsed/(24f/30f)), 16f, 40f);
9392
float posTrans = Mth.lerp((elapsed/(24f/30f)), 1f, 0f);
9493

95-
RenderSystem.setShaderColor(1f, 1f, 1f, posTrans);
96-
context.blit(PARTICLE, (x - 8) - (int) potionPosX, (((13 * height) / 50) - (int) ((34 * 2.8f) / 2)) + (int) potionPosY, 0, 0, 16, 16, 16, 16);
97-
context.blit(PARTICLE, (x - 8) + (int) potionPosX, (((13 * height) / 50) - (int) ((34 * 2.8f) / 2)) + (int) potionPosY, 0, 0, 16, 16, 16, 16);
98-
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
94+
int color = ARGB.white(posTrans);
95+
context.blitSprite(RenderPipelines.GUI_TEXTURED, PARTICLE, (x - 8) - (int) potionPosX, (((13 * height) / 50) - (int) ((34 * 2.8f) / 2)) + (int) potionPosY, 16, 16, color);
96+
context.blitSprite(RenderPipelines.GUI_TEXTURED, PARTICLE, (x - 8) + (int) potionPosX, (((13 * height) / 50) - (int) ((34 * 2.8f) / 2)) + (int) potionPosY, 16, 16, color);
9997
}
10098

10199
private static void renderShield(GuiGraphics context, int x, int y) {

src/main/java/net/kyrptonaught/lemclienthelper/hud/genericHud/packets/HideVanillaHUDPacket.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package net.kyrptonaught.lemclienthelper.hud.genericHud.packets;
22

33
import net.kyrptonaught.lemclienthelper.hud.genericHud.HideVanillaHUD;
4-
import net.kyrptonaught.lemclienthelper.hud.glideHud.GlideHudMod;
54
import net.minecraft.network.RegistryFriendlyByteBuf;
6-
import net.minecraft.network.chat.Component;
75
import net.minecraft.network.codec.ByteBufCodecs;
86
import net.minecraft.network.codec.StreamCodec;
97
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
108
import net.minecraft.resources.ResourceLocation;
11-
import net.minecraft.network.chat.ComponentSerialization;
12-
13-
import java.util.Optional;
149

1510
/**
1611
* HideVanillaHUDPacket sends banner to client

src/main/java/net/kyrptonaught/lemclienthelper/hud/glideHud/GlideHudMod.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
44
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
55
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
6-
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
6+
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
7+
import net.fabricmc.fabric.api.client.rendering.v1.hud.VanillaHudElements;
78
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
9+
import net.kyrptonaught.lemclienthelper.LEMClientHelperMod;
810
import net.kyrptonaught.lemclienthelper.hud.HudMod;
911
import net.kyrptonaught.lemclienthelper.hud.glideHud.packets.GlideHudPacket;
1012
import net.kyrptonaught.lemclienthelper.hud.glideHud.packets.GlideScorePacket;
1113
import net.kyrptonaught.lemclienthelper.hud.glideHud.packets.GlideTimerPacket;
1214
import net.kyrptonaught.lemclienthelper.hud.glideHud.packets.GlideTimerTogglePacket;
15+
import net.minecraft.resources.ResourceLocation;
1316

1417
/*
1518
import com.mojang.brigadier.arguments.BoolArgumentType;
@@ -41,7 +44,7 @@ public enum rings {
4144
}
4245

4346
public static void onInitialize() {
44-
HudRenderCallback.EVENT.register(GlideHudRenderer::onHudRender);
47+
HudElementRegistry.attachElementAfter(VanillaHudElements.SCOREBOARD, ResourceLocation.fromNamespaceAndPath(LEMClientHelperMod.MOD_ID, "glide_stats"), GlideHudRenderer::onHudRender);
4548

4649
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> SHOULD_RENDER_GLIDE = false);
4750

src/main/java/net/kyrptonaught/lemclienthelper/hud/glideHud/GlideHudRenderer.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import net.minecraft.client.DeltaTracker;
66
import net.minecraft.client.Minecraft;
77
import net.minecraft.client.gui.GuiGraphics;
8+
import net.minecraft.client.renderer.RenderPipelines;
89
import net.minecraft.resources.ResourceLocation;
10+
import net.minecraft.util.ARGB;
911
import net.minecraft.util.Mth;
1012

1113
public class GlideHudRenderer {
@@ -45,22 +47,20 @@ public static void onHudRender(GuiGraphics context, DeltaTracker v) {
4547
int width = client.getWindow().getGuiScaledWidth();
4648

4749
context.pose().pushMatrix();
48-
context.pose().translate((width - HudMod.getConfig().xOffset), height / 2f, 0);
49-
context.pose().scale(HudMod.getConfig().armorHudScale, HudMod.getConfig().armorHudScale, 1f);
50-
context.pose().translate(0, -24, 0);
51-
if (ServerInfoData.getGamemode() == ServerInfoData.GAME_MODES.SCORE_ATTACK) {context.pose().translate(0, 24, 0);}
52-
context.setColor(1f, 1f, 1f, HudMod.getConfig().transparency);
50+
context.pose().translate((width - HudMod.getConfig().xOffset), height / 2f);
51+
context.pose().scale(HudMod.getConfig().armorHudScale, HudMod.getConfig().armorHudScale);
52+
context.pose().translate(0, -24);
53+
if (ServerInfoData.getGamemode() == ServerInfoData.GAME_MODES.SCORE_ATTACK) {context.pose().translate(0, 24);}
5354
renderStopwatch(context, client);
5455
renderSpeedometer(context, client);
5556
if (ServerInfoData.getGamemode() == ServerInfoData.GAME_MODES.SCORE_ATTACK) {renderScore(context, client);}
56-
context.setColor(1f, 1f, 1f, 1f);
5757
context.pose().popMatrix();
5858
}
5959
}
6060

6161

6262
public static void renderStopwatch(GuiGraphics context, Minecraft client) {
63-
context.blit(STOPWATCH, 0, -50,0,0,16,16,16,16);
63+
context.blitSprite(RenderPipelines.GUI_TEXTURED, STOPWATCH, 0, -50,16,16, HudMod.getConfig().transparency);
6464
if (GlideHudMod.TIMER_RUNNING) {
6565
elapsed = GlideHudMod.ELAPSED_TIME;
6666
GlideHudMod.FINAL_TIME = elapsed; //This prevents the time from displaying 0 if the final time packet is not received.
@@ -73,33 +73,33 @@ public static void renderStopwatch(GuiGraphics context, Minecraft client) {
7373
int secondsindex = (seconds / 10) % 11;
7474
int minutesindex = (minutes / 5) % 11;
7575

76-
context.blit(SECONDS_HAND(secondsindex), 0, -50,0,0,16,16,16,16);
77-
context.blit(MINUTES_HAND(minutesindex), 0, -50,0,0,16,16,16,16);
76+
context.blitSprite(RenderPipelines.GUI_TEXTURED, SECONDS_HAND(secondsindex), 0, -50, 16,16, HudMod.getConfig().transparency);
77+
context.blitSprite(RenderPipelines.GUI_TEXTURED, MINUTES_HAND(minutesindex), 0, -50, 16,16, HudMod.getConfig().transparency);
7878

7979
String timer = String.format("%d:%02d.%03d", minutes, seconds, milliseconds);
8080

8181
int textWidth = client.font.width(timer);
82-
context.pose().scale(1.25f,1.25f,1.25f);
83-
context.drawString(client.font, timer, (-4 - textWidth), -38, 0xffffff, true);
84-
context.pose().scale(0.8f,0.8f,0.8f);
82+
context.pose().scale(1.25f,1.25f);
83+
context.drawString(client.font, timer, (-4 - textWidth), -38, ARGB.white(HudMod.getConfig().transparency), true);
84+
context.pose().scale(0.8f,0.8f);
8585
}
8686

8787
public static void renderSpeedometer(GuiGraphics context, Minecraft client) {
8888
double mps = client.player.getDeltaMovement().horizontalDistance() * 20;
8989
int needleIndex = Mth.clamp(Mth.floor(0.24 * mps - 0.5), 0, 11);
90-
context.blit(SPEEDOMETER, 0, -30,0,0,16,16,16,16);
91-
context.blit(SPEEDOMETER_NEEDLE(needleIndex), 0, -30,0,0,16,16, 16,16);
90+
context.blitSprite(RenderPipelines.GUI_TEXTURED, SPEEDOMETER, 0, -30,16,16, HudMod.getConfig().transparency);
91+
context.blitSprite(RenderPipelines.GUI_TEXTURED, SPEEDOMETER_NEEDLE(needleIndex), 0, -30,16,16, HudMod.getConfig().transparency);
9292

9393
String speed = String.format("%.2f m/s", mps);
9494
int textWidth = client.font.width(speed);
95-
context.drawString(client.font, speed, (-4 - textWidth), (-30), 0xffffff, true);
95+
context.drawString(client.font, speed, (-4 - textWidth), (-30), ARGB.white(HudMod.getConfig().transparency), true);
9696
}
9797

9898
public static void renderScore(GuiGraphics context, Minecraft client) {
9999
context.blit(SPEEDOMETER, 0, -10,0,0,16,16,16,16);
100100

101101
String score = String.valueOf(GlideHudMod.GLIDE_SCORE);
102102
int textWidth = client.font.width(score);
103-
context.drawString(client.font, score, (-4 - textWidth), (-30), 0xffffff, true);
103+
context.drawString(client.font, score, (-4 - textWidth), (-30), ARGB.white(HudMod.getConfig().transparency), true);
104104
}
105105
}

0 commit comments

Comments
 (0)