tlr38usd Posted July 22, 2013 Posted July 22, 2013 I have made a potion for my mod and I have also made its effect, the only problem is I don't know how to make it render a custom icon when it is applied to the player. I have found a way to do it in normal minecraft when a gui is not open with the RenderGameOverlayEvent. How would I make it so that when the players inventory is open my effect renderer (which only has a different texture btw) will render over the existing mine craft potion buff renderer. Or even better is there a way I can simply change the mine craft inventory texture without a resource pack. Quote
hydroflame Posted July 22, 2013 Posted July 22, 2013 Or even better is there a way I can simply change the mine craft inventory texture without a resource pack. yeah technicly you could set to a different render target before drawing the gui and render your texture/image/wtv there too or if thats chinese / too complicated you can also (and its a better option) make a TickHandler client side and render there Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
tlr38usd Posted July 22, 2013 Author Posted July 22, 2013 make a TickHandler client side and render there I tried something like that, but the only problem is I don't know how to make something render outside of a render class. Quote
hydroflame Posted July 22, 2013 Posted July 22, 2013 you do the exact same thign, there no magic there back in the days, before RnederGameOverlayEvent was created, i was rendering my mana bar in a TickHandler when the RenderGameOverlayEvent arrived, i copy pasted my code in a @ForgeSubscribe event method Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
WorldsEnder Posted July 22, 2013 Posted July 22, 2013 I got some code for you: import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.event.ForgeSubscribe; //maybe some imports are missing... I hope not, respond if I'm wrong or fix it yourself public class YourRenderer() { public YourRenderer() { //Whatever you need else MinecraftForge.EVENT_BUS.register(this); //You can/should/may do this after you created an instance of the class anywhere you //like } @ForgeSubscribe public void onRenderEvent(RenderGameOverlayEvent.Post postRender) //You wanted to render afterwards { if(postRender.type!=ElementType.ALL) return; //This renders it really last. You can select another ElementType if you like. //your render code } } Quote
tlr38usd Posted July 22, 2013 Author Posted July 22, 2013 you do the exact same thign, there no magic there back in the days, before RnederGameOverlayEvent was created, i was rendering my mana bar in a TickHandler when the RenderGameOverlayEvent arrived, i copy pasted my code in a @ForgeSubscribe event method Okay, that kind of works, but I use methods like drawTexturedModalRect that only work if the class it is inside extends Gui. Quote
hydroflame Posted July 22, 2013 Posted July 22, 2013 then do it by hand <superhero voice> [shadow=red,left]TESSELLATOR TO THE RESCUE !!! TO SAVE THE DAY !!!![/shadow] </superhero voice> code example because youll end up asking for it anyway Tessellator tess = Tessellator.instance; Minecraft.getMinecraft().renderEngine.bindTexture("path/to/texture");// or bind ressource if in 1.6+ tess.startDrawingQuads(); tess.setColorOpaque_F(1, 1, 1); tess.addVertexWithUV(startX, startY, 0, 0, 0); tess.addVertexWithUV(startX, startY+height, 0, 0, 1); tess.addVertexWithUV(startX+width, startY+height, 0, 1, 1); tess.addVertexWithUV(startX+xSize, startY, 0, 1, 0); tess.draw(); Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
shadowmage4513 Posted July 22, 2013 Posted July 22, 2013 you can still use the methods from your gui-extending class even when MC isn't 'displaying' that GUI -- this is how I render health bars for my vehicles in an overlay. in your client tick handler, have a reference to your gui-extending object, and onTick() just call the render methods for (from/within) your GUI. Quote
WorldsEnder Posted July 22, 2013 Posted July 22, 2013 Tick Handler maybe great for some purposes but in my opinion @ForgeSubcribe-method is better as you can hook in everywhere you want (for example after the healthbar or before the hungerbar w s e). Just sayin Quote
tlr38usd Posted July 22, 2013 Author Posted July 22, 2013 Okay, put it in a client tick handler and it works. Kind of. It keeps randomly blinking and I'm not sure how to fix that. Quote
hydroflame Posted July 22, 2013 Posted July 22, 2013 same thing happened to me, print your code i dont remember the answer Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
tlr38usd Posted July 22, 2013 Author Posted July 22, 2013 My client tick handler. Do you need anything else? package TuxWeapons.TuxCraft; import java.util.Collection; import java.util.EnumSet; import java.util.Iterator; import org.lwjgl.opengl.GL11; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ResourceLocation; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class ClientTickHandler implements ITickHandler { private ResourceLocation location = new ResourceLocation( TuxWeaponsCore.modidLowerCase, "textures/gui/statusEffects.png"); Minecraft mc = Minecraft.getMinecraft(); @Override public void tickStart(EnumSet<TickType> type, Object... tickData) { //onClientTick(); } @Override public void tickEnd(EnumSet<TickType> type, Object... tickData) { onClientTick(); } private void onClientTick() { ScaledResolution scaledresolution = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight); int width = scaledresolution.getScaledWidth(); int height = scaledresolution.getScaledHeight(); int i = ((width - 176) / 2) - 64; int j = (height - 166) / 2; boolean flag = true; Collection collection = this.mc.thePlayer.getActivePotionEffects(); if (!collection.isEmpty()) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_LIGHTING); int k = 33; if (collection.size() > 5) { k = 132 / (collection.size() - 1); } for (Iterator iterator = this.mc.thePlayer.getActivePotionEffects().iterator(); iterator.hasNext(); j += k) { PotionEffect potioneffect = (PotionEffect)iterator.next(); Potion potion = Potion.potionTypes[potioneffect.getPotionID()]; GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.func_110434_K().func_110577_a(location); this.drawTexturedModalRect(i, j, 0, 166, 140, 32); if (potion.hasStatusIcon()) { int l = potion.getStatusIconIndex(); this.drawTexturedModalRect(i + 6, j + 7, 0 + l % 8 * 18, 198 + l / 8 * 18, 18, 18); } String s = I18n.func_135053_a(potion.getName()); if (potioneffect.getAmplifier() == 1) { s = s + " II"; } else if (potioneffect.getAmplifier() == 2) { s = s + " III"; } else if (potioneffect.getAmplifier() == 3) { s = s + " IV"; } mc.fontRenderer.drawStringWithShadow(s, i + 10 + 18, j + 6, 16777215); String s1 = Potion.getDurationString(potioneffect); mc.fontRenderer.drawStringWithShadow(s1, i + 10 + 18, j + 6 + 10, 8355711); } } } public void drawTexturedModalRect(int par1, int par2, int par3, int par4, int par5, int par6) { float zLevel = 200.0F; float f = 0.00390625F; float f1 = 0.00390625F; Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.addVertexWithUV((double)(par1 + 0), (double)(par2 + par6), (double)zLevel, (double)((float)(par3 + 0) * f), (double)((float)(par4 + par6) * f1)); tessellator.addVertexWithUV((double)(par1 + par5), (double)(par2 + par6), (double)zLevel, (double)((float)(par3 + par5) * f), (double)((float)(par4 + par6) * f1)); tessellator.addVertexWithUV((double)(par1 + par5), (double)(par2 + 0), (double)zLevel, (double)((float)(par3 + par5) * f), (double)((float)(par4 + 0) * f1)); tessellator.addVertexWithUV((double)(par1 + 0), (double)(par2 + 0), (double)zLevel, (double)((float)(par3 + 0) * f), (double)((float)(par4 + 0) * f1)); tessellator.draw(); } @Override public EnumSet<TickType> ticks() { return EnumSet.of(TickType.PLAYER); } @Override public String getLabel() { return null; } } Quote
WorldsEnder Posted July 22, 2013 Posted July 22, 2013 I would suppose not to use TickType.PLAYER but TickType.RENDER. Everything should work smoother Quote
hydroflame Posted July 22, 2013 Posted July 22, 2013 oh its not the same problem, mine was because i was rendering on tickEnd, you should maybe leave that method empty as your computer will work twice as hard for the same resutl Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
tlr38usd Posted July 22, 2013 Author Posted July 22, 2013 I would suppose not to use TickType.PLAYER but TickType.RENDER. Everything should work smoother That fixed it thanks! Although, however, now the text decided to not render Quote
hydroflame Posted July 22, 2013 Posted July 22, 2013 are you rendering the text AFTER the rest ? basicly if you render it first, the rest will show up in fron of it and you wont see it Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
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.