Jump to content

Adding a new HUD Element is breaking existing elements.


Javisel

Recommended Posts

I'm trying to add a new hud element that represents data in a players capability. That works fine, but existing HUD elements break with my additions.

At first, the health bar, hunger bar and exp bar where screwed

2019-01-28_21_47_15.thumb.png.fcdbacea7f82fdc98607b2e015dad907.png

 

Source Code

But after adding .post to all the events i managed to fix it somewhat. But now i'm stuck. It's just the hunger bar which is broken now. I tried adding m.renderEngine.bindTexture(Gui.ICONS) but it didn't fix it.

2019-01-29_00_19_34.thumb.png.0836bf115436b4e4e61596e2c30db63b.png 

Source Code

package com.javisel.gui.bar.mana;

import com.google.common.graph.ElementOrder.Type;
import com.javisel.main.References;
import com.javisel.main.Utilities;
import com.javisel.resourcesystems.EnergyProvider;
import com.javisel.resourcesystems.ManaProvider;
import com.javisel.resourcesystems.Resources;
import com.javisel.resourcesystems.SoulsProvider;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;

public class AOGGUI extends Gui {

	private final ResourceLocation mana = new ResourceLocation(References.MODID, "textures/gui/manabar.png");
	private final ResourceLocation energy = new ResourceLocation(References.MODID, "textures/gui/energybar.png");
	private final ResourceLocation soul = new ResourceLocation(References.MODID, "textures/gui/soulcounter.png");
	private final int tex_width = 100, tex_height = 10, barwidth = 98, barheight = 8, soulcounterwidth = 30,
			soulcounterheight = 30;
	int ticks = 0;
	private Resources usingResource = Resources.MANA;

	@SubscribeEvent(priority = EventPriority.NORMAL)
	public void RenderManaBar(RenderGameOverlayEvent.Post e) {
		Minecraft m = Minecraft.getMinecraft();

		if (e.getType() == ElementType.TEXT) {

			float manaratio = m.player.getCapability(ManaProvider.Mana_CAP, null).getmana()
					/ m.player.getCapability(ManaProvider.Mana_CAP, null).getmaxmana();
			int currentWidth = (int) (barwidth * manaratio);
			if (Utilities.displayingresource(m.player) == Resources.MANA) {
				usingResource = Resources.MANA;

				m.renderEngine.bindTexture(mana);
				drawTexturedModalRect(0, 0, 0, 0, tex_width, tex_height);
				drawTexturedModalRect(1, 0, 1, tex_height, currentWidth, tex_height);
				drawCenteredString(m.fontRenderer,
						Math.round(m.player.getCapability(ManaProvider.Mana_CAP, null).getmana()) + "/"
								+ Math.round(m.player.getCapability(ManaProvider.Mana_CAP, null).getmaxmana()),
						tex_width / 2, 1, Integer.parseInt("ffffff", 16));
				m.renderEngine.bindTexture(Gui.ICONS);
			}
		}

	}

	@SubscribeEvent(priority = EventPriority.NORMAL)
	public void RenderEnergyBar(RenderGameOverlayEvent.Post e) {
		Minecraft m = Minecraft.getMinecraft();

		if (e.getType() == ElementType.TEXT) {

			float energyratio = m.player.getCapability(EnergyProvider.Energy_CAP, null).getEnergy()
					/ m.player.getCapability(EnergyProvider.Energy_CAP, null).getmaxEnergy();
			int currentWidth = (int) (barwidth * energyratio);
			if (Utilities.displayingresource(m.player) == Resources.ENERGY) {
				usingResource = Resources.ENERGY;
				m.renderEngine.bindTexture(energy);
				drawTexturedModalRect(0, 0, 0, 0, tex_width, tex_height);
				drawTexturedModalRect(1, 0, 1, tex_height, currentWidth, tex_height);
				drawCenteredString(m.fontRenderer,
						Math.round(m.player.getCapability(EnergyProvider.Energy_CAP, null).getEnergy()) + "/"
								+ Math.round(m.player.getCapability(EnergyProvider.Energy_CAP, null).getmaxEnergy()),
						tex_width / 2, 1, Integer.parseInt("ffffff", 16));
				m.renderEngine.bindTexture(Gui.ICONS);
			}
		}

	}

	@SubscribeEvent(priority = EventPriority.NORMAL)
	public void RenderSoulCounter(RenderGameOverlayEvent.Post e) {
		Minecraft m = Minecraft.getMinecraft();

		m.renderEngine.bindTexture(soul);
		if (e.getType() == ElementType.TEXT) {

			drawTexturedModalRect(0, tex_height + 1, 0, 0, soulcounterwidth, soulcounterheight);
			drawCenteredString(m.fontRenderer,
					Integer.toString(Math.round(m.player.getCapability(SoulsProvider.Souls_CAP, null).getSouls())),
					soulcounterwidth / 2, soulcounterheight + 1, Integer.parseInt("ffffff", 16));

			m.renderEngine.bindTexture(Gui.ICONS);
		}
	}

	@SubscribeEvent(priority = EventPriority.NORMAL)
	public void RenderSoulCounterText(RenderGameOverlayEvent.Post e) {
		Minecraft m = Minecraft.getMinecraft();

		m.renderEngine.bindTexture(soul);
		if (e.getType() == ElementType.TEXT) {

			drawCenteredString(m.fontRenderer,
					Integer.toString(Math.round(m.player.getCapability(SoulsProvider.Souls_CAP, null).getSouls())),
					soulcounterwidth / 2, soulcounterheight + 1, Integer.parseInt("ffffff", 16));

			m.renderEngine.bindTexture(Gui.ICONS);
		}
	}

}

Any idea as to what's going wrong? 

Link to comment
Share on other sites

You need to rebind the textures that Minecraft expects to be in place, they can be found at GuiInGame and/or GuiInGameForge

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.

Guest
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Ensure your system is running the latest version of Java. Sodium requires Java 17 or later for newer Minecraft versions (like 1.17+). 
    • Hi I wanted to my custom mob to hold any sword item, but didn’t rendered properly.   In entity class, make entity hold items as below: @Override public InteractionResult mobInteract(Player pPlayer, InteractionHand pHand) { //… ItemStack itemstack = pPlayer.getItemInHand(pHand); if (this.isTame()) { if ( (itemstack.is(Items.MELON_SLICE) || itemstack.is(Items.HONEY_BOTTLE)) && this.getHealth() < this.getMaxHealth() ) { //… } /* Handle holding sword */ else if (itemstack.getItem() instanceof SwordItem) { pPlayer.displayClientMessage(Component.literal("Clicked with item: " + itemstack.getDisplayName().getString()).withStyle(ChatFormatting.GOLD), true); //Return sword //pPlayer.getInventory().add(this.getItemInHand(InteractionHand.MAIN_HAND)); pPlayer.getInventory().add(this.getItemBySlot(EquipmentSlot.MAINHAND)); //The entity holds item //this.setItemInHand(InteractionHand.MAIN_HAND, itemstack); this.setItemSlot(EquipmentSlot.MAINHAND, itemstack.copy()); //Give copy of itemstack //If player is not in creative mode. From mobInteract() in wolf. if (!pPlayer.getAbilities().instabuild) { //Decrement sword count in hand pPlayer.getItemInHand(pHand).shrink(1); } return InteractionResult.SUCCESS; } else { //If player is sneaking pPlayer.displayClientMessage(getItemInHand(InteractionHand.MAIN_HAND).getDisplayName(), false); if (pPlayer.isShiftKeyDown()) { //Return sword //pPlayer.getInventory().add(this.getItemInHand(InteractionHand.MAIN_HAND)); pPlayer.getInventory().add(this.getItemBySlot(EquipmentSlot.MAINHAND)); //The entity holds nothing this.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); return InteractionResult.SUCCESS; } else { //… } } else { return interactionresult; } }   And in render class, render the item as below: @Override public void render(RanaEntity pEntity, float pEntityYaw, float pPartialTicks, PoseStack pMatrixStack, MultiBufferSource pBuffer, int pPackedLight) { if(pEntity.isBaby()) { pMatrixStack.scale(0.5f, 0.5f, 0.5f); } model.setupAnim(pEntity, 0, 0, 0, pEntityYaw, 0); // //Get location and rotation of arm bone ModelPart rightArm = model.rightArm(); //Get right arm //Get location and rotation of item according to arm bone pMatrixStack.pushPose(); pMatrixStack.translate(rightArm.x, rightArm.y, rightArm.z); //Move to bone location pMatrixStack.mulPose(Axis.XP.rotationDegrees(rightArm.xRot)); //Rotate X pMatrixStack.mulPose(Axis.YP.rotationDegrees(rightArm.yRot)); //Rotate Y pMatrixStack.mulPose(Axis.ZP.rotationDegrees(rightArm.zRot)); //Rotate Z //Draw item //ItemStack itemStack = pEntity.getItemInHand(InteractionHand.MAIN_HAND); ItemStack itemStack = pEntity.getItemBySlot(EquipmentSlot.MAINHAND); if (!itemStack.isEmpty()) { //Offset pMatrixStack.translate(0.0, 0.0, 0.1); // Render the item //Minecraft.getInstance().getItemRenderer().renderStatic(itemStack, ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, pPackedLight, OverlayTexture.NO_OVERLAY, pMatrixStack, pBuffer, pEntity.level(), pEntity.getId()); //itemRenderer.renderStatic(itemStack, ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, pPackedLight, OverlayTexture.NO_OVERLAY, pMatrixStack, pBuffer, pEntity.level(), pEntity.getId()); itemInHandRenderer.renderItem(pEntity, itemStack, ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, false, pMatrixStack, pBuffer, pEntity.getId()); } pMatrixStack.popPose(); super.render(pEntity, pEntityYaw, pPartialTicks, pMatrixStack, pBuffer, pPackedLight); }   I confirmed the entity can properly hold item(logically) but the item which the entity holds is not rendered at all.   Full code: https://github.com/sakiiiiika/ranamod   Thanks.
    • It is Immersive Melodies
    • MINECRAFT JAVA wht is ic_im it shows up yellow heres the modpack https://rocktheslayer.wixsite.com/my-site-7 also It wouldnt Let me submit a bug report only a suggestion for this post
  • Topics

×
×
  • Create New...

Important Information

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