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.
At a glance
Section titled “At a glance”| 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 |
Quick start
Section titled “Quick start”In the class that holds your mod’s API, a callback interface and the event built from it:
@FunctionalInterfacepublic 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; });ModEvent
Section titled “ModEvent”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:
if (VEIN_PLACED.invoker().onVeinPlaced(level, origin) == EventResult.CANCEL) return false;See also
Section titled “See also”- Lifecycle events:
Event, the type every Stope callback registers through.