Question

I tried to make a ingame GUI in minecraft with this function. (I'm using forge with MC 1.5.2).

Minecraft.getMinecraft().fontRenderer.drawString(String)

Here's my code:

@ForgeSubscribe
public void onServerChat(ServerChatEvent event)
{
    mcObject.fontRenderer.drawStringWithShadow("Hello WOrld", 4, 4, 0xffFFFFFF);
    mcObject.ingameGUI.drawRect(2 /*X*/, 2 /*Y*/, 100 /*X1*/, 12 /*Y1*/, 0x80000000 /*COLOUR*/);
}

But when I type a chat message (just using that event for testing) the text disappears instantly and you can barely see it and certainly not read it.

I'm quite new to forge modding.

How to make a text more permanent and how you remove it again (or overwrite)?

Was it helpful?

Solution

onServerChat is an instantaneous event: it fires when the chat receives a message and immediately stops.

You will need to draw your GUI in an event that updates every frame. I have been doing it OnRenderExperienceBar, an element of Minecraft's default GUI. Here's an example using your code.

@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.NORMAL)
public void onRenderExperienceBar(RenderGameOverlayEvent event) {

mcObject.fontRenderer.drawStringWithShadow("Hello World", 4, 4, 0xffFFFFFF);
mcObject.ingameGUI.drawRect(2 /*X*/, 2 /*Y*/, 100 /*X1*/, 12 /*Y1*/, 0x80000000 /*COLOUR*/);

}

OTHER TIPS

I do not have experience with Minecraft code, but I'd speculate that whatever you're trying to draw is only drawn for a single frame. This would be consistent with the "instantly disappearing" behaviour you're seeing. If this is the case, you can invoke the methods on every frame until you want to stop drawing.

I've got an answer, I looked at the Minecraft crafting gui code, and found this, it might help you:

this.fontRenderer.drawString("Crafting", 28, 6, 4210752); 
// Args that I think: text, X, Y, color 

and you need to import org.lwjgl.opengl.GL11;

Just so you know, this was from MCP in the normal Minecraft but it should work

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top