Moved some magical numbers into variables.

This commit is contained in:
2024-05-15 18:52:08 +01:00
parent 459e74013c
commit 28b82950bc

View File

@ -26,28 +26,34 @@ public class GuiRenderTickMixin {
return;
}
// Initialize variables
double screenHalfWidth = Minecraft.getInstance().getWindow().getGuiScaledWidth() / 2.0;
double screenHalfHeight = Minecraft.getInstance().getWindow().getGuiScaledHeight() / 2.0;
// Setup
PoseStack poseStack = guiGraphics.pose();
poseStack.pushPose();
poseStack.translate(Minecraft.getInstance().getWindow().getGuiScaledWidth() / 2.0,
Minecraft.getInstance().getWindow().getGuiScaledHeight() / 2.0, 0);
poseStack.translate(screenHalfWidth, screenHalfHeight, 0);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
// Render player state text
poseStack.pushPose();
poseStack.scale(5, 5, 5);
poseStack.scale(3, 3, 3);
// Check if we should draw the state
if (Proxy.Client.getPlayerState() != null && !Proxy.Client.getPlayerState().equals(ProtectedPlayer.State.ACTIVE)) {
// Initialize variables
Font font = Minecraft.getInstance().font;
float offsetX = -(font.width(Proxy.Client.getPlayerState().toString()) / 2f);
float offsetY = -((font.lineHeight / 2f) + ((Minecraft.getInstance().getWindow().getGuiScaledHeight() / 4f) / 5));
int textHalfWidth = font.width(Proxy.Client.getPlayerState().toString()) / 2;
int textHalfHeight = font.lineHeight / 2;
float positionScale = 1.5f;
int offsetX = -textHalfWidth;
int offsetY = (int)-((textHalfHeight + screenHalfHeight) / positionScale);
int argb = 0xFFFFFFFF;
// Draw the player's protection state
guiGraphics.drawString(font, Proxy.Client.getPlayerState().toString().replace("_", " "), (int)offsetX, (int)offsetY, argb);
guiGraphics.drawString(font, Proxy.Client.getPlayerState().toString().replace("_", " "), offsetX, offsetY, argb);
}
poseStack.popPose();