Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10][SOLVED] Creating Events


Recommended Posts

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))
...

1.7.10 is no longer supported by forge, you are on your own.

Link to post
Share on other sites

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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 Privacy Policy.