Annotation Interface EventBusSubscriber


@Retention(RUNTIME) @Target(TYPE) public @interface EventBusSubscriber
Annotate a class which will be subscribed to an Event Bus at mod construction time.

Annotated classes will be scanned for static methods that have the SubscribeEvent annotation. For example:

@EventBusSubscriber
public class MyEventHandler {
    @SubscribeEvent
    private static void onSomeEvent(SomeEvent event) {
        // SomeEvent handler here
    }

    @SubscribeEvent
    private static void onAnotherEvent(AnotherEvent event) {
        // AnotherEvent handler here
    }
}

Event subscribers for events inheriting from IModBusEvent will be registered to the mod's event bus, while the rest will be registered to the NeoForge#EVENT_BUS.

By default, the subscribers will be registered on both physical sides. This can be customised using value().

See Also:
  • invalid reference
    Bus
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Optional value, only necessary for mod jars that contain multiple mods.
    net.neoforged.api.distmarker.Dist[]
    Specify targets to load this event subscriber on.
  • Element Details

    • value

      net.neoforged.api.distmarker.Dist[] value
      Specify targets to load this event subscriber on. Can be used to avoid loading Client specific events on a dedicated server, for example.
      Returns:
      an array of Dist to load this event subscriber on
      Default:
      {CLIENT, DEDICATED_SERVER}
    • modid

      String modid
      Optional value, only necessary for mod jars that contain multiple mods.
      Returns:
      the mod id whose mod bus events to subscribe to
      Default:
      ""