Posted September 30, 201510 yr I want to replace the health/hunger/oxygen/armour/xp/jump bars with my own. But I can't figure out how to cancel only those specific render types. I try to check if it's rendering those types, load mine then cancel the event but nothing renders. Not mine, not the ones I want cancelled, not even the crosshair, inventory or pause menu. How do I do this right? public class HeadsUpDisplay extends Gui { private Minecraft mc; private static final ResourceLocation texturepath = new ResourceLocation(This.MODID, "hud.png"); protected static final RenderItem itemRenderer = new RenderItem(); public HeadsUpDisplay() { super(); this.mc = Minecraft.getMinecraft(); } @SubscribeEvent public void renderHUD(RenderGameOverlayEvent.Pre event) { if (event.isCancelable() || event.type == ElementType.HEALTH || event.type == ElementType.FOOD || event.type == ElementType.AIR || event.type == ElementType.HOTBAR || event.type == ElementType.EXPERIENCE || event.type == ElementType.JUMPBAR) { render(); event.setCanceled(true); } } private void render() { EntityPlayer player = mc.thePlayer; FontRenderer fontrenderer = this.mc.fontRenderer; InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory; int xPos = (mc.displayWidth / 2) - 90; int yPos = mc.displayHeight - 60; GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_BLEND); this.mc.getTextureManager().bindTexture(texturepath); // Render main HUD background this.drawTexturedModalRect(xPos, yPos, 0, 0, 180, 54); // Render health int health = (int) (player.getHealth() * 2); int maxHealth = (int) (player.getMaxHealth() * 2); int healthWidth = (health / maxHealth) * 71; this.drawTexturedModalRect(xPos + 4, yPos + 21, 0, 185, healthWidth, 9); if (health <= 1) { this.drawTexturedModalRect(xPos + 66, yPos + 13, 4, 57, 4, 10); } String hp = health + "/" + maxHealth; int w1 = fontrenderer.getStringWidth(hp) / 2; fontrenderer.drawStringWithShadow(hp, xPos + 122, yPos + 13, 0x000000); // Render hunger int hunger = player.getFoodStats().getFoodLevel(); int hungerWidth = (hunger / 20) * 71; this.drawTexturedModalRect(xPos + 105, yPos + 21, 9, 185, hungerWidth, 9); if (hunger <= 1) { this.drawTexturedModalRect(xPos + 110, yPos + 13, 0, 57, 4, 10); } String hDisplay = hunger + "/" + 20; int w2 = fontrenderer.getStringWidth(hDisplay) / 2; fontrenderer.drawStringWithShadow(hDisplay, xPos + 56, yPos + 13, 0x000000); // Render hotbar item selector this.drawTexturedModalRect(xPos + 6 + inventoryplayer.currentItem * 20, yPos - 34, 8, 57, 8, 7); // Render hotbar icons this.mc.mcProfiler.startSection("actionBar"); GL11.glEnable(GL12.GL_RESCALE_NORMAL); RenderHelper.enableGUIStandardItemLighting(); for (int i = 0; i < 9; ++i) { this.renderInventorySlot(i, xPos + i * 20, yPos + 37, 1); } RenderHelper.disableStandardItemLighting(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); this.mc.mcProfiler.endSection(); GL11.glDisable(GL11.GL_BLEND); // Render horse jump bar if (this.mc.thePlayer.isRidingHorse()) { this.mc.mcProfiler.startSection("jumpBar"); float jump = this.mc.thePlayer.getHorseJumpPower(); int jumpMax = 148; this.drawTexturedModalRect(xPos + 16, yPos - 19, 0, 90, (int) ((jump / jumpMax) * jumpMax), 19); if (jump > 0) { this.drawTexturedModalRect(xPos + 20, yPos + 8, 0, 109, 140, 4); } this.mc.mcProfiler.endSection(); } // Render xp bar int xp = (int) player.experience; int toNextLevel = player.xpBarCap(); int level = player.experienceLevel; String s = "" + level; int w3 = fontrenderer.getStringWidth(s) / 2; fontrenderer.drawStringWithShadow(s, xPos + 90, yPos + 20, 0x000000); if (level > 0) { this.drawTexturedModalRect(xPos + 20, yPos + 4, 20, 57, (xp / toNextLevel) * 140, 4); } // Render armour // Render oxygen } protected void renderInventorySlot(int slot, int x, int y, float tick) { ItemStack itemstack = this.mc.thePlayer.inventory.mainInventory[slot]; if (itemstack != null) { float f1 = (float) itemstack.animationsToGo - tick; if (f1 > 0.0F) { GL11.glPushMatrix(); float f2 = 1.0F + f1 / 5.0F; GL11.glTranslatef((float) (x + , (float) (y + 12), 0.0F); GL11.glScalef(1.0F / f2, (f2 + 1.0F) / 2.0F, 1.0F); GL11.glTranslatef((float) (-(x + ), (float) (-(y + 12)), 0.0F); } itemRenderer.renderItemAndEffectIntoGUI(this.mc.fontRenderer, this.mc.getTextureManager(), itemstack, x, y); if (f1 > 0.0F) { GL11.glPopMatrix(); } itemRenderer.renderItemOverlayIntoGUI(this.mc.fontRenderer, this.mc.getTextureManager(), itemstack, x, y); } } }
September 30, 201510 yr RenderGameOverlayEvent#isCancable() wil always return true, so you will always cancel rendering for everything. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
October 1, 201510 yr Author Okay that was dumb. But now after fixing that my HUD still won't render. @SubscribeEvent public void renderHUD(RenderGameOverlayEvent.Pre event) { if (event.isCancelable()) { if (event.type == ElementType.HEALTH || event.type == ElementType.FOOD || event.type == ElementType.AIR || event.type == ElementType.HOTBAR || event.type == ElementType.EXPERIENCE || event.type == ElementType.JUMPBAR) { render(); event.setCanceled(true); } } } If the event is cancelled after it renders or if I don't cancel it at all, it just shows a really glitchy-looking black-and-white version of the vanilla HUD. If the event is cancelled before it renders, the vanilla HUD doesn't render but mine still doesn't either.
October 1, 201510 yr Take a look at the source for my mod HUDWidgets, it does a similar kind of thing to what you want I believe: https://github.com/Flenix/HUDWidgets http://s13.postimg.org/z9mlly2av/siglogo.png[/img] My mods (Links coming soon) Cities | Roads | Remula | SilvaniaMod | MoreStats
October 1, 201510 yr Hey so what I have found is that the rendering needs to be cancelled in a specific order and reimplemented in a specific order. In order to cancel Hunger, Health, Exp, and the storage... @SubscribeEvent(priority=EventPriority.NORMAL) public void onRenderPre(RenderGameOverlayEvent.Pre event) { if (event.type == ElementType.HOTBAR) { event.setCanceled(true); return; } if (event.type == ElementType.FOOD) { event.setCanceled(true); return; } if (event.type == ElementType.EXPERIENCE) { event.setCanceled(true); return; } if (event.type == ElementType.HEALTH) { event.setCanceled(true); return; } ///Im not positive if you need this statement but I kept it in otherwise I noticed weird glitches with my custom stuff if (event.type != ElementType.FOOD) { return; } } then in the RenderGameOverlay Post event render your new custom elements in the same order as above. Note, I am unsure where the air bar fits in I havent messed with it yet, lemme know if you figure that out. If you mess up the order you get weird glitches I found where some of your custom stuff will look weird. Im not sure why this happens but this seems to work perfectly for me. @SubscribeEvent(priority=EventPriority.NORMAL) public void RenderBattleGUI(RenderGameOverlayEvent.Post event) { if (event.type != ElementType.CROSSHAIRS) { return; } ////////////////Render Custom Hot Bar//////////////////////////////////////////// ////////////////Render Custom Food Bar//////////////////////////////////////////// ///////////////////Render Custom ExpBar//////////////////////////////////////////// ////////////////Render Custom HealthBar//////////////////////////////////////////// } Also ---------------> Hit Thanks if you dont mind
October 1, 201510 yr I render my custom gui hud elements as so in the event you see above GL11.glEnable(GL11.GL_BLEND); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDepthMask(false); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_ALPHA_TEST); ...//Custom Stuff... ///Then the stuff you care about/// /////////ExpBar//////////////////////////////////////////// this.mc.getTextureManager().bindTexture(expBarTexture); int expBarWidth = (int)(((float) (((int)expGained) -this.getExpFromLevel(id, level))/ (this.getExpFromLevel(id, level + 1)-this.getExpFromLevel(id, level))) * pixelWidthOfTexture); drawTexturedModalRect(width/2 -106, height- 32, 0, 0, 77, 9); drawTexturedModalRect(width/2 -106 + 2, height- 32 + 1, 0, 9, expBarWidth, 5); ////////////////HealthBar//////////////////////////////////////////// this.mc.getTextureManager().bindTexture(healthBarTexture); int healthBarWidth = (int)(((float) (int)this.mc.thePlayer.getHealth() / hpMax) * pixelWidthOfTexture); drawTexturedModalRect(width/2 -106, height- 40, 0, 0, 77, 9); drawTexturedModalRect(width/2 -106 + 2, height- 40 + 1, 0, 19, healthBarWidth, 5); ...//.etc etc.... ///more custom stuff/// GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthMask(true); Again The Thank you btn is ---> that a way ish
October 4, 201510 yr Author Unfortunately that still doesn't work. Nothing renders. @SubscribeEvent public void clear(RenderGameOverlayEvent.Pre event) { if (event.type == ElementType.HOTBAR) { event.setCanceled(true); return; } if (event.type == ElementType.FOOD) { event.setCanceled(true); return; } if (event.type == ElementType.EXPERIENCE) { event.setCanceled(true); return; } if (event.type == ElementType.HEALTH) { event.setCanceled(true); return; } if (event.type == ElementType.JUMPBAR) { event.setCanceled(true); return; } if (event.type == ElementType.AIR) { event.setCanceled(true); return; } if (event.type == ElementType.ARMOR) { event.setCanceled(true); return; } if (event.type != ElementType.FOOD) { return; } } @SubscribeEvent public void render(RenderGameOverlayEvent.Post event) { EntityPlayer player = mc.thePlayer; FontRenderer fontrenderer = this.mc.fontRenderer; InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory; this.mc.getTextureManager().bindTexture(texturepath); int xPos = (mc.displayWidth / 2) - 90; int yPos = mc.displayHeight - 60; GL11.glEnable(GL11.GL_BLEND); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDepthMask(false); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_ALPHA_TEST); // HOTBAR - ICONS this.mc.mcProfiler.startSection("actionBar"); GL11.glEnable(GL12.GL_RESCALE_NORMAL); RenderHelper.enableGUIStandardItemLighting(); for (int i = 0; i < 9; ++i) { this.renderInventorySlot(i, xPos + i * 20, yPos + 37, 1); } RenderHelper.disableStandardItemLighting(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); this.mc.mcProfiler.endSection(); GL11.glDisable(GL11.GL_BLEND); // HOTBAR - SELECTOR this.drawTexturedModalRect(xPos + 6 + inventoryplayer.currentItem * 20, yPos - 34, 8, 57, 8, 7); if (!mc.thePlayer.capabilities.isCreativeMode) { // HUD BACKGROUND this.drawTexturedModalRect(xPos, yPos, 0, 0, 180, 54); // FOOD BAR int hunger = player.getFoodStats().getFoodLevel(); int hungerWidth = (hunger / 20) * 71; this.drawTexturedModalRect(xPos + 105, yPos + 21, 9, 185, hungerWidth, 9); if (hunger <= 1) { this.drawTexturedModalRect(xPos + 110, yPos + 13, 0, 57, 4, 10); } String hDisplay = hunger + "/" + 20; int w2 = fontrenderer.getStringWidth(hDisplay) / 2; fontrenderer.drawStringWithShadow(hDisplay, xPos + 56, yPos + 13, 0x000000); // EXPERIENCE BAR int xp = (int) player.experience; int toNextLevel = player.xpBarCap(); int level = player.experienceLevel; String s = "" + level; int w3 = fontrenderer.getStringWidth(s) / 2; fontrenderer.drawStringWithShadow(s, xPos + 90, yPos + 20, 0x000000); if (level > 0) { this.drawTexturedModalRect(xPos + 20, yPos + 4, 20, 57, (xp / toNextLevel) * 140, 4); } // HEALTH BAR int health = (int) (player.getHealth() * 2); int maxHealth = (int) (player.getMaxHealth() * 2); int healthWidth = (health / maxHealth) * 71; this.drawTexturedModalRect(xPos + 4, yPos + 21, 0, 185, healthWidth, 9); if (health <= 1) { this.drawTexturedModalRect(xPos + 66, yPos + 13, 4, 57, 4, 10); } String hp = health + "/" + maxHealth; int w1 = fontrenderer.getStringWidth(hp) / 2; fontrenderer.drawStringWithShadow(hp, xPos + 122, yPos + 13, 0x000000); // HORSE BAR if (this.mc.thePlayer.isRidingHorse()) { this.mc.mcProfiler.startSection("jumpBar"); float jump = this.mc.thePlayer.getHorseJumpPower(); int jumpMax = 148; this.drawTexturedModalRect(xPos + 16, yPos - 19, 0, 90, (int) ((jump / jumpMax) * jumpMax), 19); if (jump > 0) { this.drawTexturedModalRect(xPos + 20, yPos + 8, 0, 109, 140, 4); } this.mc.mcProfiler.endSection(); } // OXYGEN // ARMOUR } }
October 4, 201510 yr 1. Did you register event? 2. Is it even called? 3. Use syso/debug - very useful. 4. For your rendering - USE PHASE (ALL for example). 1.7.10 is no longer supported by forge, you are on your own.
October 4, 201510 yr Author Uh, if it wasn't being registered then nothing would happen. As I've said several times, nothing renders, not mine or the vanilla. So the pre-event is clearly being called. The post-event that's supposed to render mine is being called, for some reason it's not doing anything.
October 4, 201510 yr Please understand that the event is posted for each element type, with different rendering state. If you cancel the event with element type == ALL, NOTHING is rendered. You can cancel any number of them, but you need to choose ONE element type to render ONCE. See GuiInGameForge to check the rendering states.
October 4, 201510 yr This isn't hard at all just remember: 1.) You should cancel this event in Pre 2) Cancelling "ElementType.ALL" will disable every HUD rendered element Take a look at this example: public void onEvent(RenderGameOverlayEvent.Pre event) { switch(event.type) { case HOTBAR : event.setCanceled(event.isCancelable); break; case ANOTHERELEMENT : yourRenderMethod(); event.setCanceled(event.isCancelable); break; default : break; } } EDIT: Depending on your rendering you should probably render your new widgets / icons in current / post. You can also decide when to render it based on when other elements render, shown below: public void onEvent(RenderGameOverlayEvent event) { if(event.type.equals(ElementType.EXPERIENCE) { yourRenderMethodOnExperienceBar(); } } Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]
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.