Posted October 19, 201411 yr What is the difference between the mod methods preInit, init, and postInit? How can I use them most effectively?
October 19, 201411 yr EventHandlers During startup, Forge will call your Mod several times to let you add new blocks, items, read configuration files, and otherwise integrate itself into the game by registering your Classes in the appropriate spots. Before Forge can call your Mod, it needs to know which methods to use. This is where @EventHandler comes in. For example - during startup Forge will go through a number of phases for all of the mods which are loaded: PreInitialization - "Run before anything else. Read your config, create blocks, items, etc, and register them with the GameRegistry." Initialization - "Do your mod setup. Build whatever data structures you care about. Register recipes." PostInitialization - "Handle interaction with other mods, complete your setup based on this. PreInitialization is peformed for all the mods, followed by Initialization for all mods, followed by PostInitialization for all mods. Initialising the mods in phases is particularly useful when there might be interactions between multiple mods - for example if one mod adds an extra type of wood (during PreInit), and your mod adds a recipe which uses that wood (during Init). When Forge wants to tell your mod that it's time to run your PreInitialization code, it reads through your mod's code until it finds @EventHandler in front of a method, then checks the parameter definition to see if it matches the FMLPreInitializationEvent Class. If so, it calls the method. The PreInitialization, Initialization, and PostInitialization events will often need to do different things depending on whether your mod is in a CombinedClient or a DedicatedServer. For this reason I suggest that your event handlers should just immediately call a method in the CommonProxy, see below. @EventHandler public void preInit(FMLPreInitializationEvent event) { proxy.preInit(); } @EventHandler public void load(FMLInitializationEvent event) { proxy.load(); } @EventHandler public void postInit(FMLPostInitializationEvent event) { proxy.postInit(); } from http://greyminecraftcoder.blogspot.com/2013/11/how-forge-starts-up-your-code.html
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.