Jump to content

Recommended Posts

Posted

I am wanting to make a bar like the vanilla experience bar but with my own values. I want the bar to have the two textures like the experience bar (the empty and full textures) and display the increments of "experience" shown when it gets to the right amount (what I mean is that the bar fills up with a little bit of the full texture being shown on the screen).

I know this will involve a tick handler, but I am not entirely sure how to go about it... So any help will be appreciated.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Posted

Having built my own HP bar recently, you'll need a few things.

 

1) empty bar

2) full bar (you can use the same png and sprite-sheet it)

3) Event Handler

4) Packet Handler

5) Gui script

 

Your event handler you can register like any other, but the event you'll be interested in is the

 

public void EntityUpdate(LivingEvent event){ }

 

Check for if(event.entityLiving instanceof EntityPlayer) and store your data in the player NBT.  There are two ways to go about it, I use ent.getEntityData() but there's also IExtendedProperties.

 

When the value changes, send a new packet to the player, packet handler intercepts, passes the value to the gui script, the gui script then does the drawing:

 

GuiIngame gui = this.mc.ingameGUI;
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/mods/DecayingWorld/textures/gui/gui.png"));  //I stored my texture along with my other textures
int u = [current exp] / [max exp];  //remember to use floating point division and finish with an integer
gui.drawTexturedModalRect(122, 209, 0, 0, w, h);  //w here is the width we need from the empty bar, in pixels, h is the height
gui.drawTexturedModalRect(122, 209, 0, h, u, h);  //u here is the width from the full bar
//122, 209 are approximate locations of the exp bar at the default window size.  I haven't done any gui scaling yet
//0,0 and 0,h assume the upper left corner of your png and height of your bar (full stacked under the empty one with 0 pixel spacing)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Yes, I could get that much done, I just don't get how it draws the full bar onto the empty one :/

 

SO if that could be explained in the code you posted???

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Posted

Yes, I could get that much done, I just don't get how it draws the full bar onto the empty one :/

 

SO if that could be explained in the code you posted???

 

Two draw calls:

 

gui.drawTexturedModalRect(122, 209, 0, 0, full_width, h);
gui.drawTexturedModalRect(122, 209, 0, h, width_of_partial_fill, h);

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.