Posted March 27, 201510 yr Hey fellow modders, I followed Forge's example and setup configuration files and the associated gui menu's that appear after clicking my mod's config button by extending GuiConfig and all that good stuff. However, I'm getting stuck with my event handler that saves my configuration file not receiving the onConfigChangedEvent even though I (supposedly) registered it to the EVENT_BUS. My code is (generally) as follows: public class ConfigEventHandler { @SubscribeEvent(priority=EventPriority.NORMAL) public void onEvent(OnConfigChangedEvent event) { System.out.println("Config Changed Event Fired!"); if (MyMod.MODID.equals(event.modID) && !event.isWorldRunning) { if (Configuration.CATEGORY_GENERAL.equals(event.configID)) { StartupCommon.syncConfig(false); //my version of syncConfig is almost identical to Forge's } else if ("miscConfig".equals(event.configID)) { //update miscConfiguration file } } } } InitCommon is similar to GreyGhost's implementation in MinecraftByExample (runs during Init phase in both clients and dedicated servers): public static void initCommon() { //register the save config handler to EVENT_BUS bus System.out.println("Registering event handlers..."); MinecraftForge.EVENT_BUS.register(new ConfigEventHandler()); } I'm not sure if my mod's container needs to implement registerBus like ForgeModContainer does. And if it needs to, I am not sure how to override methods of my mod's container since forge creates the container for me.
March 27, 201510 yr OnConfigChangedEvent is fired on FML's event bus, not Forge's. Create a public static instance of ConfigEventHandler, and register it with FMLCommonHandler.instance().bus().register(configEventHandler). Potato's have skin. I have skin. Therefore, i am a potato. Follow me on Twitter! http://www.twitter.com/I_Mod_Minecraft
March 27, 201510 yr Author Perfect, everything works now! In the future I should probably check which package the event is in before deciding on the correct bus. Thanks!
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.