Posted May 19, 201312 yr Hello, I'd like to call a function from outside the main mod class when for example the game starts. It'd be in the main mod class like this: @PreInit public static void preInit(FMLPreInitializationEvent event){ function(); } I hope I explained well if not please tell me! Thank you in advance, Dawars http://i.imgur.com/RvFDhZj.gif[/img]
May 19, 201312 yr But here is how I would attempt to go about it: import net.minecraftforge.event.ForgeSubscribe; import cpw.mods.fml.common.event.FMLPreInitializationEvent; public class EventHookContainerClass { @ForgeSubscribe public void FunctionNameHere(FMLPreInitializationEvent event) { //What you want to do here. } } And then in your mods Main class add: @Init public void load(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new EventHookContainerClass()); }
May 19, 201312 yr Hello, I'd like to call a function from outside the main mod class when for example the game starts. It'd be in the main mod class like this: @PreInit public static void preInit(FMLPreInitializationEvent event){ function(); } I hope I explained well if not please tell me! Thank you in advance, Dawars You mean like calling a function from an other class in your main mod file? Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
May 20, 201312 yr Author Yes I meant class. I tried it and it crashed: package.package.FunctionNameHere(cpw.mods.fml.common.event.FMLInitializationEvent) has @ForgeSubscribe annotation, but takes a argument that is not a Event class cpw.mods.fml.common.event.FMLInitializationEvent What I'd like to do is a program that modders can put into their mods and register in their mod file maximum once. It'd send data to my website and they could see theirs stats there... I don't want it to be to complicated for them. http://i.imgur.com/RvFDhZj.gif[/img]
May 20, 201312 yr Well, if your looking to do the @init you need to use FMLPreInitialisatiomevent, not FMLInitiliaztionEvent
May 20, 201312 yr Author Yes I changed it that way but still not working http://i.imgur.com/RvFDhZj.gif[/img]
May 20, 201312 yr Author 2013-05-20 10:09:04 [sEVERE] [ForgeModLoader] Fatal errors were detected during the transition from PREINITIALIZATION to INITIALIZATION. Loading cannot continue 2013-05-20 10:09:04 [sEVERE] [ForgeModLoader] mcp [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized FML [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized Forge [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized Suggestions [suggestions mod] (bin) Unloaded->Constructed->Errored 2013-05-20 10:09:04 [sEVERE] [ForgeModLoader] The following problems were captured during this phase 2013-05-20 10:09:04 [sEVERE] [ForgeModLoader] Caught exception from Suggestions java.lang.IllegalArgumentException: Method public void mods.suggestions.webstats.WebStats.FunctionNameHere(cpw.mods.fml.common.event.FMLInitializationEvent) has @ForgeSubscribe annotation, but takes a argument that is not a Event class cpw.mods.fml.common.event.FMLInitializationEvent at net.minecraftforge.event.EventBus.register(EventBus.java:50) at mods.suggestions.Suggestions.preInit(Suggestions.java:62) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:515) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) at com.google.common.eventbus.EventBus.post(EventBus.java:267) at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:165) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) at com.google.common.eventbus.EventBus.post(EventBus.java:267) at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:98) at cpw.mods.fml.common.Loader.loadMods(Loader.java:514) at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:160) at net.minecraft.client.Minecraft.startGame(Minecraft.java:407) at net.minecraft.client.MinecraftAppletImpl.startGame(MinecraftAppletImpl.java:44) at net.minecraft.client.Minecraft.run(Minecraft.java:729) at java.lang.Thread.run(Unknown Source) http://i.imgur.com/RvFDhZj.gif[/img]
May 20, 201312 yr Hmmm, I really wish I was next to my computer right now so that I could try and help some more, but for now I don't know what to say I'm really sorry :'(
May 20, 201312 yr Author No problem, I can finish the other side of the stat system And you can help when you are next to a computer Thanks! http://i.imgur.com/RvFDhZj.gif[/img]
May 20, 201312 yr FML's events are not part of Forge's event bus as Forge's event bus is highly specialized for efficiency. Your best bet is just do do things normaly. Have a 'bouncer' method in your main class that just has a 'OtherClass.onInit(event)' I do Forge for free, however the servers to run it arn't free, so anything is appreciated. Consider supporting the team on Patreon
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.