Jump to content

Recommended Posts

Posted

I have some hud "mana bar" type things that I am displaying but there are some odd things going on.

1. If I do not have an item in my hand all the bars go black

2. The colors don't look like they do when I pull the values from here

 

This is my hud overlay class

public class CustomHud{

private static LuxinBarRenderer[] bar_Lux;

public CustomHud(){
	Minecraft mc = Minecraft.getMinecraft();
	Collection<ILuxin> luxin = LuxinReg.RegisteredLuxin.values();
	bar_Lux = new LuxinBarRenderer[luxin.size()];
	int index = 0;
	for(ILuxin lux : luxin)
	{
		bar_Lux[index] = new LuxinBarRenderer(lux.GetName(), mc, index, lux.GetColor());
		index++;
	}
}

@SubscribeEvent(receiveCanceled=false)
public void onEvent(RenderGameOverlayEvent.Pre event) {
	renderHud();
}

public void renderHud()
{
	for( LuxinBarRenderer rend : bar_Lux)
		rend.RenderLuxinBar();
}
}

 

This is the LuxinBarRenderer class

public class LuxinBarRenderer {

private final static int BAR_WIDTH = 81;
private final static int BAR_HEIGHT = 9;
private final static int BAR_SPACING = 3;

private String lux;
private Minecraft mc;
private int iteration;
private int[] RGB;

public LuxinBarRenderer(String lux, Minecraft mc, int iteration, int[] RGB)
{
	this.lux = lux;
	this.mc = mc;
	this.iteration = iteration;
	this.RGB = RGB;
}

public void RenderLuxinBar()
{
	EntityPlayerSP player = mc.thePlayer;
	if(player == null)
		return;
	IDrafter drafter = DraftingProvider.get(player);
	if( drafter == null && !(drafter instanceof DefaultDrafter))
		return;
	DefaultDrafter prop = (DefaultDrafter) drafter;
	float avail = prop.GetAvailableLuxin().get(lux);
	float cap = prop.GetMaxLuxin().get(lux);
	float percent = cap / avail;
	GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
	GL11.glPushMatrix();

	GL11.glColor4f((float)RGB[0]/255, (float)RGB[1]/255, (float)RGB[2]/255, .6f);

	int top = BAR_SPACING + (iteration * (BAR_SPACING + BAR_HEIGHT));
	int left = BAR_SPACING;
	GL11.glBegin(GL11.GL_LINE_LOOP);
	{
		GL11.glVertex2i(left, top);
		GL11.glVertex2i(left + BAR_WIDTH, top);
		GL11.glVertex2i(left + BAR_WIDTH, top + BAR_HEIGHT);
		GL11.glVertex2i(left, top + BAR_HEIGHT);
	}
	GL11.glEnd();

	GL11.glColor4f((float)RGB[0]/255, (float)RGB[1]/255, (float)RGB[2]/255, 1f);
	GL11.glBegin(GL11.GL_QUADS);
	{
		int right = left + (int)(new Float(BAR_WIDTH) / percent);
		GL11.glVertex2i(left, top);
		GL11.glVertex2i(left, top + BAR_HEIGHT);
		GL11.glVertex2i(right, top + BAR_HEIGHT);
		GL11.glVertex2i(right, top);			
	}
	GL11.glEnd();
	GL11.glPopMatrix();
	GL11.glPopAttrib();
}
}

 

Any idea what would be cause these issues?

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Posted

So I started a new world and the bars were displaying properly.

I created one of my items and then only the luxin type that was used to create that item displayed properly and all of the others changed hue.

 

I then killed a chicken with my item, got 2 feathers and all of the bars display correctly again.

If I throw one or both of the feathers out of my inventory all but that one bar get messed up.

Picking up the feathers fixes the display.

 

I am so confused...

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Posted

When you render, you change GL states - just make sure you are getting back at proper state after rendering.

 

1. When using RenderGameOveralyEvent you ALWAYS need to pick event.type (otherwise you render multiple times per frame) - I suggest: ElementType.ALL.

 

2. RenderGameOveralyEvent has 2 subs - Pre and Post - Pre can be used to cancel renderings of vanilla/other mods, Post should/can be used for your stuff.

Post rendering also (usually) guarantees that you "can't" really messup other renderings since you do it at the end - still - you will probably need to re-set GL attrubutes - to know which to what - see where this event is called and what attrisbs were there before (or you know - just print them).

 

3. Are you sure problem is code in question? (just make sure).

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

Posted

1. So you mean surround all that with an

if(event.type == ElementType.ALL)
{
   //my code
}

 

2. Alright, I'll switch that to post.

 

3. I really have no idea but I cant think of anywhere else in my code that might be causing this. The only other part of my code this touchs is ILuxin#GetColor which for all instances is a single line method that looks like this

public int[] GetColor(){return new int[]{255,0,0,255};}

 

So after applying 1,2 The bars are staying the correct color but when I scroll through the hotbar any time I come across an item the bars completely disappear for a short time(1.5 - 2 seconds). I Also tried removing my receiveCanceled=false but that didn't change anything.

 

is that something that might be getting caused by using ElementType.All?

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

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.