Posted March 5, 201411 yr Hello, after updating from Forge 1024 to 1034 my EventHandler doesn't work anymore. In my mod_File I've: public void LoadMod(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new EventHandler()); } EventHandler.class public class FE_EventHandler { @SubscribeEvent public static void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) { String welcome = EnumChatFormatting.YELLOW + "Mod V1.0 successfully loaded."; event.player.addChatComponentMessage(new ChatComponentText(welcome)); } } The message doesn't appear and some other things I added to EventHandler also doesn't work. Can someone help me, please?
March 5, 201411 yr By doesn't work anymore, surely you must mean never worked. Look at the import for your PlayerLoggedInEvent, and you will see it's in the cpw.mods.fml.common.eventhandler.Event package, NOT MinecraftForge. You need to register it to the FML bus: FMLCommonHandler.instance().bus().register(new YourFMLEventHandler()); http://i.imgur.com/NdrFdld.png[/img]
March 5, 201411 yr Author After I changed it, i get this error pointing to onPlayerLogin: Expecting non-static method
March 5, 201411 yr ALL events MUST be "public void", NOT static, not private. Look at yours: public static void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {} http://i.imgur.com/NdrFdld.png[/img]
March 5, 201411 yr The system sends the events to the instance of your mod class, so static event handlers will not work. As said, you cannot use a static method, but you can delegate the work to a static method, if you need to do so. Just call your static method from the instance's event handler. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
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.