package dev.micle.loginprotection.mixin; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import dev.micle.loginprotection.data.ProtectedPlayer; import dev.micle.loginprotection.proxy.Proxy; import dev.micle.loginprotection.setup.Config; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.gui.overlay.ForgeGui; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ForgeGui.class) @OnlyIn(Dist.CLIENT) public class GuiRenderTickMixin { @Inject(method = "render", at = @At(value = "HEAD")) private void onClientTick(GuiGraphics guiGraphics, float partialTick, CallbackInfo ci) { // Check if enabled if (!Config.Client.GUI_SCREEN_TEXT_ENABLED.get()) { 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(screenHalfWidth, screenHalfHeight, 0); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); // Render player state text poseStack.pushPose(); 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; 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("_", " "), offsetX, offsetY, argb); } poseStack.popPose(); // Finish RenderSystem.disableBlend(); poseStack.popPose(); } }