Posted July 10, 201510 yr Hi! I'm creating a new class that doesn't extend any existing classes and I want to have an onUpdate() method in it that will run every tick while the game is running (not like in the title screen or anything, only in-game). I know all the existing onUpdate() methods are in some way linked to the run() method in the base Minecraft.class class, but it's never a good idea to edit the source code of Minecraft. So, I was wondering if forge has any annotations I can put over the method to update it every tick and make my life easier, or any classes I can extend that are linked to the world and contains an onUpdate() method that will run when the game is running? I'd like to not have to make a new run() method by implementing Runnable, as it might mess with Minecraft's ticking system or something like that. Thanks IGN: matte006 Played Minecraft since summer 2011. Modding is my life now. Please check out my mod https://minecraft.curseforge.com/projects/gadgets-n-goodies-mod?gameCategorySlug=mc-mods&projectID=230028
July 10, 201510 yr Why dont you use the tickEvents? Those get called every tick, the only thing left is adding the calls to every update() method. You can hardcode these calls or use reflection to add methods dynamically. Projects: Discontinued: - N2ConfigAPI - Meachanical Crafting Table Latest: - CollectionUtils Coöperations: - InGameConfigManager
July 10, 201510 yr Author I never really got the hang of events, but I'm guessing this is wrong, as it didn't work @SubscribeEvent public void onUpdate(TickEvent.WorldTickEvent event) { System.out.println("Hello World!"); //Some example code } Edit: nvm I'm stupid, I forgot to register the event in the EventHandler IGN: matte006 Played Minecraft since summer 2011. Modding is my life now. Please check out my mod https://minecraft.curseforge.com/projects/gadgets-n-goodies-mod?gameCategorySlug=mc-mods&projectID=230028
July 10, 201510 yr To set up an event handler, you have to register an instance of the containing class with one of Forge's busses. I'm not sure which bus is required for WorldTickEvent though.
July 10, 201510 yr You probably solved it alredy, but: * Tick Events are FML. FMLCommonHandler.instance().bus().register(new FMLEvents()); While FMLEvents is class containing @SubscribeEvent methods. Note that ALL tick events have 2 phases - START and END - you need to specify phase, otherwise code runst twice per tick. More notes: Server and worl tick run only on SERVER. Client and Render run only on CLIENT. Player runs on both. 1.7.10 is no longer supported by forge, you are on your own.
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.