From 55b8dcef55f57fe612e480ef131af2052c06f02e Mon Sep 17 00:00:00 2001 From: Micle Date: Wed, 15 May 2024 18:52:08 +0100 Subject: [PATCH] Moved some magical numbers into variables. --- .../mixin/GuiRenderTickMixin.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/dev/micle/loginprotection/mixin/GuiRenderTickMixin.java b/src/main/java/dev/micle/loginprotection/mixin/GuiRenderTickMixin.java index fb5f396..327e44b 100644 --- a/src/main/java/dev/micle/loginprotection/mixin/GuiRenderTickMixin.java +++ b/src/main/java/dev/micle/loginprotection/mixin/GuiRenderTickMixin.java @@ -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();