fr0st Posted November 25, 2015 Share Posted November 25, 2015 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. Quote I try my best, so apologies if I said something obviously stupid! Link to comment Share on other sites More sharing options...
coolAlias Posted November 25, 2015 Share Posted November 25, 2015 I don't believe so, but I would only do that if you had several events in the same class that were on different buses. If the events aren't related, though, I would consider splitting them up into different classes. Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
fr0st Posted November 25, 2015 Author Share Posted November 25, 2015 Alright, thanks for clearing that up for me. Cheers! Quote I try my best, so apologies if I said something obviously stupid! Link to comment Share on other sites More sharing options...
fr0st Posted November 25, 2015 Author Share Posted November 25, 2015 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. Quote I try my best, so apologies if I said something obviously stupid! Link to comment Share on other sites More sharing options...
jabelar Posted November 26, 2015 Share Posted November 26, 2015 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? Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/ Link to comment Share on other sites More sharing options...
Choonster Posted November 26, 2015 Share Posted November 26, 2015 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. Quote 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. Link to comment Share on other sites More sharing options...
jeffryfisher Posted November 26, 2015 Share Posted November 26, 2015 Aha, so we can declare a unique instance of a handler class and pass it to every bus that will accept it. Quote 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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.