momar Posted January 6, 2015 Posted January 6, 2015 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?! 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... Am I doing everything completely wrong or is there a light at the end of my code? Thanks in advance momar 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) { super(); 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); GL11.glDisable(GL11.GL_LIGHTING); 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; } } Quote
brandon3055 Posted January 6, 2015 Posted January 6, 2015 Your first approach may work. Unless there is something different about the record textures the texture should be 16x16 so why are you trying to draw it as 255x255? You can also rescale it using GL11.glScale Quote I am the author of Draconic Evolution
momar Posted January 7, 2015 Author Posted January 7, 2015 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... 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... Quote
momar Posted January 7, 2015 Author Posted January 7, 2015 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! IBakedModel iBakedModel = mc.getRenderItem().getItemModelMesher().getItemModel(new ItemStack(item)); TextureAtlasSprite textureAtlasSprite = mc.getTextureMapBlocks().getAtlasSprite(iBakedModel.getTexture().getIconName()); mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture); Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldrenderer = tessellator.getWorldRenderer(); worldrenderer.startDrawingQuads(); 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()); tessellator.draw(); The second problem solved itself: I stupid human did use posX instead of posY... Yeah, my first Forge mod is finally one small step furter Thanks for your help momar 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.