Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EventBusSubscriber automatically look up and dispatch mod bus events as necessary #140

Open
Shadows-of-Fire opened this issue May 18, 2024 · 0 comments
Labels
cleanup enhancement New feature or request

Comments

@Shadows-of-Fire
Copy link

@EventBusSubscriber has the capacity to be provided a modid argument, which will be used to lookup the mod bus for the target class. We should leverage this functionality to permit automatic dispatch of mod bus and non-mod bus events to the correct bus within a single class as long as the modid is present. This would also mean we can remove the Bus argument and enum.

We should also consider adding a non-static method for doing so (though this may need to be in NeoForge, and not here). Potentially NeoForge.registerEventSubscriber(modid, Object / Class), mimicking this new functionality but with IEventBus#register semantics.

The current paradigm requires separation of mod bus and non-mod bus events at the class level, ex:

@EventBusSubscriber(modid = "mymod", Bus = Bus.MOD)
public class ModEvents {

    @SubscribeEvent
    public static void setup(FMLCommonSetupEvent e) {
        // Do setup tasks
    }

    @EventBusSubscriber
    public static class ForgeBusEvents {
        
        @SubscribeEvent
        public static void tick(LevelTickEvent.Pre e) {
            // Do something on tick
        }
    }
}

This approach does not provide meaningful separation (there is no reason that these must be separated at the class level, aside from the current EBS implementation), and unifying these events in the same class can readily be achieved via IEventBus#addListener.

Further, implementing such a feature will reduce the need to answer support questions about registering events to the correct event bus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant