Skip to content
MehVahdJukaar edited this page Jul 25, 2026 · 1 revision

Events

A few events that neither loader gives you, fired the same way on both.

This is not a general event bus. Forge has one and Fabric has callbacks, use those for everything they already cover. These are the specific hooks that had no cross loader equivalent:

Event Fired when
ILightningStruckBlockEvent Lightning hits a block
IFireConsumeBlockEvent Fire is about to burn a block away. setFinalState(...) leaves something other than air behind
IDropItemOnDeathEvent A player dies and an item is about to drop. Cancel to keep it, or swap it
IVillagerBrainEvent A villager brain is being built, see Villagers
AfterLanguageLoadEvent The language file loaded. Add entries at runtime
EarlyPackReloadEvent Resource packs are about to reload

Getting Started

MoonlightEventsHelper.addListener(MyMod::onLightningStrike, ILightningStruckBlockEvent.class);
private static void onLightningStrike(ILightningStruckBlockEvent event) {
    if (event.getState().is(Blocks.SAND)) {
        event.getLevel().setBlock(event.getPos(), Blocks.GLASS.defaultBlockState(), 3);
    }
}

To fire your own, implement SimpleEvent and call MoonlightEventsHelper.postEvent(event, MyEvent.class).

Notes

IDropItemOnDeathEvent fires twice, once before the drop and once after the item is cloned to the respawning player. isBeforeDrop() tells you which; cancel both if you want the item to neither drop nor persist.

AfterLanguageLoadEvent is mostly used to name blocks generated at runtime. isDefault() is true for en_us. Config comments register themselves this way.

Clone this wiki locally