Forge events
Warning
This page is for the LabyMod 3 Addon API, which is no longer maintained nor supported. Visit https://wiki.labymod.net/pages/addon/ for the LabyMod 4 Addon API Wiki.
Using Forge events
With LabyMod we're delivering a selection of Forge events you can use to develop LabyMod addons.
Note
If you're interested in more than just this selection of Forge events, you can add your required method calls by manipulating the bytecode via ASM. Alternatively you can create an issue in our GitHub issue tracker where you explain which event you need.
Forge events you can use:
-
FOVUpdateEvent - Called when the player's fov gets updated
-
GuiOpenEvent - Called when a new GUI is being opened
-
GuiScreenEvent$DrawScreenEvent$Post - Called after any GUI has been drawn
-
RenderWorldLastEvent - Called after the world has been rendered
-
InputEvent$KeyInputEvent - Called when a key is pressed
-
InputEvent$MouseInputEvent - Called when a mouse button is clicked
-
TickEvent$ClientTickEvent - Called after every Minecraft tick
-
TickEvent$RenderTickEvent - Called before every render-tick
Creating event listeners
Your listener-method's first parameter should be a type of the event you want to use (e.g. TickEvent$ClientTickEvent). The method should also be annotated by the SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent) class.
Example listener
package net.labymod.addons.test;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
/**
* Test listener
*/
public class TestListener {
@SubscribeEvent
public void onTick( TickEvent.ClientTickEvent event ) {
System.out.println( "Yay! A Minecraft tick was called." );
}
}
Registering event listeners
You should register the event listeners using LabyModAddon#getApi()#registerForgeListener( Object listener ) in your LabyModAddon#onEnable() method.