-
Notifications
You must be signed in to change notification settings - Fork 56
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 |
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).
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.
Basics Platform Helpers Registration Networking Events Configs Config Screen
Resources Runtime Resource Packs Texture Manipulation Resource Helpers Block Set API
Client Custom Models Item Rendering Rendered Textures Post Shaders GUI Toolkit Colors
World Block and Item Interfaces Additional Item Placements Improved Entities Fake Levels World Data Dispenser Behaviors
Utilities Codec Utilities Misc Helpers Commands
Datapacks Villagers Soft Fluids Map Markers Spawn Boxes Global Datapack Folder