Jump to content

Annotation for updating while game is running?


TheMattyBoy

Recommended Posts

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

Link to comment
Share on other sites

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 :P

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.