Jump to content

Recommended Posts

Posted

Another issue has come up yet again! I want to override the default HUD completely, as in no default HUD items are being rendered (health bar, hotbar, hunger etc...)

 

I've done it using Reflection for now, but this seems to break when I build my mod. Which leads me to believe that is not a good way to approach this issue (duh!)

So what I'm asking for basically, how can I either prevent the default HUD items from rendering or replace the class completely without borking everything.

Posted

Check the type field of the event instance, it is of Type RenderGameOverlayEvent.ElementType, which tells you what is being rendered.

 

I did, it still cancels everything.

 

@SubscribeEvent
public void onRenderGameOverlay(RenderGameOverlayEvent.Pre event) {
	if(event.type != ElementType.CHAT && event.type != ElementType.CROSSHAIRS){
		event.setCanceled(true);
	}
}

Posted

Oh right, I forgot.

There is ElementType.ALL which is fired before anything is drawn. If you cancel that, no further rendering occurs down the line (so it doesn't even try to render anything).

 

Thanks a lot! It works now. Two more questions though. How do I get the amount of hunger someone has left? If I do

Minecraft.getMinecraft().thePlayer.getFoodStats().getFoodLevel();

It doesn't return the right value.

 

And second, is it possible to draw a button on the in game GUI? Or other controls. If so, how would I do that?

 

Sorry to bother you with this. ^^"

Posted

Sorry to pile on this thread, but I have some questions in following this thread.

 

First of all, there are two event types that extend RenderGuiOverlayEvent.Pre: Chat and Text

 

Question #1) Does the parent event (in this case the Pre event) fire when each of the Chat and Text events are posted, or are they considered fully separate postings?

 

Question #2) I think this is related to the first, but those extended class events canceled if RenderGuiOverlayEvent.Pre is canceled?  It is not clear to me that canceling a parent event necessarily cancels any extended classes since I assume the extended classes could be posted independently.  So I guess my actual question is whether canceling a parent event cancels the extended classes?

 

Question #3) Since there is a type field for the Pre event, that implies it is called for each element.  But then in this thread you mentioned that the "ALL" type is posted first.  I don't quite understand what it means to post an ALL type then post each separate type.  I mean if there is already an event meant for all, why would there be separate elements posted as well?  I just don't understand the utility of having an "ALL" if you also get each separate element type.

 

Question #4) Is there any practical difference between handling the Pre event and checking for types CHAT and TEXT versus handling the events for Chat and Text directly?

 

Sorry for all these questions, but I'm just really starting to dig into event processing again.

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Since this is somewhat related to my original request I figured to post here again instead of making a whole new thread.

 

I've got pretty much everything I want working.

I just need to calculate the delta time now so my HUD animations are framerate independent. (delta time = time the last frame took to complete)

 

I've been looking around on Google but didn't really find a solution which properly explains how it works. I don't just want to copy and paste code.

 

The calculation I use now doesn't work and always comes out on "0.016666666666666666" regardless of my FPS, whether it be 10 or 200.

Posted

#1) No, it does not. As in: There are no 2 events fired, only Chat and Text, not Pre, then Chat, then Pre, then Text. Still, because both Chat and Text extend Pre if you have an EventHandler for Pre, you will receive these two as well.

 

#2) See #1.

 

#3) ALL is intended for when you just want to cancel the whole rendering. In that case it makes no sense to through all the things type by type and ask "Maybe render this? No? Ok.". You rather just go "Ok, don't render anything at all. We are done here."

 

#4) If you handle Chat and Text directly you won't get any other Pre events. If you are really only interested in these specific events this is the way to go (this is a general purpose advice: Narrow down your event handlers as much as possible, don't use e.g. PlayerEvent and then use instanceof etc. to check which event it actually is).

 

Thanks!  This is pretty much what I expected but it is a lot better having confidence, especially on the topic of how the parent and subclasses work with respect to handling.

 

One further question though: it seems that some parent classes get fired and others don't, or at least I've had trouble subscribing to them.  For example subscribing to GuiScreenEvent seems to give me an error when registering my handler, but subscribing to GuiScreenEvent.ActionPerformed works fine.  Is there any specific reasoning behind this?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.