Subscriber events
Getting started with OneConfig's subscriber-based events system is easy and straightforward! If you've worked with MinecraftForge or NeoForge before, you'll be more than familiar with how these function.
Registering a listener
In order for your subscriber methods to execute when an event is dispatched, you'll need to register their containing instance as an event listener. This can be done via an instance of EventManager
, typically the statically provided INSTANCE
:
Listening for events
Now that your instance is registered as an event listener, you can define your subscriber methods for the events which you want to listen for dispatches of. This can be done by defining those events as parameters for a method/function then annotating that same method/function with @Subscribe
.
And there you have it! This instance of our ExampleListener
now receives all dispatched instances of TickEvent.Start
as long as our run
method/function is executed at least once in it's lifetime.
Last updated