Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.2] Drawing text


Endyl
 Share

Recommended Posts

I've searched far and wide to find a way to draw text to the screen and I have found the following so far, that is unfortunately not working correctly:

 

I have a TickEventHandler.java, that is registered through FMLCommonHandler.instance().bus().

My event handler gets called (if I write to the console from there, the console gets flooded), but the text is nowhere to be seen.

 

My question is: how can I draw text to the screen, preferably showing only when in a game (not in menu screens) like the data shown when F3 is pressed?

 

Thanks!

Link to comment
Share on other sites

  • 2 months later...

package something;

import net.minecraft.client.gui.Gui;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class MyClass extends Gui
{

    @SubscribeEvent(priority = EventPriority.NORMAL)
    public void hej(RenderGameOverlayEvent event)
    {

        if (event.isCancelable() || event.type != ElementType.EXPERIENCE)
        {
            return;
        }
        
        drawString(FMLClientHandler.instance().getClient().fontRenderer, "heeeejjjjj", 40, 40, 0xffffff);
    }
}

 

Mainmod:

 

        MinecraftForge.EVENT_BUS.register(new MyClass());

Link to comment
Share on other sites

I have a cheaty way of doing this. Not most simple, but works.

 

Registration:

MinecraftForge.EVENT_BUS.register(new IngameText(Minecraft.getMinecraft()));

 

IngameText class:

//you can add package and imports
public class IngameText extends Gui {
     private Minecraft mc;

     public IngameText(Minecraft mc) {
           super();
           this.mc = mc;
     }

     @SubscribeEvent
     public void renderScreen(RenderGameOverlayEvent.Post event) {
           if (event.isCancelable() || event.type != ElementType.TEXT) {
                return;          
          }
          render(mc);
     }

     public void render(Minecraft minecraft) {
          minecraft.fontRenderer.drawString(//add your fields);
     }
}

 

Like I said, this is like the worst way to do it, but it works :D

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.