Jump to content

Recommended Posts

Posted

I don't personally play with mods, so I haven't run across this myself, but while coding some event stuff a question occurred to me, and I apologize if it isn't very clear.

 

If multiple mods or even one mod with multiple event handlers handling the same event, what happens?

 

I assume that's where the priority level comes in, but what if they are all the same priority? What happens if one of the handlers cancels the event?

 

Would it follow that if your handler has the possibility of canceling the event, you should give it high priority, whereas if your handler needs to be sure the event is going to happen it should have the lowest possible priority?

 

An example: Two hypothetical mods both use LivingDeathEvent at default priority. Mod 1 wants to prevent the player from dying due to a death ward ability and cancels the event, while mod 2 uses the event to transform the player into a vampire and subsequently respawn normally (as a vampire).

 

How is order determined in such a case, and is there anything we can do as modders to minimize potential impacts from this sort of scenario (if there are indeed any impacts)?

 

Thanks for reading,

coolAlias

Posted

public boolean post(Event event)
    {
        IEventListener[] listeners = event.getListenerList().getListeners(busID);
        for (IEventListener listener : listeners)
        {
            listener.invoke(event);
        }
        return (event.isCancelable() ? event.isCanceled() : false);
    }

This is what happens in EventBus.

Simply, all listeners will be #invoke in registration order, for each priority list. (see ListenerList)

By "default", IEventListener is implemented by

@Override
    public void invoke(Event event)
    {
        if (handler != null)
        {
            if (!event.isCancelable() || !event.isCanceled() || subInfo.receiveCanceled())
            {
                handler.invoke(event);
            }
        }
    }

in ASMEventHandler.

Note that you can receive a canceled event with @ForgeSubscribe(receiveCanceled=true). Then you can uncancel it. Only the final state of the event will be accounted for.

You can also register your own IEventListener with ListenerList#register(int, EventPriority, IEventListener).

 

Fast answer to each of your question:

-All will receive the event if (!event.isCancelable() || !event.isCanceled() || subInfo.receiveCanceled()) if they use the "default" IEventListener.

-Same priority method will receive the event according to the registration order.

-See EventPriority enum to check the priority order. To be sure the event is not canceled, use @ForgeSubscribe(priority=LOWEST, receiveCanceled=true) and uncancel it.

-To minimize logical conflicts, you should always have special conditions, and only "rarely" cancel an event.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.