Ernio Posted October 26, 2014 Posted October 26, 2014 Hello, I've been working on my API for quite some time and I thought - why not make forge events for more user-friendly environment (till now I've been using abstract base class in which you can override and add your stuff). I tried to follow event (EntitLivingBase - which later I want to extend with e.g EventSkillCast, etc.) system by call hierarchy but that didn't end well. It's all mixup of compiled and decopiled classes stitched together by EventBus, ForgeHooks and other weird stuff. Question is - is making new event as easy as registering it via EventBus, making its call-code in right place and then just adding @SubscribeEvent? Or maybe are those coded deeply inside forge code that can't be accesed from outside? Just to be on safe side - we are talking about totally new events created by forge mod. Quick edit: From what I'm seeing now is that @SubscribeEvent is being searched for on mod registration, so I guess registering new event would not be possible by mod itself, but still - maybe somehow? for (Method method : target.getClass().getMethods()) { for (Class<?> cls : supers) { try { Method real = cls.getDeclaredMethod(method.getName(), method.getParameterTypes()); if (real.isAnnotationPresent(SubscribeEvent.class)) ... Quote 1.7.10 is no longer supported by forge, you are on your own.
gcewing Posted October 26, 2014 Posted October 26, 2014 I've never tried it, but it looks like you should be able to just define your own subclass of Event and then post() it to the relevant event bus. Should be pretty simple -- try it! Quote
coolAlias Posted October 27, 2014 Posted October 27, 2014 Yep, that's all it takes to make an event: create a class extending Event or any of its subclasses, then post it to the Forge event bus wherever you need it. Typically it only makes sense to create and post an event if you are expecting other people to be using your API, though there are some cases where it is useful to use events within your own code. Quote http://i.imgur.com/NdrFdld.png[/img]
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.