Jump to content

[1.8] [SOLVED] Draw the icon of an item and text on the screen


Recommended Posts

Hey guys,

I'm working at my first ever forge mod at the moment (http://spng.pw/t/5496), and I want to draw a notification box onto the screen, just like this little achievement box in the top right corner.


What I did so far: Drawing something onto the screen (the achievement box itself) with a class extending net.minecraft.client.gui.Gui with SubscribeEvent to a RenderGameOverlayEvent.


What I want to do now: Draw the icon of a music disc on top of the box.


What I have tried:


Approach 1:

this.mc.renderEngine.bindTexture(new ResourceLocation("textures/items/record_cat.png"));
this.drawTexturedModalRect(posX + 8, posY + 8, 0, 0, 256, 256);

This draws a 256x256 pixels huge music disc onto my screen. Not really what I want...


Approach 2:

new RenderItem(this.mc.getTextureManager(), new ModelManager(theProblem)).renderItemIntoGUI(new ItemStack(Item.getByNameOrId("sign"), 1), posX + 8, posY + ;

The problem: where can I get the TextureMap for the ModelManager constructor from? I only found out that I can get it from ModelManager, and to get one of those I need a TextureMap?! :D


What I want to do after that: Draw some text onto the box.

this.mc.fontRendererObj.drawStringWithShadow("Text, where are you?!", posX + 32, posX + 8, 0xffffffff);

Does not do anything at all, unfortunately... :D


Am I doing everything completely wrong or is there a light at the end of my code? ;)


Thanks in advance



P.S.: My whole class:


package de.momar.minecraft.m4m;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.lwjgl.opengl.GL11;

public class NotificationDrawer extends Gui {

    private Minecraft mc;
    private int posX, posY, mulY;

    public NotificationDrawer(Minecraft mc, Configuration config) {
        this.mc = mc;

        //Save the top left corner of the fully visible notification to posX, posY and mulY.
        ScaledResolution sr = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
        posX = sr.getScaledWidth() - 160;
        posY = sr.getScaledHeight() - 32;
        mulY = -1;
        String[] position = config.get(Configuration.CATEGORY_GENERAL, "position", "top-left").getString().split("-");
        if (position[0] == "top") { posY = 0; mulY = 1; }
        if (position[1] == "left") posX = 0;

    @SubscribeEvent(priority = EventPriority.NORMAL)
    public void onRender(RenderGameOverlayEvent event) {
        //Render above the chat
        if(event.isCancelable() || event.type != RenderGameOverlayEvent.ElementType.ALL) return;
        //Render only if there's a new notification
        if (step == -1) return;

        //Prepare rendering
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

        this.mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/achievement/achievement_background.png"));
        this.drawTexturedModalRect(posX, posY, 96, 202, 160, 32);


        this.mc.renderEngine.bindTexture(new ResourceLocation(icon));
        //this.drawTexturedModalRect(posX + 8, posY + 8, 0, 0, 256, 256);
        new RenderItem(this.mc.getTextureManager(), new ModelManager()).renderItemIntoGUI(new ItemStack(Item.getByNameOrId("sign"), 1), posX + 8, posY + ;

        //                                           text   x              y         color
        this.mc.fontRendererObj.drawStringWithShadow(title, posX + 32,     posX + 8, 0xffffffff);
        this.mc.fontRendererObj.drawStringWithShadow(text,  posX + 32 + 8, posX + 8, 0xffcccccc);

    private String icon = "textures/blocks/bed_feet_top.png", title = "ERROR", text = "There was an error with the notification!";
    private int step = 0;
    public void notification(String icon, String title, String text) {
        this.icon = icon;
        this.title = title;
        this.text = text;
        this.step = 1;


Link to comment
Share on other sites

The texture is 16x16, but if I use 16 in the method call, I get the top left pixel of the icon... Or, in the case of records, it doesn't do anything at all because that pixel is transparent... :D

Seems like the UV map size is 256x256 for every texture...


This is what I tried with glScaled:

GL11.glScaled(16 / 256, 16 / 256, 16 / 256);

It does not show the icon or anything after the statement at all, and instead makes event the GUI overlay (Escape menu, death screen, chat input line, ...) completely invisible, even if I run glScaled again with 256/16...

Link to comment
Share on other sites

So, I now just took the code from ZyinHUD (https://github.com/Zyin055/zyinhud/blob/master/src/main/java/com/zyin/zyinhud/ZyinHUDRenderer.java), and it finally works like a charm! :D


IBakedModel iBakedModel = mc.getRenderItem().getItemModelMesher().getItemModel(new ItemStack(item));
TextureAtlasSprite textureAtlasSprite = mc.getTextureMapBlocks().getAtlasSprite(iBakedModel.getTexture().getIconName());
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
worldrenderer.addVertexWithUV((double)(x),          (double)(y + height),  0.0, (double)textureAtlasSprite.getMinU(), (double)textureAtlasSprite.getMaxV());
worldrenderer.addVertexWithUV((double)(x + width),  (double)(y + height),  0.0, (double)textureAtlasSprite.getMaxU(), (double)textureAtlasSprite.getMaxV());
worldrenderer.addVertexWithUV((double)(x + width),  (double)(y),           0.0, (double)textureAtlasSprite.getMaxU(), (double)textureAtlasSprite.getMinV());
worldrenderer.addVertexWithUV((double)(x),          (double)(y),           0.0, (double)textureAtlasSprite.getMinU(), (double)textureAtlasSprite.getMinV());


The second problem solved itself: I stupid human did use posX instead of posY... :o


Yeah, my first Forge mod is finally one small step furter :D

Thanks for your help


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.

  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • when i join it looks normal until i look a mob or i have some thing in my hand and my screen starts turning different colors when i look around. i can see my inventory and the menu but not mobs or blocks in my hand I've tried to turn off the anti virus  uninstall and reinstalling the best driver  going back from version 20 to 8 and putting a ton of ram into minecraft. if i could get any help. thank you
    • Hi fellow minecrafter,   We've got exciting news from the Pacific Laboratory for Artificial Intelligence (PLAI) at UBC! We're merging the worlds of Minecraft and AI research, and you're invited to join through our platform, plaicraft.ai, to aid our data collection process. It's not just playing games; it's contributing to cutting-edge AI research.   BetterStructures and more!!: We want to make the server as fun as possible for everyone so we recently added a bunch of structural plugins that adds over a hundred of new structures and sites for you to explore and challenge. We are also working on PVP, bedwars and skyblock content, which will make the server even more fun!   Here’s how you can get involved! -Register on plaicraft.ai with your email(you can fake one, as long as you can receive email from it it's fine). -Complete a consent form. -Play Minecraft and contribute to science! (all you need is a Chrome browser and a steady internet, you'll be playing on VM)   Why You Should Participate? -Support AI Research: Your gameplay directly contributes to important AI advancements.  -Free Minecraft Access: Enjoy the game without any cost. -We have shaders and a bunch of cool mods loaded on our instances  -Great Community: Our server currently has a fantastic community, with many awesome players you can meet.   Elephant in the room: Now I want to address some obvious concerns, I sure did a good job making us sound like a scam by the above content. I know that the "free Minecraft" thing has always been taboo in the Minecraft community. So how can I prove to you that this is not a scam? - The easiest way and most official way is that we are approved by the University of British Columbia ethics board, our BREB number is H23-02389. You can verify this case number yourself. - The harder way is that I'll explain the technical details of this project and why we choose to provide free Minecraft. So the goal of this project is very similar to the paper MineDojo or MineRL, we want to collect a multi-modal dataset that consists of video, audio, keyboard and mouse movement. Minecraft has been a very important simulation environment for the ML community and there are tons of papers related to it. Now we obviously don't have enough money like those big tech companies who can just pay people to play, so we have to turn to the Minecraft community. To record all the data mentioned, there needs to be a lot of setup and coding, and it's definitely impossible for us to ask people to run these recording programs on their personal computers. So we carefully configured the AWS EC2 instance to run Minecraft alongside the programs. And that's where and why we also provide you with free Minecraft licenses, of course, we are not giving the account to you, just allowing you to be able to play Minecraft on these instances. You might ask, "Why can't I log in with my account on the instances?", that's because first login with your personal Minecraft account is another privacy risk; second not all our target audiences have an account; and lastly we restricted a lot on what you can do on the instance, basically all you can do is play Minecraft and that's all the data we want, allowing you to log in will make things complicated to control.   For more information on the project and the team, visit Dr. Frank Wood’s website or follow @frankdonaldwood on Twitter. You can also learn more about PLAI lab research on our website (just search ubc plai). Join us in transforming your gaming experience into a meaningful contribution to AI research. Let’s push the boundaries of what gaming can achieve together! Happy plaiing!   Best,  The PLAI Team
    • The mod has improved a lot from yesterday just 1 last issue  Here's the crash report- https://pastebin.com/k2A1BAKn   Please help, Thanks.
    • Take Your Gaming Experience to the Next Level with These Essential Tools   If you're a Minecraft enthusiast, you've likely experienced the need to customize your world and server to make it more exciting and challenging. Fortunately, there's a perfect solution for you: https://menzatyx.xyz, the website that offers a wide selection of free and pre-configured Minecraft plugins. At https://menzatyx.xyz, you'll find a diverse range of plugins that will allow you to take your gaming experience to the next level. From server management tools to mods that add new functionalities, each of these plugins has been carefully selected and configured, so you can enjoy a more personalized and thrilling Minecraft experience. One of the primary benefits of using these pre-configured plugins is the ease of implementation. You no longer have to spend hours configuring and adjusting each individual plugin. Simply download the package that best suits your needs, and you're good to go! You'll be able to enjoy all the features and improvements without investing too much time and effort. From plugins that enhance the security of your server to mods that add new game modes, the variety offered by https://menzatyx.xyz is impressive. Moreover, as these are free plugins, you can access these tools without spending a single penny. It's the perfect opportunity to take your Minecraft experience to the next level without affecting your wallet! Whether you're a casual player or an experienced server administrator, at https://menzatyx.xyz you'll find the Minecraft plugins you need to personalize and enhance your game. Visit the website now and discover how you can transform your Minecraft world into something unique and thrilling!
    • Meaning I need to restart the server and redownload cobblemon?
  • Topics

  • Create New...

Important Information

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