Created initial mixin for drawing the state text on screen.

This commit is contained in:
2022-05-24 02:16:35 +01:00
parent 962749cfae
commit a204f7ac56

View File

@ -0,0 +1,45 @@
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 net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.gui.ForgeIngameGui;
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(ForgeIngameGui.class)
@OnlyIn(Dist.CLIENT)
public class GuiRenderTickMixin {
@Inject(method = "render", at = @At(value = "HEAD"))
private void onClientTick(PoseStack poseStack, float partialTicks, CallbackInfo callbackInfo) {
// Setup
poseStack.pushPose();
poseStack.translate(Minecraft.getInstance().getWindow().getGuiScaledWidth() / 2.0,
Minecraft.getInstance().getWindow().getGuiScaledHeight() / 2.0, 0);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
// Render state
poseStack.pushPose();
poseStack.scale(5, 5, 5);
Font font = Minecraft.getInstance().font;
int titleWidth = font.width(Proxy.Client.getPlayerState().toString());
float offset = -titleWidth / 2f;
int alpha = 255 << 24 & 0xFF000000;
if (!Proxy.Client.getPlayerState().equals(ProtectedPlayer.State.ACTIVE)) {
font.draw(poseStack, Proxy.Client.getPlayerState().toString(), offset, -50, 0xFFFFFF | alpha);
}
poseStack.popPose();
RenderSystem.disableBlend();
poseStack.popPose();
}
}