Jump to content

[1.19.3] Inconsistent GUI behaviour between Forge SDK client and regular forge client with .jar packed mod.


Recommended Posts

So, I'm preparing a little HUD for an event I'm going to do with some friends. It all works fine in the client executed when running ./gradlew runClient. It's the expected result: wvfnors.png

But the problem comes when I either open the Forge SDK world to LAN OR load the mod to a separate Forge server instance, both needing the packed .jar made via ./gradlew build:


As you can see, it drags the whole pause GUI with it. Of the four text lines, only one is seen. I use both scale and translate methods, and this exact thing happened on the SDK client too, but I fixed it using pushpose and poppose methods initially. The timer updates via network packets and works fine, as I said, on the Forge SDK instance of the client. The packets also work fine on their own, I only changed it so it would update the text in the GUI instead of outputting directly to the game chat. Here is the code of the GUI I made:

public class PVPStateOverlay{
    //if you need custom textures they should be placed unde resources/assets/yourmodid/textures/gui (gui interchangable with other folders)
    //Refer to ClientEvents.java for the gui registration
    private static final ResourceLocation TEXTURE = new ResourceLocation(MOD_ID, "textures/mainvisor/fhcmclogo.png");
    public static final IGuiOverlay HUD_MAINOVERLAY = ((gui, poseStack, partialTick, width, height) -> {
        int x = width / 2;
        int y = height;
        int logoxoffset = 145;
        int logoyoffset = -225;
        int rextanglexstart= -35;
        int rextangleystart = 13;
        int rextanglexend= 60;
        int rextangleyend = 70;
        int textxoffset = 12;
        int textyoffset = 20;

        //Push the matrix to the stack, so that the scale and translation don't affect other elements
        //At the end, pop the matrix from the stack so that subsequent renders aren't affected!

        final double scaled = (1.f / gui.getMinecraft().getWindow().getGuiScale()) * 3;
        final float scale = (float) scaled;
        poseStack.scale(scale, scale, scale);
        poseStack.translate(175F, 75F, 0F);

        // Draw semi-transparent grey rectangle
        RenderSystem.setShaderColor(0.5F, 0.5F, 0.5F, 0.5F);
        GuiComponent.fill(poseStack,x + logoxoffset + rextanglexstart, y + logoyoffset + rextangleystart, x + logoxoffset + rextanglexend, y + logoyoffset + rextangleyend,0xFFFFFFFF);//Pos and then scale

        // Draw "Time remaining" text
        Minecraft minecraft = Minecraft.getInstance();
        Font font = minecraft.font;
        String timeRemaining = "Tiempo restante:";
        int textWidth = font.width(timeRemaining);
        int textX = (x + logoxoffset + textxoffset - textWidth / 2);
        int textY =(y + logoyoffset + textyoffset);
        GuiComponent.drawString(poseStack, font, timeRemaining, textX, textY, 0xFFFFFFFF);

        // Draw "HH:MM:SS" text

        PlayerTimeTracker trckr = PlayerTimeManager.getTracker(gui.getMinecraft().player.getUUID());
        LocalTime remainingTimeLT = LocalTime.ofSecondOfDay(PlayerTimeManager.getDailyTimeLimit() - trckr.getSecsPlayed());
        String remainingTime = remainingTimeLT.format(DateTimeFormatter.ofPattern("HH:mm:ss")).toString();
        textWidth = font.width(remainingTime);
        textX = x + logoxoffset + textxoffset - textWidth / 2;
        textY += font.lineHeight + 2; // add some space between the two lines of text
        font.draw(poseStack, remainingTime, textX, textY, 0xFFFFFFFF);

        // Draw PVP State text
        String pvpstate = "PVP:"; // replace with your logic to get the remaining time
        textWidth = font.width(pvpstate);
        textX = x + logoxoffset + textxoffset - textWidth / 2;
        textY += font.lineHeight + 8; // add some space between the two lines of text
        GuiComponent.drawString(poseStack, font, pvpstate, textX, textY, 0xFFFFFFFF);

        // Draw "OFF/ON/HARDCORE" text
        String statePVP = "ULTRA"; // replace with your logic to get the remaining time
        textWidth = font.width(statePVP);
        textX = x + logoxoffset + textxoffset - textWidth / 2;
        textY += font.lineHeight + 2; // add some space between the two lines of text
        font.draw(poseStack, statePVP, textX, textY, 0xFFFFFFFF);

        //Render the logo
        RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
        RenderSystem.setShaderTexture(0, TEXTURE);
        GuiComponent.blit(poseStack, x + logoxoffset, y + logoyoffset, 0, 0, 25, 25, 25, 25);



And it is registered on a separate class:

        public static void registerGuiOverlays(RegisterGuiOverlaysEvent event) {
            event.registerAboveAll("mainoverlayid", PVPStateOverlay.HUD_MAINOVERLAY);

Any insights? I'm really scratching my head right now

Edited by chxr
Typos and clarifications
Link to comment
Share on other sites

39 minutes ago, Hipposgrumm said:

Why is your mod changing vanilla classes to do this? It shouldn't need to.

I'm going blind with GUI stuff so I've just followed a tutorial that has yielded results. so no actual reason. If you can point me to a more correct direction then I'm all ears, too!

Link to comment
Share on other sites

Yeah, I had already scouted through it before (though I didn't see that clearly what I could use, so I'll check on your tip later). My main problem (the reason why I'm scaling the GUI in the first place) is that I can't find a way to scale the text itself, that's why I resorted to scale the whole thin

Also, why is the client behaving differently on the SDK vs the regular client? (This is more out of curiosity really, i don't know if the reason is in my code or somewhere else)


Link to comment
Share on other sites

  • chxr changed the title to [1.19.3] Inconsistent GUI behaviour between Forge SDK client and regular forge client with .jar packed mod.
  • 2 weeks later...

For anyone wondering -  it was the networking fault. As i was rendering all the GUI on the same block of code, the render failed when getting the information from the packets and stopped, and since it didn't reach the popStack at the end of the code block, the rest of the GUI just stayed with the same modified scale.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.