FancyModLoader icon indicating copy to clipboard operation
FancyModLoader copied to clipboard

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

Open Shadows-of-Fire opened this issue 9 months ago • 0 comments

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

Shadows-of-Fire avatar May 18 '24 04:05 Shadows-of-Fire