Skip to content

Events a mod defines

A mod with an API of its own declares its events through Stope, so other mods listen the same way they listen to Stope’s, on every loader. Use them where another mod should be able to react to, or cancel, something your mod does, such as a vein it is about to place.

Type Summary Status Since Side Thread
EventResult A listener’s answer for a cancelable event a mod declares with Event#create. Experimental 2.10.0 both any
ModEvent An event a mod declared with Event#create: other mods register listeners, and the declaring mod fires it through #invoker. Experimental 2.10.0 both any

In the class that holds your mod’s API, a callback interface and the event built from it:

Declare a cancelable event
@FunctionalInterface
public interface VeinPlaced {
EventResult onVeinPlaced(WorldGenLevel level, BlockPos pos);
}
public static final ModEvent<VeinPlaced> VEIN_PLACED = Event.create(VeinPlaced.class,
listeners -> (level, pos) -> {
for (VeinPlaced listener : listeners) {
if (listener.onVeinPlaced(level, pos) == EventResult.CANCEL) return EventResult.CANCEL;
}
return EventResult.PASS;
});

Experimental · Since 2.10.0 · Side: both · Thread: any

ModEvent is the event Event#create returns: other mods register listeners on it, and the declaring mod fires it through its invoker. With VEIN_PLACED from the quick start, in the mod’s feature, where level and origin come from the feature’s context:

Fire the event and skip a canceled vein
if (VEIN_PLACED.invoker().onVeinPlaced(level, origin) == EventResult.CANCEL) return false;