chxr Posted February 19, 2023 Posted February 19, 2023 (edited) 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: 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) //https://www.youtube.com/watch?v=J3a7JT0rxTM //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! poseStack.pushPose(); poseStack.pushPose(); 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.setShader(GameRenderer::getPositionColorShader); 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.setShader(GameRenderer::getPositionTexShader); 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); poseStack.popPose(); poseStack.popPose(); }); } And it is registered on a separate class: @SubscribeEvent public static void registerGuiOverlays(RegisterGuiOverlaysEvent event) { event.registerAboveAll("mainoverlayid", PVPStateOverlay.HUD_MAINOVERLAY); } Any insights? I'm really scratching my head right now Edited February 21, 2023 by chxr Typos and clarifications Quote
Hipposgrumm Posted February 19, 2023 Posted February 19, 2023 Why is your mod changing vanilla classes to do this? It shouldn't need to. Quote I'm not good at modding, but at least I can read a crash report (well enough). That's something, right?
chxr Posted February 19, 2023 Author Posted February 19, 2023 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! Quote
Hipposgrumm Posted February 20, 2023 Posted February 20, 2023 I would try copying the vanilla hotbar gui code and modifying it to look how you want it. Quote I'm not good at modding, but at least I can read a crash report (well enough). That's something, right?
chxr Posted February 20, 2023 Author Posted February 20, 2023 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) Quote
chxr Posted March 6, 2023 Author Posted March 6, 2023 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. Quote
Recommended Posts
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.