Forge events

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. Alternativately 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

  • RenderGameOverlayEvent - Called when the ingame GUI is being rendered

  • 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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.

Example

1
2
3
4
@Override
public void onEnable() {
    getApi().registerForgeListener( new TestListener() );
}