Jump to content

Drawing simple text to screen?


SirLollington

Recommended Posts

So, I've been trying to figure this out for the past few hours, but the documentation is extremely sparse and I haven't been able to figure this out.

I want to write some text to the screen, kind of like an FPS meter. Unfortunately for me, my mod currently doesn't display anything at all. There aren't any errors, and from what I have been able to find, the way I'm going about this is correct. 

I'm using Minecraft 1.11.2.

 

Here's the code in question:

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@Mod.EventBusSubscriber
public class MessageGui extends Gui {
	private static String text = "Test Text";
	private static int color = 0xFFFFFF;
	private FontRenderer fontRenderer;
	
	private void verifyRenderer() {
		if (fontRenderer != null) return;
		Minecraft minecraft = Minecraft.getMinecraft();
		fontRenderer = minecraft.fontRendererObj;
	}
	
	@SubscribeEvent
	public void render(RenderGameOverlayEvent.Post event) {
		verifyRenderer();
		fontRenderer.drawStringWithShadow(text, 10, 20, color);
	}
}

 

As far as I've been told, @Mod.EventBusSubscriber and @SubscribeEvent should automatically subscribe the RenderGameOverlayEvent to the correct bus... but it's not doing anything at all. Can someone tell me what I'm missing here? 

 

EDIT: I AM creating an instance of this class in my mod's init() function. There shouldn't be a reason for this not to work.

Edited by SirLollington
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.

Guest
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.