Skip to content

Creating an Event

Devan-Kerman edited this page May 16, 2020 · 6 revisions

Creating an event

NanoEvents is a statically registered event framework, so all events need to be declared early on, the way NanoEvents does this is by evt files. EVT files are mostly just property files with 1 level of brackets, they look like this. All white space is removed inside the brackets.

mymod:myevent {
   # the package where the mixins for your event lies, optional
   classes = net.mymod.mixin.myevent.*
   # the class in which the invoker lies
   invoker = net.mymod.invokers.MyEventInvoker
   # true by default, this states that if there are no listeners registered, the event can safely be ignored, disabling the mixins for the class
   noOp = false
}
  ...
  "depends": { // example
    "fabricloader": ">=0.8.2+build.194",
    "minecraft": "1.15.2"
  }, // example
  "custom": {
    ...
    "nano:evt": "events.evt", // this can be an array of strings as well
    "nano:lst": "listener.properties" // so can this
    ...
  }
  ...
}

This file needs to be specified in your mod JSON, you can declare multiple files at once, or just one

classes

With nano events, you can specify which package you've put your event mixins in, so if there are no listeners for a given event, NanoEvents won't apply the mixin, further reducing any potential overhead and performance costs. To use this feature, you must specify (net.devtech.nanoevents.plugin.NanoEventMixinPlugin) as your mixin plugin by setting the "plugin" field in your mixin config (your mixin json) to "net.devtech.nanoevents.plugin.NanoEventMixinPlugin" This isn't always desirable, so it's optional. You can also check if there is a listener for an event manually with NanoEventsAPI#isEnabled.

invoker

This is the class where the invoker for your event exists.

continue: Invokers

Clone this wiki locally