Jump to content

[1.8] XP Bar disappearing why? [SOLVED]


JoelGodOfWar

Recommended Posts

Been wondering why this code when enabled, causes the XP bar to be removed and replaced with random text?

Is there a call i should make to render the XP Bar when text is rendered on the screen?

package com.datacraftcoords.event;



import org.lwjgl.opengl.GL11;

import com.datacraftcoords.Configs;
import com.datacraftcoords.GuiRepairOverride;

import net.minecraft.client.Minecraft;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.client.gui.GuiRepair;
import net.minecraft.client.gui.inventory.GuiEditSign;
import net.minecraftforge.client.event.GuiOpenEvent;

public class EventManager {

//public static String daConfig;
/** Enables/Disables this Mod */
public static boolean Enabled;
public static boolean chunkEnabled;

    /**
     * Toggles this Mod on or off
     * @return The state the Mod was changed to
     */
    public static void ToggleEnabled()
    {
    		Enabled = !Enabled;
    		Configs.SaveConfigSettings();
    	        	
    }

@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent e){
	/** Checks if Enabled, if it is Enabled process code. */
	if(EventManager.Enabled)
        {
		/** Checks if experience bar is displayed or not. If it is start code. */
	if(e.type == ElementType.JUMPBAR || e.type == ElementType.EXPERIENCE){
		//String DefaultChatStringFormat = "[{x}, {y}, {z}]";
		/** Gets Biome, and compares it to nether. Then alters the coords displayed based on results */
		String varBiome = getBiome();
		if(!varBiome.equals("Hell")){
			/** We are NOT in the Nether so display Overworld, and Nether Coords. */
			String coordinateString = "{x}, {y}, {z}";
        	coordinateString = coordinateString.replace("{x}", Integer.toString(GetXCoordinate()));
        	coordinateString = coordinateString.replace("{y}", Integer.toString(GetYCoordinate()));
        	coordinateString = coordinateString.replace("{z}", Integer.toString(GetZCoordinate()));
        	/** Display Overworld coords */
        	mc.fontRendererObj.drawString(EnumChatFormatting.YELLOW + "O: " + coordinateString + " " + EnumChatFormatting.RED + yawCalc() + EnumChatFormatting.WHITE + " T:" + CalculateMessageForInfoLine(null), 2, 2, 0xffffff);
        	
        	String coordinateString2 = "{x}, {y}, {z}";
        	coordinateString2 = coordinateString2.replace("{x}", Integer.toString(GetXCoordinate() / );
        	coordinateString2 = coordinateString2.replace("{y}", Integer.toString(GetYCoordinate()));
        	coordinateString2 = coordinateString2.replace("{z}", Integer.toString(GetZCoordinate() / );
        	/** Display Nether Coords, Overworld Dived by 8*/
        	mc.fontRendererObj.drawString(EnumChatFormatting.LIGHT_PURPLE + "N: " + coordinateString2 + EnumChatFormatting.GREEN + " XP: " + getXP(), 2, 12, 0xffffff);
        	//System.out.println("Biome " + varBiome + " - coord1 " + coordinateString + " - coord2 " + coordinateString2);
        	}
		else if(varBiome.equals("Hell")){
			/** We ARE in the Nether so display Nether, and Overworld Coords. */
			String coordinateString3 = "{x}, {y}, {z}";
        	coordinateString3 = coordinateString3.replace("{x}", Integer.toString(GetXCoordinate()));
        	coordinateString3 = coordinateString3.replace("{y}", Integer.toString(GetYCoordinate()));
        	coordinateString3 = coordinateString3.replace("{z}", Integer.toString(GetZCoordinate()));
        	/** Display Nether Coords */
        	mc.fontRendererObj.drawString(EnumChatFormatting.LIGHT_PURPLE + "N: " + coordinateString3 + " " + EnumChatFormatting.RED + yawCalc() + EnumChatFormatting.WHITE + " T:" + CalculateMessageForInfoLine(null), 2, 2, 0xffffff);
        	
        	String coordinateString4 = "{x}, {y}, {z}";
        	coordinateString4 = coordinateString4.replace("{x}", Integer.toString((GetXCoordinate() * ));
        	coordinateString4 = coordinateString4.replace("{y}", Integer.toString(GetYCoordinate()));
        	coordinateString4 = coordinateString4.replace("{z}", Integer.toString((GetZCoordinate() * ));
        	/** Display Overworld Coords, Nether Multiplied by 8 */
        	mc.fontRendererObj.drawString(EnumChatFormatting.YELLOW + "O: " + coordinateString4 + EnumChatFormatting.GREEN + " XP: " + getXP(), 2, 12, 0xffffff);
        	//System.out.println("Biome " + varBiome + " - coord3 " + coordinateString3 + " - coord4 " + coordinateString4);
		}

        	//Minecraft.getMinecraft().fontRendererObj.drawString("" + coordFormat + "", 2, 2, 0xffffff);
		/** Display Biome */
		mc.fontRendererObj.drawString("B: " + getBiome() + "", 2, 22, 0xffffff);
		int chunkX = GetXCoordinate() / 16;
		int chunkY = GetYCoordinate() / 16;
		int chunkZ = GetZCoordinate() / 16;
		int inChunkX = GetXCoordinate() % 16;
		int inChunkY = GetYCoordinate() % 16;
		int inChunkZ = GetZCoordinate() % 16;
		String daChunk = ("" + Integer.toString(inChunkX) + " " + Integer.toString(inChunkY) + " " + Integer.toString(inChunkZ) + " in " + Integer.toString(chunkX) + " " + Integer.toString(chunkY) + " " + Integer.toString(chunkZ)); 

		if(chunkEnabled){
			mc.fontRendererObj.drawString("C: " + daChunk + "", 2, 32, 0xffffff);
		}

	}
	}
}
//public static String coordFormat = "" + Integer.toString(GetXCoordinate()) + ", " + Integer.toString(GetYCoordinate()) + ", " + Integer.toString(GetZCoordinate()) + "";

protected static Minecraft mc = Minecraft.getMinecraft();
//String yawCalc = "" + (MathHelper.floor_double((double) (mc.thePlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3);
/** Get Direction we are facing N S E W */
public static double getYaw(){
	return (double) (MathHelper.floor_double((double) (mc.thePlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3);
}
public static String yawCalc(){
	double var1 = getYaw();
	String var2 = "";
	if(var1 == 0){
		var2 = "S";
	}
	else if(var1 == 1){
		var2 = "W";
	}
	else if(var1 == 2){
		var2 = "N";
	}
	else if(var1 == 3){
		var2 = "E";
	}
	return var2;
}
/** Get XP, Current to Next Level */
public static String getXP(){
	return (String) "" +  String.valueOf((int) Math.ceil(mc.thePlayer.experience * mc.thePlayer.xpBarCap())) + "/" + mc.thePlayer.xpBarCap();
}
/** Get Biome */
public static String getBiome(){
	return (String) "" + mc.thePlayer.worldObj.getBiomeGenForCoords(mc.thePlayer.getPosition()).biomeName;
}
/** Get Player Coordinates */
public static int GetXCoordinate()
{
	return (int) Math.floor(mc.thePlayer.posX);
}
public static int GetYCoordinate()
{
	return (int) Math.floor(mc.thePlayer.posY);
}
public static int GetZCoordinate()
{
	return (int) Math.floor(mc.thePlayer.posZ);
}

private static long mobSpawningStartTime = 13187;
//mobs stop spawning at: 22813
//mobs start to burn at: 23600
private static long mobSpawningStopTime = 23600;
/**
     * Calculates time
     * @return time if the Clock is enabled, otherwise "".
     */
    public static String CalculateMessageForInfoLine(String infoLineMessageUpToThisPoint)
    {
        if (Enabled)
        {
        	
            	//0 game time is 6am, so add 6000
                long time = (mc.theWorld.getWorldTime() + 6000) % 24000;
                
                long hours = time / 1000;
                long seconds = (long)((time % 1000) * (60.0/1000.0));

                if(IsNight())
        		{
                    String nighttimeClockString = EnumChatFormatting.GRAY + String.format("%02d", hours) + ":" + String.format("%02d", seconds);
                    return nighttimeClockString;
        		}
                else
        		{
                    String daytimeClockString = EnumChatFormatting.YELLOW + String.format("%02d", hours) + ":" + String.format("%02d", seconds);
                    return daytimeClockString;
        		}
        	
        	
        	
        }

        return "";
    }
    
    public static boolean IsNight()
    {
    	long time = (mc.theWorld.getWorldTime()) % 24000;
    	return time >= mobSpawningStartTime && time < mobSpawningStopTime;
    }
    @SubscribeEvent
    public void GuiOpenEvent(GuiOpenEvent event)
{
    	//if(UseQuickPlaceSign && event.gui instanceof GuiEditSign && mc.thePlayer.isSneaking())
    	//{
    	//	event.setCanceled(true);
    	//}
    	if(true && event.gui instanceof GuiRepair)
    	{
    		event.gui = new GuiRepairOverride(mc.thePlayer.inventory, mc.theWorld);
    	}
}
}

Link to comment
Share on other sites

Lots of mess in code. :P

 

Your problem sounds like you are not rebinding texture.

After using FontRenderer in OverlayEvent you need to rebing WIDGETS. They are in Gui I think (or somewhere).

 

Note: Might not be it.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Drawing strings (FontRenderer) is nothing else but a tesselator that grabs a symbol on some coordinates in symbols map and draws it in sequence.

 

After using FontRenderer your bound texture is set to using this symbol map, you need to come back to default (icons).

 

How: At the very end of your own rendering do:

 

mc.getTextureManager().bindTexture(Gui.icons);

 

Gui.icons is minecraft field (public static final ResourceLocation icons = new ResourceLocation("textures/gui/icons.png");).

 

Note that OverlayEvent has many rendering phases (each for every overlay part) - use rebinding not in all phases but jsut after you do something in one of them.

 

P.S: And yes, I made mistake, not widgets, but icons.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I fixed it another way just a few minutes ago, but i will try this also.

The fix i found was changing this

if(e.type == ElementType.JUMPBAR || e.type == ElementType.EXPERIENCE){

to this

if(e.type == RenderGameOverlayEvent.ElementType.TEXT){

and now the experience bar displays.

 

thank you Ernio

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



×
×
  • Create New...

Important Information

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