Jump to content

Recommended Posts

Posted

Hi.

 

Simple question I'm not sure about.

MinecraftForge.EVENT_BUS.register(new EventHandler());
FMLCommonHandler.instance().bus().register(new EventHandler());

 

Would registering the same EventHandler on two buses (for different types of events) have any consequences?

If so, could you explain why?

 

Thanks.

I try my best, so apologies if I said something obviously stupid!

Posted

Yes, I noticed I had used a new instance afterwards.

Anyway I have removed the MinecraftForge.EVENT_BUS.register(new EventHandler()); line of code, so I guess it won't be a problem for the time being.

 

Thank you for that, too.

I try my best, so apologies if I said something obviously stupid!

Posted

Just as a note:

Yes, in 1.8.8 this will have an impact.

In 1.8.8 using this construct will make you receive all events twice, since the forge bus and the FML bus will be using the same object. FML does check for duplication like this, but it can only do so if you use the same instance, not a new one.

 

I don't quite understand this. I thought the event handler method was called based on the method prototype. Doesn't the forge bus only look for methods that take event parameters for that bus, and similarly for the FML bus? Why would forge bus fire the LivingDropsEvent for example?

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

Posted

Just as a note:

Yes, in 1.8.8 this will have an impact.

In 1.8.8 using this construct will make you receive all events twice, since the forge bus and the FML bus will be using the same object. FML does check for duplication like this, but it can only do so if you use the same instance, not a new one.

 

I don't quite understand this. I thought the event handler method was called based on the method prototype. Doesn't the forge bus only look for methods that take event parameters for that bus, and similarly for the FML bus? Why would forge bus fire the LivingDropsEvent for example?

 

The Forge and FML buses will be references to the same object (see how the FML bus is initialised here). If you register two instances of the same class on a bus, both instances will receive the event when it's fired.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Aha, so we can declare a unique instance of a handler class and pass it to every bus that will accept it.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.