Posted August 7, 20196 yr I have a mod called immortality that add a potion that keeps the player's health from dropping below 20%. The mod itself works just fine, but I want to add an overlay effect to the health bar to show the player how low their health can go, specifically by covering 20% of the health bar (usually 2 hearts) in custom hearts, kinda like how poison turns your hearts green. I have some rendering code, but its not rendering anything. Here's the event handler Im using, I've confirmed it works: private static Minecraft mc = Minecraft.getMinecraft(); private static final ImmortalityBarRenderer renderer = new ImmortalityBarRenderer(mc); @SubscribeEvent//render immortal hearts over player hearts public void onDrawBar(RenderGameOverlayEvent.Post event) { EntityPlayerSP entityPlayerSP = Minecraft.getMinecraft().player; if (entityPlayerSP == null) return; if(event.getType() == ElementType.HEALTH) { renderer.renderStatusBar(event.getResolution().getScaledWidth(), event.getResolution().getScaledHeight()); } } And here is my renderer class, I have confirmed that renderStatusBar is getting called, which means its something in my render code: public class ImmortalityBarRenderer extends Gui { private static final ResourceLocation overlay = new ResourceLocation(Immortality.MODID +":textures/gui/immortal_heart.png"); private Minecraft mc; public ImmortalityBarRenderer(Minecraft mc) { this.mc = mc; } public void renderStatusBar(int screenWidth, int screenHeight) { World world = mc.world; EntityPlayer player = mc.player; final int barHeight = 9; final int barWidth = (int) (9*((Math.ceil(player.getMaxHealth()/5))/2)); final int expBarSpace = 3; //push matrix GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); GL11.glPushMatrix(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(overlay); final int vanillaExpLeftX = screenWidth / 2 - 91; // leftmost edge of the experience bar final int vanillaExpTopY = screenHeight - 32 + 3; // top of the experience bar GL11.glTranslatef(vanillaExpLeftX, vanillaExpTopY - expBarSpace - barHeight, 0); drawTexturedModalRect(0, 0, 0, 0, barWidth, barHeight); GL11.glPopAttrib(); GL11.glPopMatrix(); } } I know next to nothing about rendering on the HUD, I've just been replicating examples I've seen. If I've done something obviously wrong, please point it out so I don't do it again.
August 8, 20196 yr 4 hours ago, theishiopian said: I have some rendering code, but its not rendering anything. Have you confirmed that your render code is executing? Is the event being called? Is the event ever have the exact fields (Does the Post event ever fire with ElementType.HEALTH)? VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 8, 20196 yr Author As I said in my post, I have confirmed the event is firing, and that the render code is being called.
August 8, 20196 yr 34 minutes ago, theishiopian said: As I said in my post, I have confirmed the event is firing, and that the render code is being called. My bad. Try removing your translate call. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 8, 20196 yr 10 hours ago, theishiopian said: mc.renderEngine.bindTexture(overlay); Instead do mc.getTextureManager().bindTexture(...) VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 8, 20196 yr Author That makes sense, always better to use a getter instead of the field. Regardless, it did not fix the issue.
August 8, 20196 yr Just now, theishiopian said: That makes sense, always better to use a getter instead of the field. Regardless, it did not fix the issue. Switch your barWidth to a constant. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 8, 20196 yr Author That did not help either. As a side note, I need to be able to vary the amount of hearts the bar covers since the effect is based on a percentage of your health, is there a better way to do that?
August 8, 20196 yr 53 minutes ago, theishiopian said: That did not help either. As a side note, I need to be able to vary the amount of hearts the bar covers since the effect is based on a percentage of your health, is there a better way to do that? What you are doing seems appropriate. Can you post your image you are trying to render. And have you refreshed your workspace since you added it. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 8, 20196 yr Author Ok, progress! Im now seeing 6 dark red rectangles on the oposite side of the HUD from the health bar, that twitch occasionally. code used: public void renderStatusBar(int screenWidth, int screenHeight) { //System.out.println("called"); World world = mc.world; EntityPlayer player = mc.player; final int barHeight = 9; //final int barWidth = (int) (9*((Math.ceil(player.getMaxHealth()/5))/2)); final int barWidth = 18; final int expBarSpace = 3; mc.getTextureManager().bindTexture(overlay); final int vanillaExpLeftX = screenWidth / 2 - 91; // leftmost edge of the experience bar final int vanillaExpTopY = screenHeight - 32 + 3; // top of the experience bar //GL11.glTranslatef(vanillaExpLeftX, vanillaExpTopY - expBarSpace - barHeight, 0); //drawTexturedModalRect(0, 0, 0, 0, barWidth, barHeight); this.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, 9, 9, 9, 9); } I should clarify that this is still not the desired effect, but at least its rendering now. EDIT: I just noticed the icons rendering at the top of the screen! Now i just gotta translate them to the right spot. And get rid of those artifacts on the HUD. Edited August 8, 20196 yr by theishiopian clarification.
August 8, 20196 yr Author Ah, that makes a lot of sense. I figured I would have to clean up after myself. Also, whats the best way to make my hearts jiggle when the player is on low health, along with the vanilla ones? EDIT: regarding translation, thats what I meant, yeah. EDIT2: rebinding the icon textures fixed the hunger bar. Edited August 8, 20196 yr by theishiopian
August 8, 20196 yr Author Ok, it looks like the heart shaking is random, I might want to just cancel the health bar rendering and render my own. If anyone has a better idea, I'm all ears. Thank you for the help so far, I've learned a lot about HUD rendering.
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.