Jump to content

[1.10.2] & [1.11.2] Missing XP Bar - SOLVED


hugo_the_dwarf

Recommended Posts

Currently I have my own overlays or added overlays, I'm slowly replacing the existing HEALTH and FOOD overlays with my own Health and Stamina models and then adding Mana later on.

But in my works I've noticed the XP bar has vanished however the XP counter (1, 2, 3 etc) that number still appears if you collect enough xp but the progress bar is not visible 

 

package htd.rot.events.client;

import htd.rot.Rot;
import htd.rot.capability.playerextra.CapPlayerExtra;
import htd.rot.capability.playerextra.CapPlayerExtraData;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
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;

public class EventPlayerOverlayGui extends Gui
{
	// Registered in ClientProxy
	private Minecraft mc;
	private static final ResourceLocation staminaTexture = new ResourceLocation(Rot.MODID + ":textures/gui/stam_bar.png");

	private int barW = 81, barH = 9;
	private int innerBarW = barW - 2;

	public EventPlayerOverlayGui(Minecraft mc)
	{
		super();
		this.mc = mc;
	}

	@SubscribeEvent(priority = EventPriority.NORMAL)
	public void onRenderExperienceBar(RenderGameOverlayEvent event)
	{
		if (event.getType() == ElementType.FOOD)
		{
			event.setCanceled(true);
			return;
		}
		if (event.getType() != ElementType.EXPERIENCE)
		{
			return;
		}

		ScaledResolution res = event.getResolution();
		int bottomScreen = res.getScaledHeight(), halfHeight = bottomScreen / 2;
		int rightScreen = res.getScaledWidth(), halfWidth = rightScreen / 2;
		CapPlayerExtraData capPlayerExtra = Minecraft.getMinecraft().thePlayer.getCapability(CapPlayerExtra.CAPABILITY, null);

		int currentbarwidth = 0;
		int xPos = halfWidth + 10;
		int yPos = bottomScreen - 22 - ((this.barH * 2) - 1);

		// Draw Stam Bar
		this.mc.getTextureManager().bindTexture(staminaTexture);

		float currentStam = capPlayerExtra.getCurrentStam();
		float maxStam = capPlayerExtra.MAX_STAM;

		currentbarwidth = MathHelper.clamp_int((int) ((currentStam / maxStam) * this.innerBarW), 0, this.innerBarW);

		drawTexturedModalRect(xPos, yPos, 0, 0, this.barW, this.barH);
		drawTexturedModalRect(xPos + 1, yPos, 0, this.barH, currentbarwidth, this.barH);
	}
}

 

Is the issue that I'm extending Gui? I'm doing that so I can use the "drawTexturedModalRect()" method for drawing. And "ScaledResolution" for positioning.
EDIT: in the attached image LEFT is my modded version, RIGHT is vanilla

MissingXPBar.png

Edited by hugo_the_dwarf
Changing Title to indicate SOLVED
Link to comment
Share on other sites

6 minutes ago, hugo_the_dwarf said:

this.mc.getTextureManager().bindTexture(staminaTexture);

After you are done rendering your stuff you need to rebind the texture that was previously used. Forge won't rebind the texture after each even it posts in GuiIngameForge, it leaves it to modders(and that is the way it should be). The numbers are still drawn as FontRenderer binds the font texture every time it needs to draw anything.

  • Like 1
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.



×
×
  • Create New...

Important Information

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