-
Notifications
You must be signed in to change notification settings - Fork 2
Annotation Processor
as of NanoEvents 3, NanoEvents now comes with it's own Annotation Processor! This automates all the file stuff making it significantly easier.
fabric.mod.json
"custom": {
"nano:uses_AP": true
}build.gradle
dependencies {
// in dependencies
compileOnly 'net.devtech:nanoevents-ap:1.0.0'
annotationProcessor 'net.devtech:nanoevents-ap:1.0.0'
}
processResources {
from(sourceSets.main.output.classesDirs.singleFile) {
include "nanoevents/**"
}
}The annotation processor also packs an annotation called Listener and is used to decorate a listener method
@Listener("examplemod:init")
public static void init() {
System.out.println("examplemod init event!");
}would generate the following lst ini
[examplemod\:init]
listeners = net.fabricmc.example.Listeners\:\:initthe listeners field is a special case value, and will always give the class and method name
additional parameters can be specified by specifying the annotation types in the Listener#args field, and then decorating the method with those args.
eg.
@Listener(value = "examplemod:init", args = {MyAnnotation.class})
@MyAnnotation("test")
public static void init() {
System.out.println("examplemod init event!");
}parameter annotations can also take advantage of the @Name annotation, which will take priority over the method name when serializing the value into the ini file.
The standard Invoker annotation is one of the annotations in the NanoEvents suite, you can specify a custom EventApplyManager via the applyManager field
@Invoker("examplemod:init")
public static void init() {
Logic.start();
init();
Logic.end();
}for example, would generate
[examplemod\:init]
applier = net.devtech.nanoevents.api.event.EventApplyManager$Default
invoker = net.fabricmc.example.InvokersAs we know, the default event apply manager takes a field called mixinPath which tells you which mixins can be disabled/enabled,
in the Invoker#args method you can already see the args used for that apply manager, Invoker$Default has a value field with a @Name annotation
which has the value mixinPath, this means when that when the args are serialized, the name mixinPath goes in the ini file, rather than value.
as a result you can use this annotation in your invoker like this:
@Invoker("examplemod:pre_init")
@Invoker.Default("net.fabricmc.example.mixin.NoApplyMixin")
public static void preInit() {
Logic.start();
preInit();
Logic.end();
}Now, when the annotation processor gets to this, it will produce
[examplemod\:pre_init]
applier = net.devtech.nanoevents.api.event.EventApplyManager$Default
invoker = net.fabricmc.example.Invokers
mixinPath = net.fabricmc.example.mixin.NoApplyMixin